1 -- Authors: tyranix <tyranix@gmail.com>
2 -- License: Public domain
3 -- Last Changed: Unknown
7 Example of how to use statusd.popen_bgread() with coroutines to avoid blocking
10 This only has one key to keep it simple: %uname_a
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
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 ]
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
52 result
= result
.. partial_data
53 -- statusd.popen_bgread() will resume us when it has more data
54 partial_data
= coroutine
.yield()
57 -- If we have a new result, tell statusd
58 if result
and result
~= "" then
59 statusd
.inform("uname_a", result
)
62 -- Setup the next execution.
63 uname_timer
:set(settings
.update_interval
, update_uname
)
66 -- If we get any stderr, just print it out.
67 local function flush_stderr(partial_data
)
68 -- Continually grab stderr
71 result
= result
.. partial_data
72 partial_data
= coroutine
.yield()
75 if result
and result
~= "" then
76 print("STDERR:", result
, "\n")
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
))
87 -- Timer so we can keep telling statusd what the current value is.
88 uname_timer
= statusd
.create_timer()