style: move log function
This commit is contained in:
@@ -198,6 +198,43 @@ end
|
||||
|
||||
registerEventListener("key", scrollLogs)
|
||||
|
||||
--[[
|
||||
drawing functions
|
||||
]]
|
||||
local function drawLogs(x0, y0, x1, y1)
|
||||
local w = x1 - x0
|
||||
local h = y1 - y0
|
||||
|
||||
local drawnLines = 0
|
||||
for i = #log.bufer - logOffset, 1, -1 do
|
||||
if drawnLines > y then break end
|
||||
|
||||
local entry = log.buffer[i]
|
||||
local format = logTypes[entry.type]
|
||||
|
||||
term.setCursorPos(1, endY - drawnLines)
|
||||
|
||||
ocal prevColourBg = term.getBackgroundColour()
|
||||
local prevColourFg = term.getTextColour()
|
||||
|
||||
term.setBackgroundColour(format["BG"])
|
||||
term.setTextColour(format["FG"])
|
||||
term.write(("[%s]"):format(entry.type))
|
||||
|
||||
if format["AffectContent"] then
|
||||
term.write((" %s\n"):format(entry.message))
|
||||
term.setBackgroundColour(prevColourBg)
|
||||
term.setTextColour(prevColourFg)
|
||||
else
|
||||
term.setBackgroundColour(prevColourBg)
|
||||
term.setTextColour(prevColourFg)
|
||||
term.write((" %s\n"):format(entry.message))
|
||||
end
|
||||
|
||||
drawnLines = drawnLines + 1
|
||||
end
|
||||
end
|
||||
|
||||
--[[
|
||||
main loop functions
|
||||
]]
|
||||
@@ -228,38 +265,7 @@ function updateScreen()
|
||||
term.setTextColour(colors.white)
|
||||
|
||||
-- logs
|
||||
local function drawLogs(startY, endY)
|
||||
local drawnLines = 0
|
||||
for i = #log.buffer - logOffset, 1, -1 do
|
||||
if drawnLines > endY - startY then break end
|
||||
|
||||
local entry = log.buffer[i]
|
||||
local format = logTypes[entry.type]
|
||||
|
||||
term.setCursorPos(1, endY - drawnLines)
|
||||
|
||||
local prevColourBg = term.getBackgroundColour()
|
||||
local prevColourFg = term.getTextColour()
|
||||
|
||||
term.setBackgroundColour(format["BG"])
|
||||
term.setTextColour(format["FG"])
|
||||
term.write(("[%s]"):format(entry.type))
|
||||
|
||||
if format["AffectContent"] then
|
||||
term.write((" %s\n"):format(entry.message))
|
||||
term.setBackgroundColour(prevColourBg)
|
||||
term.setTextColour(prevColourFg)
|
||||
else
|
||||
term.setBackgroundColour(prevColourBg)
|
||||
term.setTextColour(prevColourFg)
|
||||
term.write((" %s\n"):format(entry.message))
|
||||
end
|
||||
|
||||
drawnLines = drawnLines + 1
|
||||
end
|
||||
end
|
||||
|
||||
drawLogs(2, h - 1)
|
||||
drawLogs(1, 2, w, h - 1)
|
||||
end
|
||||
|
||||
function pollEvents()
|
||||
|
||||
Reference in New Issue
Block a user