mirror of
https://github.com/kepler155c/opus
synced 2025-01-18 19:32:52 +00:00
Merge pull request #9 from hugeblank/startup-revamp
improve startup option screen
This commit is contained in:
commit
a5fc89beee
@ -12,25 +12,74 @@ local bootOptions = {
|
|||||||
local bootOption = 2
|
local bootOption = 2
|
||||||
if settings then
|
if settings then
|
||||||
settings.load('.settings')
|
settings.load('.settings')
|
||||||
bootOption = tonumber(settings.get('opus.boot_option') or 2) or 2
|
bootOption = tonumber(settings.get('opus.boot_option')) or bootOption
|
||||||
end
|
end
|
||||||
|
|
||||||
local function startupMenu()
|
local function startupMenu()
|
||||||
while true do
|
local x, y = term.getSize()
|
||||||
|
local align, selected = 0, 1
|
||||||
|
local function redraw()
|
||||||
|
local title = "Boot Options:"
|
||||||
term.clear()
|
term.clear()
|
||||||
term.setCursorPos(1, 1)
|
term.setTextColor(colors.white)
|
||||||
print('Select startup mode')
|
term.setCursorPos((x/2)-(#title/2), (y/2)-(#bootOptions/2)-1)
|
||||||
print()
|
term.write(title)
|
||||||
for k,option in pairs(bootOptions) do
|
for i = 1, #bootOptions do
|
||||||
print(k .. ' : ' .. option.prompt)
|
local txt = i..". "..bootOptions[i].prompt
|
||||||
end
|
term.setCursorPos((x/2)-(align/2), (y/2)-(#bootOptions/2)+i)
|
||||||
print('')
|
term.write(txt)
|
||||||
term.write('> ')
|
|
||||||
local ch = tonumber(_G.read())
|
|
||||||
if ch and bootOptions[ch] then
|
|
||||||
return ch
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
for i = 1, #bootOptions do
|
||||||
|
if (bootOptions[i].prompt):len() > align then
|
||||||
|
align = (bootOptions[i].prompt):len()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
redraw()
|
||||||
|
repeat
|
||||||
|
term.setCursorPos((x/2)-(align/2)-2, (y/2)-(#bootOptions/2)+selected)
|
||||||
|
if term.isColor() then
|
||||||
|
term.setTextColor(colors.yellow)
|
||||||
|
else
|
||||||
|
term.setTextColor(colors.lightGray)
|
||||||
|
end
|
||||||
|
term.write(">")
|
||||||
|
local k = ({os.pullEvent()})
|
||||||
|
if k[1] == "mouse_scroll" then
|
||||||
|
if k[2] == 1 then
|
||||||
|
k = keys.down
|
||||||
|
else
|
||||||
|
k = keys.up
|
||||||
|
end
|
||||||
|
elseif k[1] == "key" then
|
||||||
|
k = k[2]
|
||||||
|
else
|
||||||
|
k = nil
|
||||||
|
end
|
||||||
|
if k then
|
||||||
|
if k == keys.enter or k == keys.right then
|
||||||
|
return selected
|
||||||
|
elseif k == keys.down then
|
||||||
|
if selected == #bootOptions then
|
||||||
|
selected = 0
|
||||||
|
end
|
||||||
|
selected = selected+1
|
||||||
|
elseif k == keys.up then
|
||||||
|
if selected == 1 then
|
||||||
|
selected = #bootOptions+1
|
||||||
|
end
|
||||||
|
selected = selected-1
|
||||||
|
elseif k >= keys.one and k <= #bootOptions+1 and k < keys.zero then
|
||||||
|
selected = k-1
|
||||||
|
return selected
|
||||||
|
end
|
||||||
|
local cx, cy = term.getCursorPos()
|
||||||
|
term.setCursorPos(cx-1, cy)
|
||||||
|
term.write(" ")
|
||||||
|
end
|
||||||
|
until true == false
|
||||||
end
|
end
|
||||||
|
|
||||||
local function splash()
|
local function splash()
|
Loading…
Reference in New Issue
Block a user