diff options
-rw-r--r-- | beescroll.lua | 35 |
1 files changed, 17 insertions, 18 deletions
diff --git a/beescroll.lua b/beescroll.lua index 0481c01..858b1ac 100644 --- a/beescroll.lua +++ b/beescroll.lua @@ -29,30 +29,29 @@ local function maybe(list, prob) end end -local function slow_write(m,s) +local function write_str(m,s,slow) + local W,H = m.getSize() for i = 1,#s do m.write(s:sub(i,i)) - os.sleep(0.1) + if slow then + os.sleep(0.1) + end + if (m.getCursorPos()) == W then + m.scroll(1) + m.setCursorPos(1,H) + end end end -local function f_write(mon, tab, fn) +local function f_write(mon, tab, slow) for _,val in ipairs(tab) do - if type(val) == "string" then fn(mon, val) + if type(val) == "string" then write_str(mon, val, slow) elseif type(val) == "number" then mon.setTextColor(val) - else f_write(mon, val, fn) + else f_write(mon, val, slow) end end end -local function f_write_fast(mon, tab) - f_write(mon, tab, function(mon, str) mon.write(str) end) -end -local function f_write_slow(mon, tab) - f_write(mon, tab, function(mon, str) slow_write(mon, str) end) -end - - local norm_color = colors.gray local urgent = { "URGENT", "WARNING", "ALERT", "CRITICAL", "BREAKING" } @@ -65,9 +64,9 @@ local function pretitle() end local function beecount() - if math.random() < 0.4 then return {"all bees ", norm_color} end + if math.random() < 0.4 then return {colors.yellow, "all bees ", norm_color} end local n = ("%4d"):format(math.random(9999)) - return {n, " bees ", norm_color} + return {colors.yellow, n, " bees ", norm_color} end local function timeframe() @@ -80,7 +79,7 @@ end local function news_item() return { - " ", colors.red, choice(urgent), norm_color, ": ", + colors.red, choice(urgent), norm_color, ": ", "The ", choice{colors.red, colors.blue, colors.green}, pretitle(), choice(orgtype), " ", choice(orgs), norm_color, " has ", choice { -- the council has condemned all bees for [being/having been] boiled [illegally/without a permit/behind schedule] @@ -112,12 +111,12 @@ end for _ = 1,H do m.scroll(1) m.setCursorPos(1,H) - f_write_fast(m,make_entry()) + f_write(m,news_item(), false) end while true do m.scroll(1) m.setCursorPos(1,H) - f_write_slow(m, news_item()) + f_write(m, news_item(), true) os.sleep(math.random(5,100)/10) end |