Include notionflux in the main repo instead of its own submodule
[notion/jeffpc.git] / contrib / statusd / statusd_uname.lua
blob3b9746b41c3ad50d7ebb08893ffecdd5524f4c6a
1 -- Authors: tyranix <tyranix@gmail.com>
2 -- License: Public domain
3 -- Last Changed: Unknown
4 --
5 -- statusd_uname.lua
6 --[[
7 Example of how to use statusd.popen_bgread() with coroutines to avoid blocking
8 while reading I/O.
10 This only has one key to keep it simple: %uname_a
12 Normal Usage:
14 1) If you do not have ~/.ion3/cfg_statusbar.lua, copy that file from Ion3 to
15 your ~/.ion3 directory. On Debian, it is in /etc/X11/ion3/cfg_statusbar.lua.
17 2) Ion3 will load the appropriate modules if they are in the template at
18 startup.
20 So place '%uname_a' into the template in ~/.ion3/cfg_statusbar.lua.
23 Also, if you want to test this independent of ion, you can do this:
25 1) Copy statusd_uname.lua to ~/.ion3/
27 2) Run '/usr/lib/ion3/ion-statusd -m uname'
28 This will dump out all of the updates to the terminal as they happen
30 3) Hit control+c when you are done testing.
33 License: Public domain
35 tyranix [ tyranix at gmail ]
37 --]]
39 local defaults={
40 -- Update every minute
41 update_interval=60*1000,
44 local uname_timer = nil
45 local settings=table.join(statusd.get_config("uname"), defaults)
47 -- Parse the output and then tell statusd when we have all of the value.
48 function parse_uname(partial_data)
49 -- Keep reading partial_data until it returns nil
50 local result = ""
51 while partial_data do
52 result = result .. partial_data
53 -- statusd.popen_bgread() will resume us when it has more data
54 partial_data = coroutine.yield()
55 end
57 -- If we have a new result, tell statusd
58 if result and result ~= "" then
59 statusd.inform("uname_a", result)
60 end
62 -- Setup the next execution.
63 uname_timer:set(settings.update_interval, update_uname)
64 end
66 -- If we get any stderr, just print it out.
67 local function flush_stderr(partial_data)
68 -- Continually grab stderr
69 local result = ""
70 while partial_data do
71 result = result .. partial_data
72 partial_data = coroutine.yield()
73 end
75 if result and result ~= "" then
76 print("STDERR:", result, "\n")
77 end
78 end
80 -- Query mocp to get information for statusd.
81 function update_uname()
82 statusd.popen_bgread('uname -a',
83 coroutine.wrap(parse_uname),
84 coroutine.wrap(flush_stderr))
85 end
87 -- Timer so we can keep telling statusd what the current value is.
88 uname_timer = statusd.create_timer()
89 update_uname()
91 -- vim:tw=0: