fixed keys added more OS syscalls and added colored logging

This commit is contained in:
2026-01-20 11:33:24 -05:00
parent 72bfce7b08
commit 9bd9cdaba4
8 changed files with 57 additions and 33 deletions

View File

@@ -1,12 +1,12 @@
local userhost = syscall.OS_getUser().."@"..syscall.OS_getHostname() local userhost = (syscall.OS_getUser() or "Unknown").."@"..(syscall.OS_getHostname() or "Unknown")
print(".. *. .. | "..userhost) print(".. *. .. | "..userhost)
print(" *= +@* +* | "..string.rep("-",#userhost)) print(" *= +@* +* | "..string.rep("-",#userhost))
print(" .@#. -@@@= :#@. | OS: "..syscall.OS_version()) print(" .@#. -@@@= :#@. | OS: "..(syscall.OS_version() or "Unknown"))
print(" =@@+ *@@@# +@@= | Host: "..syscall.OS_getHost()) print(" =@@+ *@@@# +@@= | Host: "..(syscall.OS_getHost() or "Unknown"))
print(" %@@%: *@@@# -%@@% | Uptime: "..syscall.OS_getUptime()) print(" %@@%: *@@@# -%@@% | Uptime: "..(syscall.OS_getUptime() or "Unknown"))
print(" :@@@@+ *@@@# .*@@@@: | Tasks: "..tostring(#syscall.HPV_list())) print(" :@@@@+ *@@@# .*@@@@: | Tasks: "..tostring((#syscall.HPV_list() or "Unknown")))
print(" :*@@@%- *@@@# -@@@@*: | Packages: "..tostring()) print(" :*@@@%- *@@@# -@@@@*: | Packages: ".."Unknown")
print(" =%@@#. *@@@# .#@@%= | Shell: "..syscall.HPV_getEnviron("SHELL")) print(" =%@@#. *@@@# .#@@%= | Shell: "..(syscall.HPV_getEnviron("SHELL") or "Unknown"))
print(" :=. :*@@= *@@@# =@@+: .=: | ") print(" :=. :*@@= *@@@# =@@+: .=: | ")
print(" %@#=..*# +@@@# #*..=#@# | ") print(" %@#=..*# +@@@# #*..=#@# | ")
print(" .@@@@+=# .%@%: #=+@@@@. | ") print(" .@@@@+=# .%@%: #=+@@@@. | ")

View File

@@ -29,13 +29,18 @@ for i,v in ipairs(files) do
else else
syscall.HPV_spawn(function() syscall.HPV_spawn(function()
syscall.IO_bind("eventQueue:"..tostring(i)) syscall.IO_bind("eventQueue:"..tostring(i))
eventQueues[#eventQueues+1]="eventQueue:"..tostring(i) local spot = #eventQueues+1
eventQueues[spot]="eventQueue:"..tostring(i)
local status, err = pcall(startupFunc) local status, err = pcall(startupFunc)
if not status then if not status then
kernel.log("Error executing startup script '" .. filepath .. "': " .. err, "ERROR") kernel.log("Error executing startup script '" .. filepath .. "': " .. err, "ERROR")
else else
kernel.log("Successfully executed startup script: " .. filepath, "INFO") kernel.log("Successfully executed startup script: " .. filepath, "INFO")
end end
local event={true}
while event[1] do
syscall.IO_pullEvent()
end
end, "startup:" .. v) end, "startup:" .. v)
end end
end end

View File

@@ -13,6 +13,11 @@ local function write(text)
if c == "\n" then if c == "\n" then
y = y + 1 y = y + 1
x = 1 x = 1
if y-1 >= h then
term.scroll(1)
y = h
term.setCursorPos(x, y)
end
elseif c == "\t" then elseif c == "\t" then
local tabSize = 4 local tabSize = 4
local spaces = tabSize - ((x - 1) % tabSize) local spaces = tabSize - ((x - 1) % tabSize)
@@ -38,7 +43,7 @@ local function write(text)
y = y + 1 y = y + 1
end end
if y-1 > h then if y-1 >= h then
term.scroll(1) term.scroll(1)
y = h y = h
term.setCursorPos(x, y) term.setCursorPos(x, y)
@@ -66,7 +71,6 @@ local ok, err = xpcall(function()
local lua = { local lua = {
coroutine = true, coroutine = true,
debug = true, debug = true,
_HOST = true,
_VERSION = true, _VERSION = true,
assert = true, assert = true,
collectgarbage = true, collectgarbage = true,
@@ -160,7 +164,7 @@ local ok, err = xpcall(function()
local computer = { local computer = {
time = function() return apis.os.epoch("utc") end, time = function() return apis.os.epoch("utc") end,
clock = function() return apis.os.clock()/1000 end, clock = function() return apis.os.clock()*1000 end,
shutdown = apis.os.shutdown, shutdown = apis.os.shutdown,
reboot = apis.os.reboot, reboot = apis.os.reboot,
getMachineEvent = function() getMachineEvent = function()

View File

@@ -63,13 +63,13 @@ tKeys[keys.pageUp] = '\x1b[5~'
tKeys[keys.pageDown] = '\x1b[6~' tKeys[keys.pageDown] = '\x1b[6~'
tKeys[keys.home] = '\x1b[1~' tKeys[keys.home] = '\x1b[1~'
tKeys[keys["end"]] = '\x1b[4~' tKeys[keys["end"]] = '\x1b[4~'
tKeys[keys.capsLock] = '\x1b[capsLock' --tKeys[keys.capsLock] = '\x1b[capsLock'
tKeys[keys.scrollLock] = '\x1b[scrollLock' --tKeys[keys.scrollLock] = '\x1b[scrollLock'
tKeys[keys.numLock] = '\x1b[numLock' --tKeys[keys.numLock] = '\x1b[numLock'
if keys.printScreen then --if keys.printScreen then
tKeys[keys.printScreen] = '\x1b[printScreen' -- tKeys[keys.printScreen] = '\x1b[printScreen'
end --end
tKeys[keys.pause] = '\x1b[pause' --tKeys[keys.pause] = '\x1b[pause'
tKeys[keys.f1] = '\x1b[11~' tKeys[keys.f1] = '\x1b[11~'
tKeys[keys.f2] = '\x1b[12~' tKeys[keys.f2] = '\x1b[12~'
tKeys[keys.f3] = '\x1b[13~' tKeys[keys.f3] = '\x1b[13~'

View File

@@ -8,9 +8,11 @@ local computer = args[6]
local ifs = args[7] local ifs = args[7]
local kernel = {} local kernel = {}
kernel.LOG_Text="" kernel.LOG_Text=""
kernel.version="HyperionOS V1.0.0"
kernel.process = "Kernel" kernel.process = "Kernel"
kernel.user = "root" kernel.user = "root"
kernel.group = "root" kernel.group = "root"
kernel.hostname = "hyperion"
kernel.groups = {0} kernel.groups = {0}
kernel.uid = 0 kernel.uid = 0
kernel.gid = 0 kernel.gid = 0
@@ -24,13 +26,16 @@ kernel.sleep=sleep
_G.sleep=nil _G.sleep=nil
local windowsExp = false local windowsExp = false
function kernel.log(msg, level) function kernel.log(msg, level, c)
c=c or 12
kernel.LOG_Text = kernel.LOG_Text..tostring(computer:time()).." "..kernel.user.." "..kernel.process.."["..tostring(level or "INFO").."]: "..msg.."\n" kernel.LOG_Text = kernel.LOG_Text..tostring(computer:time()).." "..kernel.user.." "..kernel.process.."["..tostring(level or "INFO").."]: "..msg.."\n"
if kernel.status == "start" then if kernel.status == "start" then
screen:setTextColor(c)
screen:print(tostring(computer:time()).." "..kernel.user.." "..kernel.process.."["..tostring(level or "INFO").."]: "..msg) screen:print(tostring(computer:time()).." "..kernel.user.." "..kernel.process.."["..tostring(level or "INFO").."]: "..msg)
elseif kernel.status == "init" then elseif kernel.status == "init" then
kernel.standbyTask=kernel.currentTask kernel.standbyTask=kernel.currentTask
kernel.currentTask=kernel.kernelTask kernel.currentTask=kernel.kernelTask
kernel.tty.setTextColor(c)
kernel.tty.print(tostring(computer:time()).." "..kernel.user.." "..kernel.process.."["..tostring(level or "INFO").."]: "..msg) kernel.tty.print(tostring(computer:time()).." "..kernel.user.." "..kernel.process.."["..tostring(level or "INFO").."]: "..msg)
kernel.currentTask=kernel.standbyTask kernel.currentTask=kernel.standbyTask
end end
@@ -109,7 +114,7 @@ local split = function(str, delim, maxResultCountOrNil)
end end
if not ifs.isFile("/boot/boot.cfg") then if not ifs.isFile("/boot/boot.cfg") then
kernel.log("boot.cfg missing or corrupted!, Attempting to write recovery boot.cfg", "ERROR") kernel.log("boot.cfg missing or corrupted!, Attempting to write recovery boot.cfg", "ERROR", 2)
ifs.writeAllText("/boot/boot.cfg",ifs.readAllText("/boot/safeboot.cfg")) ifs.writeAllText("/boot/boot.cfg",ifs.readAllText("/boot/safeboot.cfg"))
end end
@@ -230,13 +235,20 @@ end
kernel.syscalls["OS_time"]=function() return kernel.computer:time() end kernel.syscalls["OS_time"]=function() return kernel.computer:time() end
kernel.syscalls["OS_log"]=kernel.log kernel.syscalls["OS_log"]=kernel.log
kernel.syscalls["OS_getUptime"]=function() return kernel.computer:clock() end
kernel.syscalls["OS_getUser"]=function() return kernel.user end
kernel.syscalls["OS_getHostname"]=function() return kernel.host end
kernel.syscalls["OS_getHost"]=function() return kernel.apis._HOST end
kernel.syscalls["OS_version"]=function() return kernel.version end
kernel.syscalls["OS_setHostname"]=function(name) if kernel.uid~=0 then error("Permission denied") end kernel.hostname=name end
kernel.syscalls["OS_setUser"]=function(uid) if kernel.uid~=0 then error("Permission denied") end kernel.currentTask.uid=uid end
kernel.log("Running modules") kernel.log("Running modules")
for _,p in ipairs(modules) do for _,p in ipairs(modules) do
for _,v in ipairs(p) do for _,v in ipairs(p) do
local code=ifs.readAllText(v) local code=ifs.readAllText(v)
if not code then if not code then
kernel.log("ModuReadErr: "..v, "WARN") kernel.log("ModuReadErr: "..v, "WARN", 8)
goto skip goto skip
end end
local func,err=load(code,"@"..v) local func,err=load(code,"@"..v)

View File

@@ -5,7 +5,7 @@ for i,v in ipairs(string.split(kernel.fstab,"\n")) do
local id="" local id=""
for i=3,#v do for i=3,#v do
if v:sub(i,i)==";" then if v:sub(i,i)==";" then
if i==3 then kernel.log("Invalid fstab line... Skipping.","WARN") goto endline end if i==3 then kernel.log("Invalid fstab line... Skipping.","WARN", 8) goto endline end
id=v:sub(3,i-1) id=v:sub(3,i-1)
end end
end end

View File

@@ -13,7 +13,7 @@ function sys.spawn(func, name, envars, args, tgid)
local ok, err = xpcall(func, debug.traceback, table.unpack(args or {})) local ok, err = xpcall(func, debug.traceback, table.unpack(args or {}))
if not ok then if not ok then
if kernel.config.logTaskExit then if kernel.config.logTaskExit then
kernel.log("Task "..tostring(id).." exited with err: "..tostring(err), "ERROR") kernel.log("Task "..tostring(id).." exited with err: "..tostring(err), "ERROR", 2)
end end
tasks[tostring(id)].status="Z" tasks[tostring(id)].status="Z"
tasks[tostring(id)].exit=err tasks[tostring(id)].exit=err
@@ -123,7 +123,7 @@ function sys.kill(pid)
end end
if not tasks[tostring(pid)] then if not tasks[tostring(pid)] then
return false, "Task does not exist" return false, "Task does not exist"
elseif not isEqualToAny(tasks[tostring(pid)].pid,table.unpack(children)) then elseif not isEqualToAny(tasks[tostring(pid)].pid,table.unpack(children)) and kernel.uid~=0 then
return false, "You do not own this task" return false, "You do not own this task"
elseif tasks[tostring(pid)].status=="Z" then elseif tasks[tostring(pid)].status=="Z" then
return false, "Task is already dead" return false, "Task is already dead"
@@ -140,7 +140,7 @@ function sys.stop(pid)
end end
if not tasks[tostring(pid)] then if not tasks[tostring(pid)] then
return false, "Task does not exist" return false, "Task does not exist"
elseif not isEqualToAny(tasks[tostring(pid)].pid,table.unpack(children)) then elseif not isEqualToAny(tasks[tostring(pid)].pid,table.unpack(children)) and kernel.uid~=0 then
return false, "You do not own this task" return false, "You do not own this task"
elseif tasks[tostring(pid)].status~="R" then elseif tasks[tostring(pid)].status~="R" then
return false, "Cannot stop non running task" return false, "Cannot stop non running task"
@@ -157,7 +157,7 @@ function sys.continue(pid)
end end
if not tasks[tostring(pid)] then if not tasks[tostring(pid)] then
return false, "Task does not exist" return false, "Task does not exist"
elseif not isEqualToAny(tasks[tostring(pid)].pid,table.unpack(children)) then elseif not isEqualToAny(tasks[tostring(pid)].pid,table.unpack(children)) and kernel.uid~=0 then
return false, "You do not own this task" return false, "You do not own this task"
elseif tasks[tostring(pid)].status~="T" then elseif tasks[tostring(pid)].status~="T" then
return false, "Task is not stopped" return false, "Task is not stopped"
@@ -271,6 +271,7 @@ function kernel.main()
kernel.vfs.cwd = task.cwd kernel.vfs.cwd = task.cwd
kernel.user = task.user kernel.user = task.user
kernel.uid = task.uid kernel.uid = task.uid
kernel.process = task.name
N = N + 1 N = N + 1
-- assign adaptive time slice -- assign adaptive time slice
@@ -298,7 +299,7 @@ function kernel.main()
-- handle task results -- handle task results
if ret[1] == "error" then if ret[1] == "error" then
kernel.log("processHandlerException: "..ret[2]) kernel.log("processHandlerException: "..ret[2], "ERROR", 2)
task.status = "Z" task.status = "Z"
task.exit = "processHandlerException: "..ret[2] task.exit = "processHandlerException: "..ret[2]
elseif ret[1] == "timeout" then elseif ret[1] == "timeout" then
@@ -309,22 +310,22 @@ function kernel.main()
if ret[2]=="syscall" then if ret[2]=="syscall" then
if kernel.syscalls[ret[3]] then if kernel.syscalls[ret[3]] then
if kernel.config.debugSyscalls then if kernel.config.debugSyscalls then
kernel.log("Task "..task.pid.." invoking syscall: "..ret[3], "DBUG") kernel.log("Task "..task.pid.." invoking syscall: "..ret[3], "DBUG", 5)
for i=4,#ret do for i=4,#ret do
kernel.log(" inval["..tostring(i-3).."] = "..tostring(ret[i]), "DBUG") kernel.log(" inval["..tostring(i-3).."] = "..tostring(ret[i]), "DBUG", 5)
end end
end end
local sysret = {xpcall(kernel.syscalls[ret[3]], debug.traceback, table.unpack(ret, 4))} local sysret = {xpcall(kernel.syscalls[ret[3]], debug.traceback, table.unpack(ret, 4))}
if kernel.config.debugSyscalls then if kernel.config.debugSyscalls then
if not sysret[1] then if not sysret[1] then
kernel.log("Task "..task.pid.." syscall "..ret[3].." failed: "..tostring(sysret[2])) kernel.log("Task "..task.pid.." syscall "..ret[3].." failed: "..tostring(sysret[2]), "ERROR", 2)
else else
kernel.log("Task "..task.pid.." syscall "..ret[3].." completed returning "..tostring(#sysret-1).." values", "DBUG") kernel.log("Task "..task.pid.." syscall "..ret[3].." completed returning "..tostring(#sysret-1).." values", "DBUG", 5)
for i=2,#sysret do for i=2,#sysret do
if type(sysret[i])=="table" then if type(sysret[i])=="table" then
kernel.log(" retval["..tostring(i-1).."] = "..table.serialize(sysret[i]), "DBUG") kernel.log(" retval["..tostring(i-1).."] = "..table.serialize(sysret[i]), "DBUG", 5)
else else
kernel.log(" retval["..tostring(i-1).."] = "..tostring(sysret[i]), "DBUG") kernel.log(" retval["..tostring(i-1).."] = "..tostring(sysret[i]), "DBUG", 5)
end end
end end
end end

View File

@@ -27,6 +27,8 @@ kernel.tasks["1"] = {
user="root", user="root",
uid=0, uid=0,
fd={}, fd={},
envars={},
args={},
exit="", exit="",
sleep=0, sleep=0,
ivs=0, ivs=0,