aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian C. (anrxc) <anrxc@sysphere.org>2009-11-18 00:05:52 +0100
committerAdrian C. (anrxc) <anrxc@sysphere.org>2009-11-18 00:05:52 +0100
commit5cbd75996be3536672cbd2b1c5166c3ce7238f30 (patch)
tree779d425f28a0bf515290b0ea1cb6e6fab04d8e2b
parent14d69f6478c97a6561d6f8181ee166d9d73f19c3 (diff)
downloadvicious-legacy-5cbd75996be3536672cbd2b1c5166c3ce7238f30.tar.xz
net: move formatting out of the worker
-rw-r--r--net.lua19
1 files changed, 10 insertions, 9 deletions
diff --git a/net.lua b/net.lua
index 69006e8..5bd1c13 100644
--- a/net.lua
+++ b/net.lua
@@ -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