[battery_freebsd] switch to awful.spawn.easy_async
This commit is contained in:
parent
383d91399f
commit
992d835c2e
|
@ -16,7 +16,7 @@ Added:
|
||||||
|
|
||||||
Fixed:
|
Fixed:
|
||||||
|
|
||||||
- [volume,gmail] Deprecate `io.popen`
|
- [volume,gmail,battery(FreeBSD)] Deprecate `io.popen`
|
||||||
- [mpd] Lua 5.3 compatibility (for real this time); also correct a typo
|
- [mpd] Lua 5.3 compatibility (for real this time); also correct a typo
|
||||||
- [pkg,weather,contrib/btc] Allow function call without Awesome
|
- [pkg,weather,contrib/btc] Allow function call without Awesome
|
||||||
- [pkg] Use more updated front-ends for Debian/Ubuntu (apt) and Fedora (dnf)
|
- [pkg] Use more updated front-ends for Debian/Ubuntu (apt) and Fedora (dnf)
|
||||||
|
|
|
@ -1,23 +1,23 @@
|
||||||
-- {{{ Grab environment
|
-- {{{ Grab environment
|
||||||
local setmetatable = setmetatable
|
|
||||||
local tonumber = tonumber
|
local tonumber = tonumber
|
||||||
local io = { popen = io.popen }
|
|
||||||
local math = { floor = math.floor }
|
local math = { floor = math.floor }
|
||||||
local helpers = require("vicious.helpers")
|
local helpers = require("vicious.helpers")
|
||||||
|
local spawn = require("vicious.spawn")
|
||||||
local string = {
|
local string = {
|
||||||
gmatch = string.gmatch,
|
gmatch = string.gmatch,
|
||||||
match = string.match,
|
match = string.match,
|
||||||
format = string.format
|
format = string.format
|
||||||
}
|
}
|
||||||
|
|
||||||
-- }}}
|
-- }}}
|
||||||
|
|
||||||
|
-- Battery: provides battery level of requested battery
|
||||||
|
-- vicious.widgets.battery_freebsd
|
||||||
local bat_freebsd = {}
|
local bat_freebsd = {}
|
||||||
|
|
||||||
local function worker(format, warg)
|
-- {{{ Battery widget type
|
||||||
local battery = warg or "batt"
|
local function parse(stdout, stderr, exitreason, exitcode)
|
||||||
local bat_info = {}
|
local bat_info = {}
|
||||||
local f = io.popen("acpiconf -i " .. helpers.shellquote(battery))
|
for line in string.gmatch(s,"[^\n]+") do
|
||||||
for line in f:lines("*line") do
|
|
||||||
for key,value in string.gmatch(line, "(.+):%s+(.+)") do
|
for key,value in string.gmatch(line, "(.+):%s+(.+)") do
|
||||||
bat_info[key] = value
|
bat_info[key] = value
|
||||||
end
|
end
|
||||||
|
@ -25,22 +25,15 @@ local function worker(format, warg)
|
||||||
|
|
||||||
-- current state
|
-- current state
|
||||||
-- see: https://github.com/freebsd/freebsd/blob/master/usr.sbin/acpi/acpiconf/acpiconf.c
|
-- see: https://github.com/freebsd/freebsd/blob/master/usr.sbin/acpi/acpiconf/acpiconf.c
|
||||||
local state
|
local battery_state = {
|
||||||
if bat_info["State"] == "high" then
|
["high"] = "↯",
|
||||||
state = "↯"
|
["charging"] = "+",
|
||||||
elseif bat_info["State"] == "charging" then
|
["critical charging"] = "+",
|
||||||
state = "+"
|
["discharging"] = "-",
|
||||||
elseif bat_info["State"] == "critical charging" then
|
["critical discharging"] = "!",
|
||||||
state = "+"
|
["critical"] = "!",
|
||||||
elseif bat_info["State"] == "discharging" then
|
}
|
||||||
state = "-"
|
local state = battery_state[bat_info["State"]] or "N/A"
|
||||||
elseif bat_info["State"] == "critical discharging" then
|
|
||||||
state = "!"
|
|
||||||
elseif bat_info["State"] == "critical" then
|
|
||||||
state = "!"
|
|
||||||
else
|
|
||||||
state = "N/A"
|
|
||||||
end
|
|
||||||
|
|
||||||
-- battery capacity in percent
|
-- battery capacity in percent
|
||||||
local percent = tonumber(string.match(bat_info["Remaining capacity"], "[%d]+"))
|
local percent = tonumber(string.match(bat_info["Remaining capacity"], "[%d]+"))
|
||||||
|
@ -72,4 +65,11 @@ local function worker(format, warg)
|
||||||
return {state, percent, time, wear, rate}
|
return {state, percent, time, wear, rate}
|
||||||
end
|
end
|
||||||
|
|
||||||
return setmetatable(bat_freebsd, { __call = function(_, ...) return worker(...) end })
|
function battery_freebsd.async(format, warg, callback)
|
||||||
|
local battery = warg or "batt"
|
||||||
|
spawn.easy_async("acpiconf -i " .. helpers.shellquote(battery),
|
||||||
|
function (...) callback(parse(...)) end)
|
||||||
|
end
|
||||||
|
-- }}}
|
||||||
|
|
||||||
|
return helpers.setasyncall(battery_freebsd)
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
-- {{{ Grab environment
|
-- {{{ Grab environment
|
||||||
local tonumber = tonumber
|
local tonumber = tonumber
|
||||||
local string = { match = string.match }
|
local string = { match = string.match }
|
||||||
local helpers = require"vicious.helpers"
|
local helpers = require("vicious.helpers")
|
||||||
local spawn = require"vicious.spawn"
|
local spawn = require("vicious.spawn")
|
||||||
-- }}}
|
-- }}}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue