Compare commits
4 Commits
c5ab37664b
...
5aea3bb618
| Author | SHA1 | Date | |
|---|---|---|---|
| 5aea3bb618 | |||
| 6fbb54c2cd | |||
| 283ee5cb71 | |||
| 9da79947d3 |
@@ -10,7 +10,14 @@
|
||||
]]
|
||||
|
||||
--[[
|
||||
network variables
|
||||
TO-DO List:
|
||||
* Add argument / funcion type checks on callback styled register functions
|
||||
* Make log screen scrolling work based on drawn lines not log indexes
|
||||
* Rename network commands to messages, to avoid confusion with console commands
|
||||
]]
|
||||
|
||||
--[[
|
||||
general variables
|
||||
]]
|
||||
local HOST_CHANNEL = 1337
|
||||
local TURTLE_CHANNEL_BASE = 1338
|
||||
@@ -23,6 +30,8 @@ modem.open(HOST_CHANNEL)
|
||||
local monitor = peripheral.find("monitor")
|
||||
local scr = monitor or term
|
||||
|
||||
local shouldRun = true
|
||||
|
||||
--[[
|
||||
helper functions
|
||||
]]
|
||||
@@ -257,9 +266,34 @@ registerEventListener("key", scrollLogs)
|
||||
--[[
|
||||
console
|
||||
]]
|
||||
local consoleCommands = {}
|
||||
local commandBuffer = ""
|
||||
function drawConsole(y)
|
||||
|
||||
function registerConsoleCommand(name, handler)
|
||||
consoleCommands[name] = handler
|
||||
end
|
||||
|
||||
function processCommand()
|
||||
local cmd
|
||||
local args = {}
|
||||
|
||||
for word in commandBuffer:gmatch('[^%s"]+|"[^"]*"') do
|
||||
word = word:gsub('^"(.*)"$', '%1')
|
||||
if not cmd then
|
||||
cmd = word
|
||||
else
|
||||
table.insert(args, word)
|
||||
end
|
||||
end
|
||||
|
||||
if consoleCommands[cmd] then
|
||||
log.info("> %s", cmd)
|
||||
consoleCommands[cmd](args)
|
||||
else
|
||||
log.warning("Unknown command: %s", cmd)
|
||||
end
|
||||
|
||||
commandBuffer = ""
|
||||
end
|
||||
|
||||
function handleConsoleInput(char)
|
||||
@@ -269,10 +303,8 @@ end
|
||||
registerEventListener("char", handleConsoleInput)
|
||||
|
||||
function handleConsoleKeys(key)
|
||||
if key == GLFW_KEY_ENTER then
|
||||
-- executeCommand(commandBuffer)
|
||||
log.info("Executed command: %s", commandBuffer)
|
||||
commandBuffer = ""
|
||||
if key == GLFW_KEY_ENTER and commandBuffer:len() > 0 then
|
||||
processCommand()
|
||||
elseif key == GLFW_KEY_BACKSPACE then
|
||||
local len = commandBuffer:len()
|
||||
if len >= 1 then
|
||||
@@ -283,10 +315,22 @@ end
|
||||
|
||||
registerEventListener("key", handleConsoleKeys)
|
||||
|
||||
--[[
|
||||
console commands
|
||||
]]
|
||||
function echoCommand(args)
|
||||
log.info(table.concat(args, " "))
|
||||
end
|
||||
registerConsoleCommand("echo", echoCommand)
|
||||
|
||||
function exitCommand(args)
|
||||
shouldRun = false
|
||||
end
|
||||
registerConsoleCommand("exit", exitCommand)
|
||||
|
||||
--[[
|
||||
drawing functions
|
||||
]]
|
||||
-- to-do: dont apply offset based on log entries but on lines
|
||||
function drawLogs(x0, y0, x1, y1)
|
||||
local w = x1 - x0
|
||||
local h = y1 - y0
|
||||
@@ -430,7 +474,7 @@ log.general("tutel host init")
|
||||
log.info("broadcasting SCAN")
|
||||
sendToAll("SCAN", { ["hostChannel"] = HOST_CHANNEL })
|
||||
|
||||
while true do
|
||||
while shouldRun do
|
||||
updateScreen()
|
||||
pollEvents()
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user