From 448275a3865d1db82a6fc37d60548da8b865e5e0 Mon Sep 17 00:00:00 2001 From: "Adrian C. (anrxc)" Date: Fri, 2 Apr 2010 01:08:12 +0200 Subject: widgets: reuse existing datasets where appropriate Gmail, mbox, raid, weather and wifi could return the old value in case there isn't new data, no need for N/A to be so common on our wibox. --- widgets/raid.lua | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'widgets/raid.lua') diff --git a/widgets/raid.lua b/widgets/raid.lua index eaf7825..3f9ef43 100644 --- a/widgets/raid.lua +++ b/widgets/raid.lua @@ -19,20 +19,23 @@ local string = { module("vicious.widgets.raid") +-- Initialize function tables +local mddev = {} + -- {{{ RAID widget type local function worker(format, warg) if not warg then return end - - local found = false - local mddev = {} - mddev[warg] = { - ["active"] = 0, - ["assigned"] = 0 - } + if not mddev[warg] then + mddev[warg] = { + ["found"] = false, + ["active"] = 0, + ["assigned"] = 0 + } + end -- Linux manual page: md(4) for line in io.lines("/proc/mdstat") do - if found then + if mddev[warg]["found"] then local updev = string.match(line, "%[[_U]+%]") for i in string.gmatch(updev, "U") do @@ -41,7 +44,7 @@ local function worker(format, warg) break elseif string.sub(line, 1, string.len(warg)) == warg then - found = true + mddev[warg]["found"] = true for i in string.gmatch(line, "%[%d%]") do mddev[warg]["assigned"] = mddev[warg]["assigned"] + 1 -- cgit v1.2.3