feat: add monitor support
This commit is contained in:
@@ -20,6 +20,9 @@ local MSG_HEADER = 0x747574656C
|
|||||||
local modem = peripheral.find("modem") or error("No modems found", 0)
|
local modem = peripheral.find("modem") or error("No modems found", 0)
|
||||||
modem.open(HOST_CHANNEL)
|
modem.open(HOST_CHANNEL)
|
||||||
|
|
||||||
|
local monitor = peripheral.find("monitor")
|
||||||
|
local scr = monitor or term
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
helper functions
|
helper functions
|
||||||
]]
|
]]
|
||||||
@@ -295,8 +298,8 @@ function drawLogs(x0, y0, x1, y1)
|
|||||||
local entry = log.buffer[i]
|
local entry = log.buffer[i]
|
||||||
local format = logTypes[entry.type]
|
local format = logTypes[entry.type]
|
||||||
|
|
||||||
local prevColourBg = term.getBackgroundColour()
|
local prevColourBg = scr.getBackgroundColour()
|
||||||
local prevColourFg = term.getTextColour()
|
local prevColourFg = scr.getTextColour()
|
||||||
|
|
||||||
local prefix = ("[%s]"):format(entry.type)
|
local prefix = ("[%s]"):format(entry.type)
|
||||||
local prefixLength = #prefix
|
local prefixLength = #prefix
|
||||||
@@ -318,93 +321,93 @@ function drawLogs(x0, y0, x1, y1)
|
|||||||
|
|
||||||
local line = wrappedMessage[lineIdx]
|
local line = wrappedMessage[lineIdx]
|
||||||
|
|
||||||
term.setCursorPos(1, y1 - drawnLines)
|
scr.setCursorPos(1, y1 - drawnLines)
|
||||||
|
|
||||||
if lineIdx == 1 then
|
if lineIdx == 1 then
|
||||||
term.setBackgroundColor(format.BG)
|
scr.setBackgroundColor(format.BG)
|
||||||
term.setTextColor(format.FG)
|
scr.setTextColor(format.FG)
|
||||||
term.write(prefix)
|
scr.write(prefix)
|
||||||
else
|
else
|
||||||
term.setBackgroundColor(messageBG)
|
scr.setBackgroundColor(messageBG)
|
||||||
term.write((" "):rep(prefixLength))
|
scr.write((" "):rep(prefixLength))
|
||||||
end
|
end
|
||||||
|
|
||||||
term.setBackgroundColor(messageBG)
|
scr.setBackgroundColor(messageBG)
|
||||||
term.setTextColor(messageFG)
|
scr.setTextColor(messageFG)
|
||||||
term.write(" ")
|
scr.write(" ")
|
||||||
term.write(line)
|
scr.write(line)
|
||||||
|
|
||||||
local remaining = w - (prefixLength + #line)
|
local remaining = w - (prefixLength + #line)
|
||||||
if remaining > 0 then
|
if remaining > 0 then
|
||||||
term.write((" "):rep(remaining))
|
scr.write((" "):rep(remaining))
|
||||||
end
|
end
|
||||||
|
|
||||||
drawnLines = drawnLines + 1
|
drawnLines = drawnLines + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
term.setBackgroundColor(prevColourBg)
|
scr.setBackgroundColor(prevColourBg)
|
||||||
term.setTextColor(prevColourFg)
|
scr.setTextColor(prevColourFg)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function drawStatusBar(y)
|
function drawStatusBar(y)
|
||||||
term.setCursorPos(1, y)
|
scr.setCursorPos(1, y)
|
||||||
|
|
||||||
term.setBackgroundColor(colors.gray)
|
scr.setBackgroundColor(colors.gray)
|
||||||
term.setTextColor(colors.white)
|
scr.setTextColor(colors.white)
|
||||||
term.clearLine()
|
scr.clearLine()
|
||||||
|
|
||||||
local str = ("turtles: %d"):format(#turtles)
|
local str = ("turtles: %d"):format(#turtles)
|
||||||
term.write(str)
|
scr.write(str)
|
||||||
end
|
end
|
||||||
|
|
||||||
function drawCommandBar(w, y)
|
function drawCommandBar(w, y)
|
||||||
term.setCursorPos(1, y)
|
scr.setCursorPos(1, y)
|
||||||
|
|
||||||
term.setBackgroundColor(colors.gray)
|
scr.setBackgroundColor(colors.gray)
|
||||||
term.setTextColor(colors.white)
|
scr.setTextColor(colors.white)
|
||||||
|
|
||||||
term.clearLine()
|
scr.clearLine()
|
||||||
|
|
||||||
term.write("$ ")
|
scr.write("$ ")
|
||||||
|
|
||||||
local startingIndex = commandBuffer:len() - w + 4
|
local startingIndex = commandBuffer:len() - w + 4
|
||||||
if startingIndex < 0 then
|
if startingIndex < 0 then
|
||||||
startingIndex = 0
|
startingIndex = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
term.write(commandBuffer:sub(startingIndex))
|
scr.write(commandBuffer:sub(startingIndex))
|
||||||
term.setCursorBlink(true)
|
scr.setCursorBlink(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
main loop functions
|
main loop functions
|
||||||
]]
|
]]
|
||||||
function updateScreen()
|
function updateScreen()
|
||||||
local w, h = term.getSize()
|
local w, h = scr.getSize()
|
||||||
|
|
||||||
local function drawTextCentered(text)
|
local function drawTextCentered(text)
|
||||||
local x = (w / 2) - (text:len() / 2)
|
local x = (w / 2) - (text:len() / 2)
|
||||||
local _, curY = term.getCursorPos()
|
local _, curY = scr.getCursorPos()
|
||||||
term.setCursorPos(x, curY)
|
scr.setCursorPos(x, curY)
|
||||||
term.write(text)
|
scr.write(text)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- reset state and clear screen
|
-- reset state and clear screen
|
||||||
term.setBackgroundColor(colors.black)
|
scr.setBackgroundColor(colors.black)
|
||||||
term.clear()
|
scr.clear()
|
||||||
|
|
||||||
-- -- title bar
|
-- -- title bar
|
||||||
term.setCursorPos(1, 1)
|
scr.setCursorPos(1, 1)
|
||||||
|
|
||||||
term.setBackgroundColor(colors.lightGray)
|
scr.setBackgroundColor(colors.lightGray)
|
||||||
term.setTextColour(colors.black)
|
scr.setTextColour(colors.black)
|
||||||
|
|
||||||
term.clearLine()
|
scr.clearLine()
|
||||||
drawTextCentered("tutel host controller")
|
drawTextCentered("tutel host controller")
|
||||||
|
|
||||||
term.setBackgroundColor(colors.black)
|
scr.setBackgroundColor(colors.black)
|
||||||
term.setTextColour(colors.white)
|
scr.setTextColour(colors.white)
|
||||||
|
|
||||||
drawLogs(1, 2, w, h - 1)
|
drawLogs(1, 2, w, h - 1)
|
||||||
drawStatusBar(2)
|
drawStatusBar(2)
|
||||||
|
|||||||
Reference in New Issue
Block a user