From 0d7e6eb8e5ff30ef2fc52e83cff1731913d89d38 Mon Sep 17 00:00:00 2001 From: neru Date: Thu, 8 May 2025 01:58:29 -0300 Subject: [PATCH] style: formatting --- lua/CC Tweaked/tutel/tutel-host.lua | 35 ++++++++++++++--------------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/lua/CC Tweaked/tutel/tutel-host.lua b/lua/CC Tweaked/tutel/tutel-host.lua index bc7ab2c..41ca915 100644 --- a/lua/CC Tweaked/tutel/tutel-host.lua +++ b/lua/CC Tweaked/tutel/tutel-host.lua @@ -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))