diff options
author | Adrian C. (anrxc) <anrxc@sysphere.org> | 2009-11-18 00:05:52 +0100 |
---|---|---|
committer | Adrian C. (anrxc) <anrxc@sysphere.org> | 2009-11-18 00:05:52 +0100 |
commit | 5cbd75996be3536672cbd2b1c5166c3ce7238f30 (patch) | |
tree | 779d425f28a0bf515290b0ea1cb6e6fab04d8e2b | |
parent | 14d69f6478c97a6561d6f8181ee166d9d73f19c3 (diff) | |
download | vicious-legacy-5cbd75996be3536672cbd2b1c5166c3ce7238f30.tar.xz |
net: move formatting out of the worker
-rw-r--r-- | net.lua | 19 |
1 files changed, 10 insertions, 9 deletions
@@ -24,21 +24,22 @@ module("vicious.net") -- Initialise function tables local nets = {} +-- {{{ 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 = {} - 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 - for line in f:lines() do -- Match wmaster0 as well as rt0 (multiple leading spaces) if string.match(line, "^[%s]?[%s]?[%s]?[%s]?[%w]+:") then |