more TODO updates
[wmiirc-lua.git] / plugins / messages.lua
blob17936aa1734ff66ead56aee02fe43c3acbbbed5d
1 --
2 -- Copyright (c) 2007, Bart Trojanowski <bart@jukie.net>
3 --
4 -- Notification area for wmii bar
5 --
6 -- To get a messages use:
7 --
8 -- wmiir xwrite /event msg anything you want to see
9 --
10 -- If you have a script that seldom generates one-line events, you can run:
12 -- somescript | sed -u 's/^/msg /' | wmiir write /event
13 -- or
14 -- ssh remote tail -F log-file | xargs -n1 -i wmiir xwrite /event "msg {}"
17 local wmii = require("wmii")
18 local os = require("os")
19 local math = require("math")
20 local string = require("string")
21 local tostring = tostring
23 module ("messages")
24 api_version=0.1
26 -- local variables
27 local color_index = 0
28 local colors = {}
29 local color_start = {{0xFF,0xFF,0xFF}, {0xAA,0x22,0xAA}, {0xFF,0x00,0x00}}
30 local color_end = {{0x44,0x44,0x44}, {0x22,0x22,0x22}, {0x33,0x33,0x33}}
31 local color_steps = 10
33 -- build up the colours palett
34 local i,t,r
35 for i=1,color_steps do
36 local x = ""
37 for t=1,3 do
38 local s=color_start[t]
39 local e=color_end[t]
40 x = x .. '#'
41 for r=1,3 do
42 local d = (e[r] - s[r]) / color_steps
43 local c = math.floor(s[r] + (i * d))
44 x = x .. string.format("%02x", c)
45 end
46 x = x .. ' '
47 end
48 colors[i] = x
49 end
51 -- get a widget; 0 is the first location in the /rbar, so the middle
52 local widget = wmii.widget:new ("0")
54 -- function that cycles the colours
55 local timer = wmii.timer:new (function (time_since_update)
56 color_index = color_index + 1
57 if not colors[color_index] then
58 return -1
59 end
61 widget:show (nil, colors[color_index])
62 return 1
63 end)
65 -- finally, an event we can listen for
66 wmii.add_event_handler ("msg", function (ev, args)
67 wmii.log("msg: " .. tostring(args))
69 timer:stop()
70 color_index = 1
71 widget:show (tostring(args), colors[color_index])
72 timer:resched(1)
73 end)