From 5cbd75996be3536672cbd2b1c5166c3ce7238f30 Mon Sep 17 00:00:00 2001 From: "Adrian C. (anrxc)" Date: Wed, 18 Nov 2009 00:05:52 +0100 Subject: [PATCH] net: move formatting out of the worker --- net.lua | 19 ++++++++++--------- 1 file 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