From 06d96a92baaaa309155f0c9a62ba5169953eec8d Mon Sep 17 00:00:00 2001 From: mutlusun Date: Mon, 27 May 2019 09:52:00 +0200 Subject: [PATCH] [net_freebsd] Switched to async spawn --- widgets/net_freebsd.lua | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/widgets/net_freebsd.lua b/widgets/net_freebsd.lua index f78b016..2aa1180 100644 --- a/widgets/net_freebsd.lua +++ b/widgets/net_freebsd.lua @@ -1,10 +1,12 @@ -- {{{ Grab environment local tonumber = tonumber local os = { time = os.time } -local setmetatable = setmetatable local helpers = require("vicious.helpers") -local io = { popen = io.popen } -local string = { match = string.match } +local spawn = require("vicious.spawn") +local string = { + match = string.match, + gmatch = string.gmatch +} -- }}} @@ -21,15 +23,13 @@ local unit = { ["b"] = 1, ["kb"] = 1024, } -- {{{ Net widget type -local function worker(format, warg) - if not warg then return end +local function parse(stdout, stderr, exitreason, exitcode) local args = {} local buffer = nil - local f = io.popen("netstat -n -b -I " .. helpers.shellquote(warg)) local now = os.time() - for line in f:lines() do + for line in string.gmatch(stdout, "[^\n]+") do if not (line:find("