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