From c9883c2c648027e7045ca98a2642ef48d021f8cf Mon Sep 17 00:00:00 2001 From: Ponali Date: Mon, 20 Oct 2025 18:17:01 +0200 Subject: [PATCH] made all logs with multiple lines show up correctly before this commit, all logs with multiple lines show up as one whole string, where normally when a line would end and another would start, it displays as two wide characters showing "[LF][HT]". --- lib/log.lua | 49 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/lib/log.lua b/lib/log.lua index 0a2168c..250b629 100644 --- a/lib/log.lua +++ b/lib/log.lua @@ -20,6 +20,37 @@ if not _G.logSettings then } end +function getlines(s) + if s:sub(-1) ~= "\n" then + s = s .. "\n" + end + return s:gmatch("(.-)\n") +end + +local function writeToScreen(text) + -- Print onscreen + if text:sub(1, 4) == "INFO" then -- Set color + gpu.setForeground(0xFFFFFF) + elseif text:sub(1, 4) == "WARN" then + gpu.setForeground(0xFFFF00) + elseif text:sub(1, 5) == "ERROR" then + gpu.setForeground(0xFF0000) + end + local i = 0 + for line in getlines(text) do + line = line:gsub("\t", " ") + repeat -- Line wrapping + if _G.logSettings.printerY > resY then + gpu.copy(1, 2, resX, resY - 1, 0, -1) + _G.logSettings.printerY = resY + end + gpu.set(1, _G.logSettings.printerY, line .. string.rep(" ", resX - #line)) + line = line:sub(resX + 1) + _G.logSettings.printerY = _G.logSettings.printerY + 1 + until line == "" + end +end + local logFileSizeLimit = 16384 local function writeToLog(path, text) @@ -77,23 +108,7 @@ local function writeToLog(path, text) end if _G.logSettings.printLogs then - -- Print onscreen - if text:sub(1, 4) == "INFO" then -- Set color - gpu.setForeground(0xFFFFFF) - elseif text:sub(1, 4) == "WARN" then - gpu.setForeground(0xFFFF00) - elseif text:sub(1, 5) == "ERROR" then - gpu.setForeground(0xFF0000) - end - repeat -- Line wrapping - if _G.logSettings.printerY > resY then - gpu.copy(1, 2, resX, resY - 1, 0, -1) - _G.logSettings.printerY = resY - end - gpu.set(1, _G.logSettings.printerY, text .. string.rep(" ", resX - #text)) - text = text:sub(resX + 1) - _G.logSettings.printerY = _G.logSettings.printerY + 1 - until text == "" + writeToScreen(text) end end