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.
This commit is contained in:
Adrian C. (anrxc) 2009-10-15 23:38:55 +02:00
parent 4d1af1e5ad
commit 97d2ecbb19
1 changed files with 3 additions and 3 deletions

View File

@ -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 )