Added handlers to batat and fixed the battery_state table.

Batat now returns "/" in situations where the battery is not
present. Last commit broke the battery_state table, fixed that.
This commit is contained in:
Adrian C. (anrxc) 2009-07-30 02:05:22 +02:00
parent e2d503ee36
commit 2921200d0f
1 changed files with 6 additions and 4 deletions

View File

@ -19,7 +19,7 @@ function worker(format)
local battery_info = {} local battery_info = {}
local battery_state = { local battery_state = {
["full"] = "*", ["full"] = "*",
["unknown"] = " " ["unknown"] = " ",
["charged"] = "*", ["charged"] = "*",
["charging"] = "+", ["charging"] = "+",
["discharging"] = "-" ["discharging"] = "-"
@ -33,10 +33,12 @@ function worker(format)
-- Check if the battery is present -- Check if the battery is present
if line:match("^[%s]+Battery.*") then if line:match("^[%s]+Battery.*") then
-- Store state and charge information -- Store state and charge information
table.insert(battery_info, battery_state[line:match("([%a]*),")]) table.insert(battery_info, (battery_state[line:match("([%a]*),")] or "/"))
table.insert(battery_info, line:match("([%d]?[%d]?[%d])%.")) table.insert(battery_info, (line:match("([%d]?[%d]?[%d])%.") or "/"))
-- Store remaining time information if the battery supports it -- Store remaining time information
table.insert(battery_info, (line:match("%%,%s(.*)") or "/")) table.insert(battery_info, (line:match("%%,%s(.*)") or "/"))
else
return { "/", "/", "/" }
end end
end end
f:close() f:close()