aboutsummaryrefslogtreecommitdiff
path: root/bat.lua
diff options
context:
space:
mode:
authorAdrian C. (anrxc) <anrxc@sysphere.org>2009-10-04 00:54:27 +0200
committerAdrian C. (anrxc) <anrxc@sysphere.org>2009-10-04 00:54:27 +0200
commitb4e028b21ffb5b8ee384516626345cf8150dcc02 (patch)
tree389b6d74effbf63ece80661f11ed83f32f439a7e /bat.lua
parentb65d5093803ec81f89f286c90807a44fa219c733 (diff)
downloadvicious-legacy-b4e028b21ffb5b8ee384516626345cf8150dcc02.tar.xz
Removed some useless else statements
Diffstat (limited to 'bat.lua')
-rw-r--r--bat.lua56
1 files changed, 28 insertions, 28 deletions
diff --git a/bat.lua b/bat.lua
index 78ce4bf..9a45afe 100644
--- a/bat.lua
+++ b/bat.lua
@@ -38,43 +38,43 @@ local function worker(format, batid)
-- Check if the file wasn't found or the battery isn't present
if infofile == nil or string.find(infofile, "present:[%s]+no") then
return {"/", "/", "/"}
- else
- -- Get capacity information
- local capacity = string.match(infofile, "last full capacity:[%s]+([%d]+).*")
+ end
+ -- Get capacity information
+ local capacity = string.match(infofile, "last full capacity:[%s]+([%d]+).*")
- -- Get /proc/acpi/battery state
- local f = io.open("/proc/acpi/battery/"..batid.."/state")
- local statefile = f:read("*all")
- f:close()
- -- Get state information
- local state = string.match(statefile, "charging state:[%s]+([%a]+).*")
- local state = battery_state[state] or battery_state["unknown"]
+ -- Get /proc/acpi/battery state
+ local f = io.open("/proc/acpi/battery/"..batid.."/state")
+ local statefile = f:read("*all")
+ f:close()
- -- Get charge information
- local rate = string.match(statefile, "present rate:[%s]+([%d]+).*")
- local remaining = string.match(statefile, "remaining capacity:[%s]+([%d]+).*")
+ -- Get state information
+ local state = string.match(statefile, "charging state:[%s]+([%a]+).*")
+ local state = battery_state[state] or battery_state["unknown"]
+ -- Get charge information
+ local rate = string.match(statefile, "present rate:[%s]+([%d]+).*")
+ local remaining = string.match(statefile, "remaining capacity:[%s]+([%d]+).*")
- -- Calculate percentage
- local percent = math.floor(remaining / capacity * 100)
- local percent = string.format("%02d", percent)
- -- Calculate remaining (charging or discharging) time
- if state == "+" then
- timeleft = (tonumber(capacity) - tonumber(remaining)) / tonumber(rate)
- elseif state == "-" then
- timeleft = tonumber(remaining) / tonumber(rate)
- else
- return { state, percent, "/" }
- end
- local hoursleft = math.floor(timeleft)
- local minutesleft = math.floor((timeleft - hoursleft) * 60 )
- local time = string.format("%02d:%02d", hoursleft, minutesleft)
+ -- Calculate percentage
+ local percent = math.floor(remaining / capacity * 100)
+ local percent = string.format("%02d", percent)
- return {state, percent, time}
+ -- Calculate remaining (charging or discharging) time
+ if state == "+" then
+ timeleft = (tonumber(capacity) - tonumber(remaining)) / tonumber(rate)
+ elseif state == "-" then
+ timeleft = tonumber(remaining) / tonumber(rate)
+ else
+ return { state, percent, "/" }
end
+ local hoursleft = math.floor(timeleft)
+ local minutesleft = math.floor((timeleft - hoursleft) * 60 )
+ local time = string.format("%02d:%02d", hoursleft, minutesleft)
+
+ return {state, percent, time}
end
-- }}}