net: move formatting out of the worker

This commit is contained in:
Adrian C. (anrxc) 2009-11-18 00:05:52 +01:00
parent 14d69f6478
commit 5cbd75996b
1 changed files with 10 additions and 9 deletions

15
net.lua
View File

@ -24,20 +24,21 @@ module("vicious.net")
-- Initialise function tables
local nets = {}
-- {{{ Net widget type
local function worker(format)
-- Get /proc/net/dev
local f = io.open("/proc/net/dev")
local args = {}
-- {{{ Helper functions
local function uformat(array, key, value)
array["{"..key.."_b}"] = string.format("%.1f", value)
array["{"..key.."_kb}"] = string.format("%.1f", value/1024)
array["{"..key.."_mb}"] = string.format("%.1f", value/1024/1024)
array["{"..key.."_gb}"] = string.format("%.1f", value/1024/1024/1024)
return array
end
-- }}}
-- {{{ Net widget type
local function worker(format)
-- Get /proc/net/dev
local f = io.open("/proc/net/dev")
local args = {}
for line in f:lines() do
-- Match wmaster0 as well as rt0 (multiple leading spaces)