mirror of
https://github.com/kepler155c/opus
synced 2024-10-31 22:26:16 +00:00
improve startup, dont rely on debug (cbor)
This commit is contained in:
parent
6e6d4b81cd
commit
774d3ed415
146
startup.lua
146
startup.lua
@ -1,14 +1,48 @@
|
|||||||
|
--[[
|
||||||
|
.startup.boot
|
||||||
|
delay
|
||||||
|
description: delays amount before starting the default selection
|
||||||
|
default: 1.5
|
||||||
|
|
||||||
|
preload
|
||||||
|
description : runs before menu is displayed, can be used for password
|
||||||
|
locking, drive encryption, etc.
|
||||||
|
example : { [1] = '/path/somefile.lua', [2] = 'path2/another.lua' }
|
||||||
|
|
||||||
|
menu
|
||||||
|
description: array of menu entries (see .startup.boot for examples)
|
||||||
|
]]
|
||||||
|
|
||||||
local colors = _G.colors
|
local colors = _G.colors
|
||||||
local os = _G.os
|
local os = _G.os
|
||||||
local settings = _G.settings
|
local settings = _G.settings
|
||||||
local term = _G.term
|
local term = _G.term
|
||||||
|
|
||||||
local bootOptions = {
|
local function loadBootOptions()
|
||||||
{ prompt = os.version() },
|
if not fs.exists('.startup.boot') then
|
||||||
{ prompt = 'Opus' , args = { '/sys/boot/opus.boot' } },
|
local f = fs.open('.startup.boot', 'w')
|
||||||
{ prompt = 'Opus Shell' , args = { '/sys/boot/opus.boot', 'sys/apps/shell.lua' } },
|
f.write(textutils.serialize({
|
||||||
{ prompt = 'Opus Kiosk' , args = { '/sys/boot/kiosk.boot' } },
|
delay = 1.5,
|
||||||
}
|
preload = { },
|
||||||
|
menu = {
|
||||||
|
{ prompt = os.version() },
|
||||||
|
{ prompt = 'Opus' , args = { '/sys/boot/opus.boot' } },
|
||||||
|
{ prompt = 'Opus Shell' , args = { '/sys/boot/opus.boot', 'sys/apps/shell.lua' } },
|
||||||
|
{ prompt = 'Opus Kiosk' , args = { '/sys/boot/kiosk.boot' } },
|
||||||
|
},
|
||||||
|
}))
|
||||||
|
f.close()
|
||||||
|
end
|
||||||
|
|
||||||
|
local f = fs.open('.startup.boot', 'r')
|
||||||
|
local options = textutils.unserialize(f.readAll())
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
return options
|
||||||
|
end
|
||||||
|
|
||||||
|
local bootOptions = loadBootOptions()
|
||||||
|
|
||||||
local bootOption = 2
|
local bootOption = 2
|
||||||
if settings then
|
if settings then
|
||||||
settings.load('.settings')
|
settings.load('.settings')
|
||||||
@ -17,69 +51,63 @@ end
|
|||||||
|
|
||||||
local function startupMenu()
|
local function startupMenu()
|
||||||
local x, y = term.getSize()
|
local x, y = term.getSize()
|
||||||
local align, selected = 0, 1
|
local align, selected = 0, bootOption
|
||||||
|
|
||||||
local function redraw()
|
local function redraw()
|
||||||
local title = "Boot Options:"
|
local title = "Boot Options:"
|
||||||
term.clear()
|
term.clear()
|
||||||
term.setTextColor(colors.white)
|
term.setTextColor(colors.white)
|
||||||
term.setCursorPos((x/2)-(#title/2), (y/2)-(#bootOptions/2)-1)
|
term.setCursorPos((x/2)-(#title/2), (y/2)-(#bootOptions.menu/2)-1)
|
||||||
term.write(title)
|
term.write(title)
|
||||||
for i = 1, #bootOptions do
|
for i, item in pairs(bootOptions.menu) do
|
||||||
local txt = i..". "..bootOptions[i].prompt
|
local txt = i .. ". " .. item.prompt
|
||||||
term.setCursorPos((x/2)-(align/2), (y/2)-(#bootOptions/2)+i)
|
term.setCursorPos((x/2)-(align/2), (y/2)-(#bootOptions.menu/2)+i)
|
||||||
term.write(txt)
|
term.write(txt)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
for i = 1, #bootOptions do
|
for _, item in pairs(bootOptions.menu) do
|
||||||
if (bootOptions[i].prompt):len() > align then
|
if #item.prompt > align then
|
||||||
align = (bootOptions[i].prompt):len()
|
align = #item.prompt
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
redraw()
|
redraw()
|
||||||
repeat
|
while true do
|
||||||
term.setCursorPos((x/2)-(align/2)-2, (y/2)-(#bootOptions/2)+selected)
|
term.setCursorPos((x/2)-(align/2)-2, (y/2)-(#bootOptions.menu/2)+selected)
|
||||||
if term.isColor() then
|
term.setTextColor(term.isColor() and colors.yellow or colors.lightGray)
|
||||||
term.setTextColor(colors.yellow)
|
|
||||||
else
|
|
||||||
term.setTextColor(colors.lightGray)
|
|
||||||
end
|
|
||||||
term.write(">")
|
term.write(">")
|
||||||
local k = ({os.pullEvent()})
|
local event, key = os.pullEvent()
|
||||||
if k[1] == "mouse_scroll" then
|
if event == "mouse_scroll" then
|
||||||
if k[2] == 1 then
|
key = key == 1 and keys.down or keys.up
|
||||||
k = keys.down
|
elseif event == 'key_up' then
|
||||||
else
|
key = nil -- only process key events
|
||||||
k = keys.up
|
|
||||||
end
|
|
||||||
elseif k[1] == "key" then
|
|
||||||
k = k[2]
|
|
||||||
else
|
|
||||||
k = nil
|
|
||||||
end
|
end
|
||||||
if k then
|
|
||||||
if k == keys.enter or k == keys.right then
|
if key == keys.enter or key == keys.right then
|
||||||
return selected
|
return selected
|
||||||
elseif k == keys.down then
|
elseif key == keys.down then
|
||||||
if selected == #bootOptions then
|
if selected == #bootOptions.menu then
|
||||||
selected = 0
|
selected = 0
|
||||||
end
|
end
|
||||||
selected = selected+1
|
selected = selected + 1
|
||||||
elseif k == keys.up then
|
elseif key == keys.up then
|
||||||
if selected == 1 then
|
if selected == 1 then
|
||||||
selected = #bootOptions+1
|
selected = #bootOptions.menu + 1
|
||||||
end
|
end
|
||||||
selected = selected-1
|
selected = selected - 1
|
||||||
elseif k >= keys.one and k <= #bootOptions+1 and k < keys.zero then
|
elseif event == 'char' then
|
||||||
selected = k-1
|
key = tonumber(key) or 0
|
||||||
return selected
|
if bootOptions.menu[key] then
|
||||||
|
return key
|
||||||
end
|
end
|
||||||
local cx, cy = term.getCursorPos()
|
|
||||||
term.setCursorPos(cx-1, cy)
|
|
||||||
term.write(" ")
|
|
||||||
end
|
end
|
||||||
until true == false
|
|
||||||
|
local cx, cy = term.getCursorPos()
|
||||||
|
term.setCursorPos(cx-1, cy)
|
||||||
|
term.write(" ")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function splash()
|
local function splash()
|
||||||
@ -120,13 +148,17 @@ end
|
|||||||
term.clear()
|
term.clear()
|
||||||
splash()
|
splash()
|
||||||
|
|
||||||
local timerId = os.startTimer(1.5)
|
for _, v in pairs(bootOptions.preload) do
|
||||||
|
os.run(_ENV, v)
|
||||||
|
end
|
||||||
|
|
||||||
|
local timerId = os.startTimer(bootOptions.delay)
|
||||||
while true do
|
while true do
|
||||||
local e, id = os.pullEvent()
|
local e, id = os.pullEvent()
|
||||||
if e == 'timer' and id == timerId then
|
if e == 'timer' and id == timerId then
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
if e == 'char' then
|
if e == 'char' or e == 'key' then
|
||||||
bootOption = startupMenu()
|
bootOption = startupMenu()
|
||||||
if settings then
|
if settings then
|
||||||
settings.set('opus.boot_option', bootOption)
|
settings.set('opus.boot_option', bootOption)
|
||||||
@ -138,9 +170,9 @@ end
|
|||||||
|
|
||||||
term.clear()
|
term.clear()
|
||||||
term.setCursorPos(1, 1)
|
term.setCursorPos(1, 1)
|
||||||
if bootOptions[bootOption].args then
|
if bootOptions.menu[bootOption].args then
|
||||||
os.run(_ENV, table.unpack(bootOptions[bootOption].args))
|
os.run(_ENV, table.unpack(bootOptions.menu[bootOption].args))
|
||||||
else
|
else
|
||||||
print(bootOptions[bootOption].prompt)
|
print(bootOptions.menu[bootOption].prompt)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ end
|
|||||||
|
|
||||||
local setmetatable = setmetatable;
|
local setmetatable = setmetatable;
|
||||||
local getmetatable = getmetatable;
|
local getmetatable = getmetatable;
|
||||||
local dbg_getmetatable = debug.getmetatable;
|
local dbg_getmetatable = debug and debug.getmetatable;
|
||||||
local assert = assert;
|
local assert = assert;
|
||||||
local error = error;
|
local error = error;
|
||||||
local type = type;
|
local type = type;
|
||||||
|
@ -195,7 +195,7 @@ end
|
|||||||
function Entry:paste(ie)
|
function Entry:paste(ie)
|
||||||
if #ie.text > 0 then
|
if #ie.text > 0 then
|
||||||
if self.mark.active then
|
if self.mark.active then
|
||||||
self:delete()
|
self:delete()
|
||||||
end
|
end
|
||||||
self:insertText(self.pos, ie.text)
|
self:insertText(self.pos, ie.text)
|
||||||
end
|
end
|
||||||
@ -347,16 +347,16 @@ local mappings = {
|
|||||||
-- [ 'control-y' ] = Entry.paste, -- well this won't work...
|
-- [ 'control-y' ] = Entry.paste, -- well this won't work...
|
||||||
|
|
||||||
[ 'mouse_doubleclick' ] = Entry.markWord,
|
[ 'mouse_doubleclick' ] = Entry.markWord,
|
||||||
[ 'shift-left' ] = Entry.markLeft,
|
[ 'shift-left' ] = Entry.markLeft,
|
||||||
[ 'shift-right' ] = Entry.markRight,
|
[ 'shift-right' ] = Entry.markRight,
|
||||||
[ 'mouse_down' ] = Entry.markAnchor,
|
[ 'mouse_down' ] = Entry.markAnchor,
|
||||||
[ 'mouse_drag' ] = Entry.markTo,
|
[ 'mouse_drag' ] = Entry.markTo,
|
||||||
[ 'shift-mouse_click' ] = Entry.markTo,
|
[ 'shift-mouse_click' ] = Entry.markTo,
|
||||||
[ 'control-a' ] = Entry.markAll,
|
[ 'control-a' ] = Entry.markAll,
|
||||||
[ 'control-shift-right' ] = Entry.markNextWord,
|
[ 'control-shift-right' ] = Entry.markNextWord,
|
||||||
[ 'control-shift-left' ] = Entry.markPrevWord,
|
[ 'control-shift-left' ] = Entry.markPrevWord,
|
||||||
[ 'shift-end' ] = Entry.markEnd,
|
[ 'shift-end' ] = Entry.markEnd,
|
||||||
[ 'shift-home' ] = Entry.markHome,
|
[ 'shift-home' ] = Entry.markHome,
|
||||||
}
|
}
|
||||||
|
|
||||||
function Entry:process(ie)
|
function Entry:process(ie)
|
||||||
@ -369,7 +369,7 @@ function Entry:process(ie)
|
|||||||
local line = self.value
|
local line = self.value
|
||||||
|
|
||||||
local wasMarking = self.mark.continue
|
local wasMarking = self.mark.continue
|
||||||
self.mark.continue = false
|
self.mark.continue = false
|
||||||
|
|
||||||
action(self, ie)
|
action(self, ie)
|
||||||
|
|
||||||
@ -378,7 +378,7 @@ function Entry:process(ie)
|
|||||||
self:updateScroll()
|
self:updateScroll()
|
||||||
|
|
||||||
if not self.mark.continue and wasMarking then
|
if not self.mark.continue and wasMarking then
|
||||||
self:unmark()
|
self:unmark()
|
||||||
end
|
end
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
Loading…
Reference in New Issue
Block a user