From 2921200d0f1dbf36ae885d0898849a31e646f372 Mon Sep 17 00:00:00 2001 From: "Adrian C. (anrxc)" Date: Thu, 30 Jul 2009 02:05:22 +0200 Subject: [PATCH] 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. --- batat.lua | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/batat.lua b/batat.lua index dcabd2b..8f8b95a 100644 --- a/batat.lua +++ b/batat.lua @@ -19,7 +19,7 @@ function worker(format) local battery_info = {} local battery_state = { ["full"] = "*", - ["unknown"] = " " + ["unknown"] = " ", ["charged"] = "*", ["charging"] = "+", ["discharging"] = "-" @@ -33,10 +33,12 @@ function worker(format) -- Check if the battery is present if line:match("^[%s]+Battery.*") then -- Store state and charge information - table.insert(battery_info, battery_state[line:match("([%a]*),")]) - table.insert(battery_info, line:match("([%d]?[%d]?[%d])%.")) - -- Store remaining time information if the battery supports it + table.insert(battery_info, (battery_state[line:match("([%a]*),")] or "/")) + table.insert(battery_info, (line:match("([%d]?[%d]?[%d])%.") or "/")) + -- Store remaining time information table.insert(battery_info, (line:match("%%,%s(.*)") or "/")) + else + return { "/", "/", "/" } end end f:close()