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:48:02 +0200 |
commit | f363278d3f4113d2b14584d061d865013ad0745d (patch) | |
tree | 63a3f6145f07288c74cea9e3abb237bc3c45657a /bat.lua | |
parent | a72b776dd5abcbe4ab646be0e4a4364eac1d8a25 (diff) | |
download | vicious-legacy-f363278d3f4113d2b14584d061d865013ad0745d.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.
Diffstat (limited to 'bat.lua')
-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 ) |