From 3c235a7513ab89dfa3a18bf07168e3acce5efb7b Mon Sep 17 00:00:00 2001 From: neru Date: Thu, 8 May 2025 13:01:36 -0300 Subject: [PATCH] feat: begin implementing console commands --- lua/CC Tweaked/tutel/tutel-host.lua | 45 +++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/lua/CC Tweaked/tutel/tutel-host.lua b/lua/CC Tweaked/tutel/tutel-host.lua index 5242e6b..c8f4232 100644 --- a/lua/CC Tweaked/tutel/tutel-host.lua +++ b/lua/CC Tweaked/tutel/tutel-host.lua @@ -233,6 +233,8 @@ registerEventListener("modem_message", handleMessages) ]] local GLFW_KEY_DOWN = 264 local GLFW_KEY_UP = 265 +local GLFW_KEY_ENTER = 257 + local logOffset = 0 function scrollLogs(key, isHeld) @@ -248,6 +250,29 @@ end registerEventListener("key", scrollLogs) +--[[ + console +]] +local commandBuffer = "" +function drawConsole(y) + +end + + +function handleConsoleInput(char) + commandBuffer = commandBuffer..char +end +registerEventListener("char", handleConsoleInput) + +function handleConsoleKeys(key) + if key == GLFW_KEY_ENTER then + -- executeCommand(commandBuffer) + log.info("Executed command: %s", commandBuffer) + commandBuffer = "" + end +end +registerEventListener("key", handleConsoleKeys) + --[[ drawing functions ]] @@ -325,6 +350,23 @@ function drawStatusBar(y) term.write(str) end +function drawCommandBar(w, y) + term.setCursorPos(0, y) + term.clearLine() + + term.setBackgroundColor(colors.white) + term.setTextColor(colors.black) + + term.write("$ ") + + local startingIndex = commandBuffer:len() - w - 3 + if startingIndex < 0 then + startingIndex = 0 + end + + term.write(commandBuffer:sub(startingIndex)) +end + --[[ main loop functions ]] @@ -354,10 +396,9 @@ function updateScreen() term.setBackgroundColor(colors.black) term.setTextColour(colors.white) - drawLogs(1, 2, w, h - 1) - drawStatusBar(h) drawLogs(1, 2, w, h - 2) drawStatusBar(2) + drawCommandBar(w, h) end function pollEvents()