Added log printing on the screen on startup.

The log library now prints all the logs on startup.
This commit is contained in:
2025-09-17 20:54:56 +03:00
parent 87d0e6bbcb
commit 39897457f9
5 changed files with 100 additions and 42 deletions
+18 -14
View File
@@ -11,7 +11,7 @@ end
--local ocelot = LLcomponent.proxy(LLcomponent.list("ocelot")())
--ocelot.log("loaded")
_G.componentlib = {["additions"] = {}, ["removals"] = {}}
_G.componentlib = { ["additions"] = {}, ["removals"] = {} }
compLib.virtual = {}
function compLib.virtual.add(address, componentType, proxy)
@@ -23,7 +23,7 @@ function compLib.virtual.add(address, componentType, proxy)
if _PUBLIC.tsched then
proc = _PUBLIC.tsched.getCurrentTask()
end
componentlib.additions[address] = {["componentType"] = componentType, ["proxy"] = proxy, ["proc"] = proc}
componentlib.additions[address] = { ["componentType"] = componentType, ["proxy"] = proxy, ["proc"] = proc }
if componentlib.removals[address] then
componentlib.removals[address] = nil
end
@@ -49,7 +49,7 @@ end
function compLib.list(componentType)
checkArg(1, componentType, "string", "nil")
local componentList = table.copy(LLcomponent.list(componentType))
local componentList = LLcomponent.list(componentType)
for address, dataTable in pairs(componentlib.additions) do
if dataTable.componentType == componentType or not componentType then
componentList[address] = dataTable.componentType
@@ -59,10 +59,12 @@ function compLib.list(componentType)
componentList[address] = nil
end
local i, value
setmetatable(componentList, {__call = function(self)
i, value = next(self, i)
return i, value
end})
setmetatable(componentList, {
__call = function(self)
i, value = next(self, i)
return i, value
end
})
return componentList
end
@@ -93,19 +95,21 @@ function compLib.get(address)
end
for currentAddress, name in compLib.list() do
if currentAddress:find("^" .. address) then
return(currentAddress)
return (currentAddress)
end
end
return nil, "full address not found"
end
-- Add main component proxies to the library
setmetatable(compLib, {["__index"] = function(_, item)
if compLib.list(item)() then
return compLib.proxy(compLib.list(item)())
else
return compLib[item]
setmetatable(compLib, {
["__index"] = function(_, item)
if compLib.list(item)() then
return compLib.proxy(compLib.list(item)())
else
return compLib[item]
end
end
end})
})
return compLib
+35 -1
View File
@@ -1,15 +1,24 @@
local fs, computer
local fs, computer, gpu
local chunkSize = 1024
if require then
fs = require("filesystem")
computer = require("computer")
gpu = require("component").gpu
else
local loadfile = ...
fs = loadfile("/lib/filesystem.lua")(loadfile)
computer = _G.computer
gpu = loadfile("/lib/component.lua")(loadfile).gpu
end
local resX, resY = gpu.getResolution()
local log = {}
if not _G.logSettings then
_G.logSettings = { -- We have to preload the library just for this :P
["printLogs"] = true,
["printerY"] = 1
}
end
local logFileSizeLimit = 16384
@@ -60,6 +69,26 @@ local function writeToLog(path, text)
readHandle:close()
writeHandle:close()
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 == ""
end
end
setmetatable(log, {
@@ -82,4 +111,9 @@ setmetatable(log, {
end,
})
function log.setPrintLogs(setting) -- Yes, this works with the metatable.
checkArg(1, setting, "boolean")
_G.logSettings.printLogs = setting
end
return log