2019-10-29 02:01:57 +00:00
|
|
|
--[[
|
|
|
|
.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)
|
|
|
|
]]
|
|
|
|
|
2019-11-02 04:37:08 +00:00
|
|
|
local colors = _G.colors
|
|
|
|
local fs = _G.fs
|
|
|
|
local keys = _G.keys
|
|
|
|
local os = _G.os
|
|
|
|
local settings = _G.settings
|
|
|
|
local term = _G.term
|
|
|
|
local textutils = _G.textutils
|
2018-01-20 12:18:13 +00:00
|
|
|
|
2019-10-29 02:01:57 +00:00
|
|
|
local function loadBootOptions()
|
|
|
|
if not fs.exists('.startup.boot') then
|
|
|
|
local f = fs.open('.startup.boot', 'w')
|
|
|
|
f.write(textutils.serialize({
|
|
|
|
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()
|
|
|
|
|
2016-12-11 19:24:52 +00:00
|
|
|
local bootOption = 2
|
2018-01-20 12:18:13 +00:00
|
|
|
if settings then
|
2018-01-24 22:39:38 +00:00
|
|
|
settings.load('.settings')
|
2019-04-24 07:42:23 +00:00
|
|
|
bootOption = tonumber(settings.get('opus.boot_option')) or bootOption
|
2018-01-20 12:18:13 +00:00
|
|
|
end
|
2016-12-11 19:24:52 +00:00
|
|
|
|
|
|
|
local function startupMenu()
|
2019-04-24 07:42:23 +00:00
|
|
|
local x, y = term.getSize()
|
2019-10-29 02:01:57 +00:00
|
|
|
local align, selected = 0, bootOption
|
|
|
|
|
2019-04-24 07:42:23 +00:00
|
|
|
local function redraw()
|
|
|
|
local title = "Boot Options:"
|
2018-01-24 22:39:38 +00:00
|
|
|
term.clear()
|
2019-04-24 07:42:23 +00:00
|
|
|
term.setTextColor(colors.white)
|
2019-10-29 02:01:57 +00:00
|
|
|
term.setCursorPos((x/2)-(#title/2), (y/2)-(#bootOptions.menu/2)-1)
|
2019-04-24 07:42:23 +00:00
|
|
|
term.write(title)
|
2019-10-29 02:01:57 +00:00
|
|
|
for i, item in pairs(bootOptions.menu) do
|
|
|
|
local txt = i .. ". " .. item.prompt
|
|
|
|
term.setCursorPos((x/2)-(align/2), (y/2)-(#bootOptions.menu/2)+i)
|
2019-04-24 07:42:23 +00:00
|
|
|
term.write(txt)
|
2018-01-24 22:39:38 +00:00
|
|
|
end
|
2019-04-24 07:42:23 +00:00
|
|
|
end
|
|
|
|
|
2019-10-29 02:01:57 +00:00
|
|
|
for _, item in pairs(bootOptions.menu) do
|
|
|
|
if #item.prompt > align then
|
|
|
|
align = #item.prompt
|
2018-01-24 22:39:38 +00:00
|
|
|
end
|
|
|
|
end
|
2019-04-24 07:42:23 +00:00
|
|
|
|
|
|
|
redraw()
|
2019-10-29 02:01:57 +00:00
|
|
|
while true do
|
|
|
|
term.setCursorPos((x/2)-(align/2)-2, (y/2)-(#bootOptions.menu/2)+selected)
|
|
|
|
term.setTextColor(term.isColor() and colors.yellow or colors.lightGray)
|
|
|
|
|
2019-04-24 07:42:23 +00:00
|
|
|
term.write(">")
|
2019-10-29 02:01:57 +00:00
|
|
|
local event, key = os.pullEvent()
|
|
|
|
if event == "mouse_scroll" then
|
|
|
|
key = key == 1 and keys.down or keys.up
|
|
|
|
elseif event == 'key_up' then
|
|
|
|
key = nil -- only process key events
|
2019-04-24 07:42:23 +00:00
|
|
|
end
|
2019-10-29 02:01:57 +00:00
|
|
|
|
|
|
|
if key == keys.enter or key == keys.right then
|
|
|
|
return selected
|
2019-11-02 04:37:08 +00:00
|
|
|
elseif key == keys.down then
|
|
|
|
if selected == #bootOptions.menu then
|
|
|
|
selected = 0
|
2019-10-29 02:01:57 +00:00
|
|
|
end
|
|
|
|
selected = selected + 1
|
2019-11-02 04:37:08 +00:00
|
|
|
elseif key == keys.up then
|
|
|
|
if selected == 1 then
|
|
|
|
selected = #bootOptions.menu + 1
|
2019-10-29 02:01:57 +00:00
|
|
|
end
|
|
|
|
selected = selected - 1
|
|
|
|
elseif event == 'char' then
|
|
|
|
key = tonumber(key) or 0
|
2019-11-02 04:37:08 +00:00
|
|
|
if bootOptions.menu[key] then
|
2019-10-29 02:01:57 +00:00
|
|
|
return key
|
2019-04-24 07:42:23 +00:00
|
|
|
end
|
|
|
|
end
|
2019-10-29 02:01:57 +00:00
|
|
|
|
|
|
|
local cx, cy = term.getCursorPos()
|
|
|
|
term.setCursorPos(cx-1, cy)
|
|
|
|
term.write(" ")
|
|
|
|
end
|
2018-01-20 12:18:13 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
local function splash()
|
2018-01-24 22:39:38 +00:00
|
|
|
local w, h = term.current().getSize()
|
2018-01-20 12:18:13 +00:00
|
|
|
|
2018-01-24 22:39:38 +00:00
|
|
|
term.setTextColor(colors.white)
|
|
|
|
if not term.isColor() then
|
|
|
|
local str = 'Opus OS'
|
|
|
|
term.setCursorPos((w - #str) / 2, h / 2)
|
|
|
|
term.write(str)
|
|
|
|
else
|
|
|
|
term.setBackgroundColor(colors.black)
|
|
|
|
term.clear()
|
|
|
|
local opus = {
|
|
|
|
'fffff00',
|
|
|
|
'ffff07000',
|
2020-04-20 23:33:22 +00:00
|
|
|
'ff00770b00f4444',
|
2018-01-24 22:39:38 +00:00
|
|
|
'ff077777444444444',
|
|
|
|
'f07777744444444444',
|
|
|
|
'f0000777444444444',
|
|
|
|
'070000111744444',
|
|
|
|
'777770000',
|
|
|
|
'7777000000',
|
|
|
|
'70700000000',
|
|
|
|
'077000000000',
|
|
|
|
}
|
|
|
|
for k,line in ipairs(opus) do
|
|
|
|
term.setCursorPos((w - 18) / 2, k + (h - #opus) / 2)
|
|
|
|
term.blit(string.rep(' ', #line), string.rep('a', #line), line)
|
|
|
|
end
|
|
|
|
end
|
2018-01-20 12:18:13 +00:00
|
|
|
|
2018-01-24 22:39:38 +00:00
|
|
|
local str = 'Press any key for menu'
|
|
|
|
term.setCursorPos((w - #str) / 2, h)
|
|
|
|
term.write(str)
|
2016-12-11 19:24:52 +00:00
|
|
|
end
|
|
|
|
|
2019-10-29 02:01:57 +00:00
|
|
|
for _, v in pairs(bootOptions.preload) do
|
|
|
|
os.run(_ENV, v)
|
|
|
|
end
|
|
|
|
|
2019-11-02 04:37:08 +00:00
|
|
|
term.clear()
|
|
|
|
splash()
|
|
|
|
|
2019-10-29 02:01:57 +00:00
|
|
|
local timerId = os.startTimer(bootOptions.delay)
|
2016-12-11 19:24:52 +00:00
|
|
|
while true do
|
2018-01-24 22:39:38 +00:00
|
|
|
local e, id = os.pullEvent()
|
|
|
|
if e == 'timer' and id == timerId then
|
|
|
|
break
|
|
|
|
end
|
2019-10-29 02:01:57 +00:00
|
|
|
if e == 'char' or e == 'key' then
|
2018-01-24 22:39:38 +00:00
|
|
|
bootOption = startupMenu()
|
|
|
|
if settings then
|
|
|
|
settings.set('opus.boot_option', bootOption)
|
|
|
|
settings.save('.settings')
|
|
|
|
end
|
|
|
|
break
|
|
|
|
end
|
2016-12-11 19:24:52 +00:00
|
|
|
end
|
|
|
|
|
2018-01-20 12:18:13 +00:00
|
|
|
term.clear()
|
|
|
|
term.setCursorPos(1, 1)
|
2019-10-29 02:01:57 +00:00
|
|
|
if bootOptions.menu[bootOption].args then
|
|
|
|
os.run(_ENV, table.unpack(bootOptions.menu[bootOption].args))
|
2018-01-20 12:18:13 +00:00
|
|
|
else
|
2019-10-29 02:01:57 +00:00
|
|
|
print(bootOptions.menu[bootOption].prompt)
|
2018-01-20 12:18:13 +00:00
|
|
|
end
|
2018-01-24 22:39:38 +00:00
|
|
|
|