feat: begin implementing console commands
This commit is contained in:
@@ -233,6 +233,8 @@ registerEventListener("modem_message", handleMessages)
|
|||||||
]]
|
]]
|
||||||
local GLFW_KEY_DOWN = 264
|
local GLFW_KEY_DOWN = 264
|
||||||
local GLFW_KEY_UP = 265
|
local GLFW_KEY_UP = 265
|
||||||
|
local GLFW_KEY_ENTER = 257
|
||||||
|
|
||||||
local logOffset = 0
|
local logOffset = 0
|
||||||
|
|
||||||
function scrollLogs(key, isHeld)
|
function scrollLogs(key, isHeld)
|
||||||
@@ -248,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
|
||||||
]]
|
]]
|
||||||
@@ -325,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
|
||||||
]]
|
]]
|
||||||
@@ -354,10 +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)
|
|
||||||
drawStatusBar(h)
|
|
||||||
drawLogs(1, 2, w, h - 2)
|
drawLogs(1, 2, w, h - 2)
|
||||||
drawStatusBar(2)
|
drawStatusBar(2)
|
||||||
|
drawCommandBar(w, h)
|
||||||
end
|
end
|
||||||
|
|
||||||
function pollEvents()
|
function pollEvents()
|
||||||
|
|||||||
Reference in New Issue
Block a user