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