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
+13 -9
View File
@@ -4,8 +4,17 @@ _G._OSVERSION = "HALYDE VERSION" -- TODO: Put this in a separate config file
_G._OSLOGO = ""
_G._PUBLIC = {}
_G._PUBLIC.unicode = assert(loadfile("/lib/unicode.lua")(loadfile))
local component = assert(loadfile("/lib/component.lua")(loadfile))
local gpu = component.gpu
local screenAddress = component.list("screen")()
gpu.bind(screenAddress)
gpu.setResolution(gpu.maxResolution())
local log = assert(loadfile("/lib/log.lua")(loadfile))
log.kernel.info("Bound GPU to screen " .. tostring(screenAddress))
local handle, tmpdata = filesystem.open("/halyde/config/oslogo.ans", "r"), nil
repeat
tmpdata = handle:read(math.huge)
@@ -68,16 +77,11 @@ log.kernel.info("Loading modules")
require("/halyde/kernel/modload.lua")
package.preload("component")
log.kernel.info("Pre-loaded /lib/component.lua")
package.preload("computer")
log.kernel.info("Pre-loaded low-level packages")
local component = require("component")
local gpu = component.gpu
local screenAddress = component.list("screen")()
gpu.bind(screenAddress)
gpu.setResolution(gpu.maxResolution())
log.kernel.info("Bound GPU to screen " .. tostring(screenAddress))
log.kernel.info("Pre-loaded /lib/computer.lua")
package.preload("log")
log.kernel.info("Pre-loaded /lib/log.lua")
if not filesystem.exists("/halyde/config/shell.json") then -- Auto-generate configs
filesystem.copy("/halyde/config/generate/shell.json", "/halyde/config/shell.json")
+15 -5
View File
@@ -11,6 +11,8 @@ local computer = require("computer")
local filesystem = require("filesystem")
local json = require("json")
local gpu = component.gpu
local log = require("log")
function _G._PUBLIC.tsched.runAsTask(path, ...)
local args = { ... }
local function taskFunction()
@@ -62,6 +64,12 @@ function _G._PUBLIC.tsched.addTask(func, name)
end
table.insert(tsched.tasks, taskInfo)
idCounter = idCounter + 1
if taskInfo.parent then
log.kernel.info("Created task " .. name .. " with PID " .. idCounter - 1 .. " by parent with PID " .. taskInfo
.parent)
else
log.kernel.info("Created task " .. name .. " with PID " .. idCounter - 1 .. " (no parent found)")
end
return task, taskInfo
end
@@ -70,14 +78,16 @@ function _G._PUBLIC.tsched.removeTask(id)
for index, task in pairs(tsched.tasks) do
if task.id == id then
table.remove(tsched.tasks, index)
log.kernel.info("Removed task with PID " .. id)
return true
end
end
log.kernel.warn("Tried to remove task that doesn't exist - PID " .. id)
return false
end
function handleError(errormsg)
if errormsg == nil then -- TODO: Replace with proper error handling (if this isn't considered proper..?)
if errormsg == nil then -- TODO: Replace with proper error handling
print("\27[91munknown error" .. "\n \n" .. debug.traceback())
else
print("\27[91m" .. tostring(errormsg) .. "\n \n" .. debug.traceback())
@@ -138,6 +148,7 @@ end
_PUBLIC.tsched.addTask(taskFunction, "evmgr")
package.preload("event")
log.kernel.info("Starting startup apps...")
local handle, data, tmpdata = filesystem.open("/halyde/config/startupapps.json", "r"), "", nil
repeat
tmpdata = handle:read(math.huge or math.maxinteger)
@@ -155,12 +166,11 @@ for _, line in ipairs(json.decode(data)) do
end
-- _G.cormgr.loadCoroutine("/halyde/core/shell.lua")
log.setPrintLogs(false)
while true do
runTasks()
if #_G.tsched.tasks == 0 then
computer.beep(1000, 0.5)
while true do
computer.pullSignal()
end
log.kernel.warn("No more tasks left! Shutting down...")
computer.shutdown()
end
end
+6
View File
@@ -18,18 +18,22 @@ _G.shell = {}
function _G.shell.getWorkingDirectory()
return workingDirectory
end
function _G.shell.setWorkingDirectory(dir)
checkArg(1, dir, "string")
workingDirectory = dir
end
function _G.shell.getAliases()
return table.copy(aliases)
end
function _G.shell.addAlias(executable, aliasName)
checkArg(1, executable, "string")
checkArg(2, aliasName, "string")
aliases[aliasName] = executable
end
function _G.shell.removeAlias(aliasName)
checkArg(1, aliasName, "string")
aliases[aliasName] = nil
@@ -122,6 +126,8 @@ end
local shareTable = ipc.shareWithAll()
shareTable.shell = _G.shell
terminal.clear()
print(shellcfg["startupMessage"]:format(_OSVERSION, shellcfg.splashMessages[math.random(1, #shellcfg.splashMessages)]))
while true do
coroutine.yield()
+9 -5
View File
@@ -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)
setmetatable(componentList, {
__call = function(self)
i, value = next(self, i)
return i, value
end})
end
})
return componentList
end
@@ -100,12 +102,14 @@ function compLib.get(address)
end
-- Add main component proxies to the library
setmetatable(compLib, {["__index"] = function(_, 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