Merge branch 'master' of http://git.sysphere.org/vicious
This commit is contained in:
commit
4bcd10b8ad
6
TODO
6
TODO
|
@ -5,11 +5,11 @@
|
||||||
|
|
||||||
|
|
||||||
* Vicious
|
* Vicious
|
||||||
|
** TODO Consider commiting power drain support to bat.lua
|
||||||
|
** TODO Try replacing dio.lua with io.lua
|
||||||
|
*** TODO First io.lua should grab data for all devices
|
||||||
** TODO Document contrib widgets in contrib/README
|
** TODO Document contrib widgets in contrib/README
|
||||||
** TODO Consider multigraph, graph stacking, support
|
** TODO Consider multigraph, graph stacking, support
|
||||||
** TODO Consider including this code in format helper
|
|
||||||
- return format and format:gsub("${[^}]+}", "")
|
|
||||||
- Note: We should then also replace just $1/$2...
|
|
||||||
** TODO Complete the hddtemp fix
|
** TODO Complete the hddtemp fix
|
||||||
- In certain setups regexp does not match all devices
|
- In certain setups regexp does not match all devices
|
||||||
- The regexp catches the first device name, but last stats
|
- The regexp catches the first device name, but last stats
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
-- {{{ Grab environment
|
-- {{{ Grab environment
|
||||||
local pairs = pairs
|
local pairs = pairs
|
||||||
|
local tonumber = tonumber
|
||||||
local io = { open = io.open }
|
local io = { open = io.open }
|
||||||
local setmetatable = setmetatable
|
local setmetatable = setmetatable
|
||||||
local getmetatable = getmetatable
|
local getmetatable = getmetatable
|
||||||
|
@ -53,7 +54,9 @@ end
|
||||||
-- {{{ Format a string with args
|
-- {{{ Format a string with args
|
||||||
function format(format, args)
|
function format(format, args)
|
||||||
for var, val in pairs(args) do
|
for var, val in pairs(args) do
|
||||||
format = format:gsub("$" .. var, val)
|
format = format:gsub("$" .. (tonumber(var) and var or
|
||||||
|
var:gsub("[-+?*]", function(i) return "%"..i end)),
|
||||||
|
val)
|
||||||
end
|
end
|
||||||
|
|
||||||
return format
|
return format
|
||||||
|
|
|
@ -57,21 +57,26 @@ local function worker(format, warg)
|
||||||
-- Get charge information
|
-- Get charge information
|
||||||
if battery.current_now then
|
if battery.current_now then
|
||||||
rate = battery.current_now
|
rate = battery.current_now
|
||||||
else -- Todo: other rate sources, as with capacity?
|
elseif battery.power_now then
|
||||||
|
rate = battery.power_now
|
||||||
|
else
|
||||||
return {state, percent, "N/A"}
|
return {state, percent, "N/A"}
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Calculate remaining (charging or discharging) time
|
-- Calculate remaining (charging or discharging) time
|
||||||
|
local time = "N/A"
|
||||||
|
if rate ~= nil then
|
||||||
if state == "+" then
|
if state == "+" then
|
||||||
timeleft = (tonumber(capacity) - tonumber(remaining)) / tonumber(rate)
|
timeleft = (tonumber(capacity) - tonumber(remaining)) / tonumber(rate)
|
||||||
elseif state == "-" then
|
elseif state == "-" then
|
||||||
timeleft = tonumber(remaining) / tonumber(rate)
|
timeleft = tonumber(remaining) / tonumber(rate)
|
||||||
else
|
else
|
||||||
return {state, percent, "N/A"}
|
return {state, percent, time}
|
||||||
end
|
end
|
||||||
local hoursleft = math.floor(timeleft)
|
local hoursleft = math.floor(timeleft)
|
||||||
local minutesleft = math.floor((timeleft - hoursleft) * 60 )
|
local minutesleft = math.floor((timeleft - hoursleft) * 60 )
|
||||||
local time = string.format("%02d:%02d", hoursleft, minutesleft)
|
time = string.format("%02d:%02d", hoursleft, minutesleft)
|
||||||
|
end
|
||||||
|
|
||||||
return {state, percent, time}
|
return {state, percent, time}
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue