init commit

This commit is contained in:
chloe@vern.cc 2024-05-09 18:42:44 +01:00
commit 8581560929
7 changed files with 171 additions and 0 deletions

84
Eboot/boot.lua Normal file
View File

@ -0,0 +1,84 @@
--Eboot
self = {}
self._VERSION = "0.0.2 alpha"
entries = {}
for i,v in pairs(fs.list("/Eboot/entries")) do
loadstring("tab="..fs.open("/Eboot/entries/"..v, "r").readAll())()
entries[i] = tab
end
welcome = "Eboot bootloader "..self._VERSION
message = "Use the "..utf8.char(24).." and "..utf8.char(25).." keys to change selection and ENTER to boot the chosen file. press E for recovery."
sel = 1
size1 = 0
for _ in pairs(entries) do size1 = size1 + 1 end
function writeEntries(entries,selected)
term.clear()
term.setCursorBlink(false)
term.setCursorPos(1,1)
xt,yt = term.getSize()
for i=xt/2-string.len(welcome)/2,1,-1 do write(" ") end
print(welcome)
for i,v in pairs(entries) do
x,y = term.getCursorPos()
y=y+1
term.setCursorPos(1,y)
if selected==i then
term.setBackgroundColor(colors.orange)
write(v["name"])
for i=xt-string.len(v["name"]),1,-1 do write(" ") end
term.setBackgroundColor(colors.black)
else
write(v["name"])
end
end
term.setCursorPos(1,yt-1)
write(message)
end
writeEntries(entries,sel)
function main()
local event, key = os.pullEvent("key")
if keys.getName(key) == "down" then
sel = sel+1
if sel > size1 then
sel = 1
end
writeEntries(entries,sel)
end
if keys.getName(key) == "up" then
sel = sel-1
if sel == 0 then
sel = 2
end
writeEntries(entries,sel)
end
if keys.getName(key) == "enter" then
term.clear()
term.setCursorPos(1,1)
term.setCursorBlink(true)
shell.run(entries[sel]["entrypoint"])
os.shutdown()
end
if keys.getName(key) == "e" then
term.clear()
term.setCursorPos(1,1)
term.setCursorBlink(true)
shell.run("/Eboot/recovery/rec.lua")
end
end
while true do
local ok, err = pcall(main)
if ok then
else
if err == "Terminated" then
end
end
end

View File

@ -0,0 +1,4 @@
{
name = "CraftOS",
entrypoint = "/rom/programs/shell.lua"
}

4
Eboot/entries/hello.lua Normal file
View File

@ -0,0 +1,4 @@
{
name = "Hello",
entrypoint = "/rom/programs/fun/hello.lua"
}

View File

@ -0,0 +1,4 @@
{
name = "Remove Eboot",
payload = "rem.lua"
}

View File

@ -0,0 +1,2 @@
fs.delete("/Eboot")
fs.delete("startup.lua")

72
Eboot/recovery/rec.lua Normal file
View File

@ -0,0 +1,72 @@
--Eboot recovery
entries = {}
for i,v in pairs(fs.list("/Eboot/recovery/entries")) do
loadstring("tab="..fs.open("/Eboot/recovery/entries/"..v, "r").readAll())()
entries[i] = tab
end
welcome = "Eboot Recovery "
sel = 1
size1 = 0
for _ in pairs(entries) do size1 = size1 + 1 end
function writeEntries(entries,selected)
term.clear()
term.setCursorBlink(false)
term.setCursorPos(1,1)
xt,yt = term.getSize()
for i=xt/2-string.len(welcome)/2,1,-1 do write(" ") end
print(welcome)
for i,v in pairs(entries) do
x,y = term.getCursorPos()
y=y+1
term.setCursorPos(1,y)
if selected==i then
term.setBackgroundColor(colors.orange)
write(v["name"])
for i=xt-string.len(v["name"]),1,-1 do write(" ") end
term.setBackgroundColor(colors.black)
else
write(v["name"])
end
end
end
writeEntries(entries,sel)
function main()
local event, key = os.pullEvent("key")
if keys.getName(key) == "down" then
sel = sel+1
if sel > size1 then
sel = 1
end
writeEntries(entries,sel)
end
if keys.getName(key) == "up" then
sel = sel-1
if sel == 0 then
sel = 2
end
writeEntries(entries,sel)
end
if keys.getName(key) == "enter" then
term.clear()
term.setCursorPos(1,1)
term.setCursorBlink(true)
shell.run("/Eboot/recovery/payloads/"..entries[sel]["payload"])
end
end
while true do
local ok, err = pcall(main)
if ok then
else
if err == "Terminated" then
shell.run("/Eboot/boot.lua")
end
end
end

1
startup.lua Normal file
View File

@ -0,0 +1 @@
shell.run("/Eboot/boot.lua")