From c8c43d53ee6f4f70be7b220b0d1dafb13476258b Mon Sep 17 00:00:00 2001 From: mutlusun Date: Wed, 25 Jan 2017 17:54:14 +0100 Subject: [PATCH] port net widget to freebsd --- widgets/net_freebsd.lua | 83 ++++++++++++++++++++++++++++++ widgets/{net.lua => net_linux.lua} | 4 +- 2 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 widgets/net_freebsd.lua rename widgets/{net.lua => net_linux.lua} (96%) diff --git a/widgets/net_freebsd.lua b/widgets/net_freebsd.lua new file mode 100644 index 0000000..f78b016 --- /dev/null +++ b/widgets/net_freebsd.lua @@ -0,0 +1,83 @@ +-- {{{ 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 } +-- }}} + + +-- Net: provides state and usage statistics of all network interfaces +-- vicious.widgets.net +local net_freebsd = {} + + +-- Initialize function tables +local nets = {} +-- Variable definitions +local unit = { ["b"] = 1, ["kb"] = 1024, + ["mb"] = 1024^2, ["gb"] = 1024^3 +} + +-- {{{ Net widget type +local function worker(format, warg) + if not warg then return end + + 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 + if not (line:find("