1 -- Authors: Matus Telgarsky <mtelgars@andrew.cmu.edu>
3 -- Last Changed: Unknown
5 -- little ticker boondoggle
7 -- Selects amongst a set of specified commands and scrolls them not only line by line
8 -- but also within each line. Waits and marks ends of lines, beginning of command.
9 -- Should work great with an rss reader though I didn't care to try.
11 -- Author: Matus Telgarsky < mtelgars at andrew dot cmu dot edu >
13 -- I couldn't sleep and felt like learning lua.
20 'printf "hello world"',
37 interval
= 0.375 * 1000,
39 update_fun
= nil, --forward decl hack
49 local function ticker_timer(style
)
50 statusd
.inform("ticker_hint", settings
[style
].hint
)
51 settings
.timer
:set(settings
[style
].interval
, settings
.update_fun
)
54 local function ticker_line_init()
55 message
.len
= string.len(message
.s
)
59 local function ticker_single()
60 return settings
.commands
[1]
63 local function ticker_random()
64 --don't do same twice, uniformly distribute chances across others
65 local newpos
= math
.random(1, settings
.commands
.count
-1)
66 if newpos
>= settings
.commands
.pos
then
70 settings
.commands
.pos
= newpos
71 return settings
.commands
[settings
.commands
.pos
]
74 local function ticker_rotate()
75 local c
= settings
.commands
[settings
.commands
.pos
]
77 if settings
.commands
.pos
== settings
.commands
.count
then
78 settings
.commands
.pos
= 1
80 settings
.commands
.pos
= settings
.commands
.pos
+ 1
86 local function ticker_update()
87 if message
.fd
== nil then
88 message
.fd
= io
.popen(settings
.commands
.get(), 'r')
89 message
.s
= message
.fd
:read()
90 if message
.s
then --XXX this is a bug workaround!
94 elseif message
.s
== nil then
95 message
.s
= message
.fd
:read()
96 if message
.s
== nil then
103 elseif message
.pos
+ settings
.line_len
>= message
.len
then
104 message
.s
= nil --hang out at the end of a line
107 message
.pos
= message
.pos
+ settings
.step
108 ticker_timer('scroll')
111 if message
.s
~= nil then
112 statusd
.inform("ticker",
113 string.sub(message
.s
, message
.pos
, message
.pos
+ settings
.line_len
))
117 if statusd
~= nil then
118 settings
.timer
= statusd
.create_timer()
119 statusd
.inform("ticker_template", string.rep('x', settings
.line_len
))
121 settings
.update_fun
= ticker_update
122 settings
.commands
.count
= #(settings
.commands
)
123 if settings
.commands
.count
== 1 then
124 settings
.commands
.get
= ticker_single
125 elseif settings
.random then
126 settings
.commands
.pos
= 1
127 settings
.commands
.get
= ticker_random
129 settings
.commands
.pos
= 1
130 settings
.commands
.get
= ticker_rotate