Compare commits

...

3 Commits

Author SHA1 Message Date
neru 3c235a7513 feat: begin implementing console commands 2025-05-08 13:01:36 -03:00
neru f29770e3f0 feat: move command bar to top 2025-05-08 13:01:24 -03:00
neru 63c3e4e273 feat: add glfw key codes 2025-05-08 13:01:10 -03:00
+49 -4
View File
@@ -231,12 +231,16 @@ registerEventListener("modem_message", handleMessages)
--[[ --[[
key handling key handling
]] ]]
local GLFW_KEY_DOWN = 264
local GLFW_KEY_UP = 265
local GLFW_KEY_ENTER = 257
local logOffset = 0 local logOffset = 0
function scrollLogs(key, isHeld) function scrollLogs(key, isHeld)
if key == 264 then if key == GLFW_KEY_DOWN then
logOffset = logOffset - 1 logOffset = logOffset - 1
elseif key == 265 then elseif key == GLFW_KEY_UP then
logOffset = logOffset + 1 logOffset = logOffset + 1
end end
@@ -246,6 +250,29 @@ end
registerEventListener("key", scrollLogs) 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 drawing functions
]] ]]
@@ -323,6 +350,23 @@ function drawStatusBar(y)
term.write(str) term.write(str)
end 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 main loop functions
]] ]]
@@ -352,8 +396,9 @@ function updateScreen()
term.setBackgroundColor(colors.black) term.setBackgroundColor(colors.black)
term.setTextColour(colors.white) term.setTextColour(colors.white)
drawLogs(1, 2, w, h - 1) drawLogs(1, 2, w, h - 2)
drawStatusBar(h) drawStatusBar(2)
drawCommandBar(w, h)
end end
function pollEvents() function pollEvents()