Files
HyperionOS/Src/Hyperion-bash/bin/bashex
2026-02-12 11:43:41 -05:00

92 lines
3.1 KiB
Plaintext

--:Minify:--
syscall.TTY_clear()
syscall.TTY_setTextColor(1)
syscall.TTY_setCursorPos(1, 1)
syscall.TTY_print("HyperionOS Bash Shell")
local str=""
local stopInput=false
local inputIO=syscall.IO_getBoundQueue()
local pid=syscall.getpid()
local proc=0
local fs=require("sys.fs")
local timeout=false
syscall.setEnviron("SHELL","simpleshell")
printInline("> ")
while true do
local event = {syscall.IO_pullEvent()}
if event[1] then
if not stopInput then
if event[1]=="keyTyped" then
if event[3]=="\b" then
if #str>0 then
str=str:sub(1,#str-1)
printInline("\b")
end
elseif event[3]=="\n" then
print("")
stopInput=true
if str == "" then
printInline("> ")
stopInput=false
else
local path=nil
local split=string.split(str, " ")
if fs.exists("/bin/"..split[1]) then
path="/bin/"..split[1]
elseif fs.exists("/bin/"..split[1]..".lua") then
path="/bin/"..split[1]..".lua"
end
if not path then
print("Program not found")
printInline("> ")
stopInput=false
else
local text = fs.readAllText(path)
local program, err = load(text, path)
if not program then
print(err)
printInline("> ")
end
syscall.IO_bind("bash:"..tostring(pid))
proc = syscall.spawn(program, path, nil, {table.unpack(split, 2)})
syscall.IO_bind(inputIO)
end
str=""
end
elseif event[1]=="keyTyped" and event[3]=="^d" then
syscall.exit(0)
else
str=str..event[3]
printInline(event[3])
end
end
end
timeout=false
else
timeout=true
end
if stopInput then
local exited, code = syscall.collect(proc)
if exited then
if code then
print("\nTask exited with code:\n"..tostring(code))
end
printInline("> ")
stopInput=false
else
if event[1] then
if event[1]=="keyTyped" and event[3]=="^c" then
syscall.kill(proc)
print("Terminated")
printInline("> ")
stopInput=false
else
syscall.IO_pushEvent("bash:"..tostring(pid), table.unpack(event))
end
end
end
end
if timeout then
sleep(.05)
end
end