pkg-config is needed to build wmiirc-lua (thanks hsuh)
[wmiirc-lua.git] / plugins / dstat_load.lua
blob68cd63bfc99e66dadc869c83dd7011bf391d3b3a
1 --
2 -- Copyright (c) 2007, Bart Trojanowski <bart@jukie.net>
3 --
4 -- Simple load applet for wmii bar.
5 --
6 -- NOTE: dstat is required.
7 --
8 local wmii = require("wmii")
9 local os = require("os")
10 local math = require("math")
11 local string = require("string")
12 local type = type
13 local tonumber = tonumber
14 local tostring = tostring
16 module("dstat_load")
17 api_version=0.1
19 local palette = { "#888888",
20 "#999988",
21 "#AAAA88",
22 "#BBBB88",
24 "#CCCC88",
25 "#CCBB88",
26 "#CCAA88",
28 "#DD9988",
29 "#EE8888",
30 "#FF4444",
33 local widget = wmii.widget:new ("800_dstat_load")
34 wmii.add_exec ("TERM=vt100 dstat --load --nocolor --noheaders --noupdate 1",
35 function (line)
36 if type(line) ~= "string" then
37 return
38 end
40 local line = line:gsub ("%W%W+", " ")
41 if line:len() < 5 then
42 return
43 end
45 local tmp = line:match("([%d.]+)%D")
46 local current = tonumber(tmp)
48 local colors = nil
49 if type(current) == "number" then
50 local index = math.min (math.floor(current * (#palette-1)) + 1, #palette)
51 local normal = wmii.get_ctl("normcolors")
52 colors = string.gsub(normal, "^%S+", palette[index], 1)
53 end
55 widget:show (line, colors)
56 end)