style: formatting
This commit is contained in:
@@ -25,11 +25,11 @@ modem.open(HOST_CHANNEL)
|
||||
]]
|
||||
function wrapText(text, maxWidth)
|
||||
if not text then return {} end
|
||||
if maxWidth <= 0 then return {text} end
|
||||
|
||||
if maxWidth <= 0 then return { text } end
|
||||
|
||||
local lines = {}
|
||||
local currentLine = ""
|
||||
|
||||
|
||||
for word, newline in text:gmatch("([^%s\n]*)(%s*\n?)") do
|
||||
if newline:find("\n") then
|
||||
if currentLine ~= "" then
|
||||
@@ -60,15 +60,14 @@ function wrapText(text, maxWidth)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
if currentLine ~= "" then
|
||||
table.insert(lines, currentLine)
|
||||
end
|
||||
|
||||
|
||||
return lines
|
||||
end
|
||||
|
||||
|
||||
--[[
|
||||
logging
|
||||
]]
|
||||
@@ -257,19 +256,19 @@ function drawLogs(x0, y0, x1, y1)
|
||||
local drawnLines = 0
|
||||
for i = #log.buffer - logOffset, 1, -1 do
|
||||
if drawnLines > h then break end
|
||||
|
||||
|
||||
local entry = log.buffer[i]
|
||||
local format = logTypes[entry.type]
|
||||
|
||||
|
||||
local prevColourBg = term.getBackgroundColour()
|
||||
local prevColourFg = term.getTextColour()
|
||||
|
||||
|
||||
local prefix = ("[%s]"):format(entry.type)
|
||||
local prefixLength = #prefix
|
||||
local maxMessageWidth = math.max(1, w - prefixLength)
|
||||
|
||||
local maxMessageWidth = math.max(1, w - prefixLength)
|
||||
|
||||
local wrappedMessage = wrapText(tostring(entry.message), maxMessageWidth)
|
||||
|
||||
|
||||
local messageBG, messageFG
|
||||
if format.AffectContent then
|
||||
messageBG = format.BG
|
||||
@@ -278,14 +277,14 @@ function drawLogs(x0, y0, x1, y1)
|
||||
messageBG = prevColourBg
|
||||
messageFG = prevColourFg
|
||||
end
|
||||
|
||||
for lineIdx=#wrappedMessage,1, -1 do
|
||||
|
||||
for lineIdx = #wrappedMessage, 1, -1 do
|
||||
if drawnLines > h then break end
|
||||
|
||||
|
||||
local line = wrappedMessage[lineIdx]
|
||||
|
||||
term.setCursorPos(1, y1 - drawnLines)
|
||||
|
||||
|
||||
if lineIdx == 1 then
|
||||
term.setBackgroundColor(format.BG)
|
||||
term.setTextColor(format.FG)
|
||||
@@ -294,12 +293,12 @@ function drawLogs(x0, y0, x1, y1)
|
||||
term.setBackgroundColor(messageBG)
|
||||
term.write((" "):rep(prefixLength))
|
||||
end
|
||||
|
||||
|
||||
term.setBackgroundColor(messageBG)
|
||||
term.setTextColor(messageFG)
|
||||
term.write(" ")
|
||||
term.write(line)
|
||||
|
||||
|
||||
local remaining = w - (prefixLength + #line)
|
||||
if remaining > 0 then
|
||||
term.write((" "):rep(remaining))
|
||||
|
||||
Reference in New Issue
Block a user