From 2e2714520bb95ef6a89cf0303ea469bef5e86f36 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Thu, 4 Aug 2022 03:56:41 +0100 Subject: chat --- chat.lua | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/chat.lua b/chat.lua index eecd88a..0b9cd73 100644 --- a/chat.lua +++ b/chat.lua @@ -26,12 +26,6 @@ local wLb = window.create(M,Mw-lbw+1,1,lbw,11) -- utils -local function p(thing,...) - local o=term.redirect(thing) - print(...) - term.redirect(o) -end - local function pad_r(s,width) return string.rep(" ",width-#tostring(s))..s end @@ -111,6 +105,31 @@ local function draw_lb(W,scores) end end +-- logging +local function log_msg(W,user,text,score) + local w,h = W.getSize() + W.scroll(1) + W.setCursorPos(1,h) + + local function st(c) W.setTextColor(c) end + local function wr(t) W.write(t) end + + st(colors.white) wr"<" st(colors.orange) wr(user) st(colors.white) wr"> (" + st(colors.cyan) wr(score) st(colors.white) wr(") ") st(colors.lightGray) + + local x,y = W.getCursorPos + local remsp = w-x+1 + if remsp >= 3 then + if #text > remsp then + text = text:sub(1,remsp-3).."..." + end + wr(text) + end +end + + + + -- persistence local function save_scores(scores) local file,err = fs.open(".chatscores","w") -- cgit v1.2.3