diff --git a/lua/CC Tweaked/tutel/tutel-host.lua b/lua/CC Tweaked/tutel/tutel-host.lua index aaaba95..c5a5efa 100644 --- a/lua/CC Tweaked/tutel/tutel-host.lua +++ b/lua/CC Tweaked/tutel/tutel-host.lua @@ -128,12 +128,12 @@ declareCommandHandler("SCAN", handleScan, event handling ]] local eventListeners = {} -local function registerEventListener(name, listener) +function registerEventListener(name, listener) if not eventListeners[name] then eventListeners[name] = {} end table.insert(eventListeners[name], listener) end -local function dispatchEvents(event, ...) +function dispatchEvents(event, ...) log.info("dispatching event: %s", event) local eventTbl = eventListeners[event] @@ -145,7 +145,7 @@ local function dispatchEvents(event, ...) end end -local function handleMessages(side, channel, replyChannel, message, dist) +function handleMessages(side, channel, replyChannel, message, dist) if channel ~= HOST_CHANNEL then return end -- msg validation @@ -182,6 +182,11 @@ local function handleMessages(side, channel, replyChannel, message, dist) end registerEventListener("modem_message", handleMessages) +function handleKey(key, isHeld) + log.info("key pressed (%d)", key) +end +registerEventListener("key", handleKey) + --[[ main ]] @@ -203,15 +208,23 @@ function updateScreen() term.write(text) end + -- reset state and clear screen term.setBackgroundColor(colors.black) term.clear() + + -- -- title bar term.setCursorPos(1, 1) term.setBackgroundColor(colors.lightGray) term.setTextColour(colors.black) + term.clearLine() drawTextCentered("tutel host controller") + + term.setBackgroundColor(colors.black) + term.setTextColour(colors.white) + -- logs local function drawLogs(startY, endY) for i = #log.buffer, 1, -1 do if i > endY then break end @@ -219,7 +232,7 @@ function updateScreen() local entry = log.buffer[i] local format = logTypes[entry.type] - term.setCursorPos(0, startY + i) + term.setCursorPos(0, startY - 1 + i) local prevColourBg = term.getBackgroundColour() local prevColourFg = term.getTextColour()