diff options
author | Adrian C. (anrxc) <anrxc@sysphere.org> | 2009-10-15 23:38:55 +0200 |
---|---|---|
committer | Adrian C. (anrxc) <anrxc@sysphere.org> | 2009-10-15 23:38:55 +0200 |
commit | 97d2ecbb19dd10a87ea940b2306e0136a994e62c (patch) | |
tree | 9e04694628bf9da70f65a04cf31cb2d63c37ec53 | |
parent | 4d1af1e5ade06242c4a7580446781c9ab2b0f2fa (diff) | |
download | vicious-legacy-97d2ecbb19dd10a87ea940b2306e0136a994e62c.tar.xz |
bat: better returns when handling insufficient data
If we return "N/A" like we usually do then format string "$1$2" would
look like "N/AN/A". If "/" is returned a progressbar could be
broken. Now returns are: symbol for state "unknown", 0 for battery
charge, N/A for remaining time.
-rw-r--r-- | bat.lua | 6 |
1 files changed, 3 insertions, 3 deletions
@@ -36,13 +36,13 @@ local function worker(format, batid) -- Get /proc/acpi/battery info local f = io.open("/proc/acpi/battery/"..batid.."/info") -- Handler for incompetent users - if not f then return {"/", "/", "/"} end + if not f then return {battery_state["unknown"], "0", "N/A"} end local infofile = f:read("*all") f:close() -- Check if the battery is present if infofile == nil or string.find(infofile, "present:[%s]+no") then - return {"/", "/", "/"} + return {battery_state["unknown"], "0", "N/A"} end -- Get capacity information @@ -72,7 +72,7 @@ local function worker(format, batid) elseif state == "-" then timeleft = tonumber(remaining) / tonumber(rate) else - return { state, percent, "/" } + return {state, percent, "N/A"} end local hoursleft = math.floor(timeleft) local minutesleft = math.floor((timeleft - hoursleft) * 60 ) |