[FreeBSD] switched to async call (and fixed previous bug)
This commit is contained in:
parent
992d835c2e
commit
73b664b63e
|
@ -17,7 +17,7 @@ local bat_freebsd = {}
|
||||||
-- {{{ Battery widget type
|
-- {{{ Battery widget type
|
||||||
local function parse(stdout, stderr, exitreason, exitcode)
|
local function parse(stdout, stderr, exitreason, exitcode)
|
||||||
local bat_info = {}
|
local bat_info = {}
|
||||||
for line in string.gmatch(s,"[^\n]+") do
|
for line in string.gmatch(stdout, "[^\n]+") 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
|
||||||
|
@ -65,11 +65,11 @@ local function parse(stdout, stderr, exitreason, exitcode)
|
||||||
return {state, percent, time, wear, rate}
|
return {state, percent, time, wear, rate}
|
||||||
end
|
end
|
||||||
|
|
||||||
function battery_freebsd.async(format, warg, callback)
|
function bat_freebsd.async(format, warg, callback)
|
||||||
local battery = warg or "batt"
|
local battery = warg or "batt"
|
||||||
spawn.easy_async("acpiconf -i " .. helpers.shellquote(battery),
|
spawn.easy_async("acpiconf -i " .. helpers.shellquote(battery),
|
||||||
function (...) callback(parse(...)) end)
|
function (...) callback(parse(...)) end)
|
||||||
end
|
end
|
||||||
-- }}}
|
-- }}}
|
||||||
|
|
||||||
return helpers.setasyncall(battery_freebsd)
|
return helpers.setasyncall(bat_freebsd)
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
-- {{{ Grab environment
|
-- {{{ Grab environment
|
||||||
local tonumber = tonumber
|
local tonumber = tonumber
|
||||||
local setmetatable = setmetatable
|
|
||||||
local math = { floor = math.floor }
|
local math = { floor = math.floor }
|
||||||
local io = { popen = io.popen }
|
|
||||||
local helpers = require("vicious.helpers")
|
local helpers = require("vicious.helpers")
|
||||||
|
local spawn = require("vicious.spawn")
|
||||||
|
local string = {
|
||||||
|
match = string.match,
|
||||||
|
gmatch = string.gmatch
|
||||||
|
}
|
||||||
-- }}}
|
-- }}}
|
||||||
|
|
||||||
-- Mem: provides RAM and Swap usage statistics
|
-- Mem: provides RAM and Swap usage statistics
|
||||||
|
@ -12,7 +15,7 @@ local mem_freebsd = {}
|
||||||
|
|
||||||
|
|
||||||
-- {{{ Memory widget type
|
-- {{{ Memory widget type
|
||||||
local function worker(format)
|
local function parse(stdout, stderr, exitreason, exitcode)
|
||||||
local pagesize = tonumber(helpers.sysctl("hw.pagesize"))
|
local pagesize = tonumber(helpers.sysctl("hw.pagesize"))
|
||||||
local vm_stats = helpers.sysctl_table("vm.stats.vm")
|
local vm_stats = helpers.sysctl_table("vm.stats.vm")
|
||||||
local _mem = { buf = {}, total = nil }
|
local _mem = { buf = {}, total = nil }
|
||||||
|
@ -54,19 +57,20 @@ local function worker(format)
|
||||||
_swp.total = 0
|
_swp.total = 0
|
||||||
_swp.buf.free = 0
|
_swp.buf.free = 0
|
||||||
|
|
||||||
-- Read output of swapinfo in Mbytes
|
-- Read output of swapinfo in Mbytes (from async function call)
|
||||||
local f = io.popen("swapinfo -m")
|
|
||||||
-- Skip first line (table header)
|
|
||||||
f:read("*line")
|
|
||||||
-- Read content and sum up
|
-- Read content and sum up
|
||||||
for line in f:lines() do
|
local counter = 1
|
||||||
local ltotal, lused, lfree = string.match(line, "%s+([%d]+)%s+([%d]+)%s+([%d]+)")
|
for line in string.gmatch(stdout, "[^\n]+") do
|
||||||
-- Add swap space in Mbytes
|
-- Skip first line (table header)
|
||||||
_swp.total = _swp.total + tonumber(ltotal)
|
if counter ~= 1 then
|
||||||
_swp.inuse = _swp.inuse + tonumber(lused)
|
local ltotal, lused, lfree = string.match(line, "%s+([%d]+)%s+([%d]+)%s+([%d]+)")
|
||||||
_swp.buf.free = _swp.buf.free + tonumber(lfree)
|
-- Add swap space in Mbytes
|
||||||
|
_swp.total = _swp.total + tonumber(ltotal)
|
||||||
|
_swp.inuse = _swp.inuse + tonumber(lused)
|
||||||
|
_swp.buf.free = _swp.buf.free + tonumber(lfree)
|
||||||
|
end
|
||||||
|
counter = counter + 1
|
||||||
end
|
end
|
||||||
f:close()
|
|
||||||
|
|
||||||
-- Calculate percentage
|
-- Calculate percentage
|
||||||
_swp.usep = math.floor(_swp.inuse / _swp.total * 100)
|
_swp.usep = math.floor(_swp.inuse / _swp.total * 100)
|
||||||
|
@ -82,4 +86,10 @@ local function worker(format)
|
||||||
_mem.wirep, _mem.wire, _mem.notfreeablep, _mem.notfreeable }
|
_mem.wirep, _mem.wire, _mem.notfreeablep, _mem.notfreeable }
|
||||||
end
|
end
|
||||||
|
|
||||||
return setmetatable(mem_freebsd, { __call = function(_, ...) return worker(...) end })
|
function mem_freebsd.async(format, warg, callback)
|
||||||
|
spawn.easy_async("swapinfo -m",
|
||||||
|
function (...) callback(parse(...)) end)
|
||||||
|
end
|
||||||
|
-- }}}
|
||||||
|
|
||||||
|
return helpers.setasyncall(mem_freebsd)
|
||||||
|
|
|
@ -16,14 +16,14 @@ local STATE = { on = '🔉', off = '🔈' }
|
||||||
|
|
||||||
local function parse(stdout, stderr, exitreason, exitcode)
|
local function parse(stdout, stderr, exitreason, exitcode)
|
||||||
-- Capture mixer control state, e.g. 42 : 42
|
-- Capture mixer control state, e.g. 42 : 42
|
||||||
local voll, volr = string.match(stdout, "([%d]+):([%d]+)$")
|
local voll, volr = string.match(stdout, "([%d]+):([%d]+)\n$")
|
||||||
if voll == "0" and volr == "0" then return { 0, 0, STATE.off } end
|
if voll == "0" and volr == "0" then return { 0, 0, STATE.off } end
|
||||||
return { tonumber(voll), tonumber(volr), STATE.on }
|
return { tonumber(voll), tonumber(volr), STATE.on }
|
||||||
end
|
end
|
||||||
|
|
||||||
function volume_freebsd.async(format, warg, callback)
|
function volume_freebsd.async(format, warg, callback)
|
||||||
if not warg then return callback{} end
|
if not warg then return callback{} end
|
||||||
spawn.easy_async("mixer -s " .. helpers.shellquote(warg),
|
spawn.easy_async("mixer " .. helpers.shellquote(warg),
|
||||||
function (...) callback(parse(...)) end)
|
function (...) callback(parse(...)) end)
|
||||||
end
|
end
|
||||||
-- }}}
|
-- }}}
|
||||||
|
|
Loading…
Reference in New Issue