mirror of
https://github.com/Ale32bit/Capy64.git
synced 2025-01-18 18:46:43 +00:00
Add bios alert and colors
Signed-off-by: Alessandro Proto <alex@alexdevs.me>
This commit is contained in:
parent
74c9e25ad6
commit
993b7f43f3
1 changed files with 82 additions and 8 deletions
|
@ -1,4 +1,4 @@
|
||||||
-- This file is part of Capy64 - https://github.com/Capy64/Capy64
|
-- This file is part of Capy64 - https://github.com/Capy64/Capy64
|
||||||
-- Copyright 2023 Alessandro "AlexDevs" Proto
|
-- Copyright 2023 Alessandro "AlexDevs" Proto
|
||||||
--
|
--
|
||||||
-- Licensed under the Apache License, Version 2.0 (the "License").
|
-- Licensed under the Apache License, Version 2.0 (the "License").
|
||||||
|
@ -24,6 +24,9 @@ local event = require("event")
|
||||||
local bootSleep = 2
|
local bootSleep = 2
|
||||||
local bg = 0x0
|
local bg = 0x0
|
||||||
local fg = 0xffffff
|
local fg = 0xffffff
|
||||||
|
local setupbg = 0x0608a6
|
||||||
|
local setupfg = 0xffffff
|
||||||
|
local accent = 0xffea00
|
||||||
|
|
||||||
term.setForeground(fg)
|
term.setForeground(fg)
|
||||||
term.setBackground(bg)
|
term.setBackground(bg)
|
||||||
|
@ -97,11 +100,60 @@ local function promptKey()
|
||||||
event.pull("key_down")
|
event.pull("key_down")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function alert(...)
|
||||||
|
local args = {...}
|
||||||
|
table.insert(args, "[ OK ]")
|
||||||
|
local lines = {}
|
||||||
|
local width = 0
|
||||||
|
local padding = 1
|
||||||
|
for k, v in ipairs(args) do
|
||||||
|
lines[k] = tostring(v)
|
||||||
|
width = math.max(width, #tostring(v))
|
||||||
|
end
|
||||||
|
|
||||||
|
lines[#lines] = nil
|
||||||
|
|
||||||
|
local okPad = string.rep(" ", (width - #args[#args]) // 2)
|
||||||
|
local okLine = string.format("%s%s", okPad, args[#args])
|
||||||
|
|
||||||
|
local w, h = term.getSize()
|
||||||
|
local cx, cy = w//2, h//2
|
||||||
|
local dx, dy = cx - (width + padding * 2) // 2, cy - #lines//2 - 1
|
||||||
|
|
||||||
|
local pad = string.rep(" ", padding)
|
||||||
|
local emptyLine = string.format("\u{258C}%s%s%s\u{2590}", pad, string.rep(" ", width), pad)
|
||||||
|
|
||||||
|
term.setPos(dx, dy)
|
||||||
|
print("\u{259B}" .. string.rep("\u{2580}", width + padding * 2) .. "\u{259C}")
|
||||||
|
for k, v in ipairs(lines) do
|
||||||
|
term.setPos(dx, dy + k)
|
||||||
|
local space = string.rep(" ", width - #v)
|
||||||
|
print(string.format("\u{258C}%s%s%s%s\u{2590}", pad, v, space, pad))
|
||||||
|
end
|
||||||
|
term.setPos(dx, dy + #lines + 1)
|
||||||
|
print(emptyLine)
|
||||||
|
term.setPos(dx, dy + #lines + 2)
|
||||||
|
local space = string.rep(" ", width - #okLine)
|
||||||
|
term.write(string.format("\u{258C}%s", pad))
|
||||||
|
term.setForeground(accent)
|
||||||
|
term.write(okLine)
|
||||||
|
term.setForeground(setupfg)
|
||||||
|
print(string.format("%s%s\u{2590}", space, pad))
|
||||||
|
term.setPos(dx, dy + #lines + 3)
|
||||||
|
print("\u{2599}" .. string.rep("\u{2584}", width + padding * 2) .. "\u{259F}")
|
||||||
|
|
||||||
|
local _, key, keyname
|
||||||
|
repeat
|
||||||
|
_, key, keyname = event.pull("key_down")
|
||||||
|
until keyname == "enter" or keyname == "escape"
|
||||||
|
end
|
||||||
|
|
||||||
local function installDefaultOS()
|
local function installDefaultOS()
|
||||||
if fs.exists("/sys") then
|
if fs.exists("/sys") then
|
||||||
fs.delete("/sys", true)
|
fs.delete("/sys", true)
|
||||||
end
|
end
|
||||||
installOS()
|
installOS()
|
||||||
|
alert("Default OS installed!")
|
||||||
end
|
end
|
||||||
|
|
||||||
term.setBlink(false)
|
term.setBlink(false)
|
||||||
|
@ -116,6 +168,7 @@ local function setupScreen()
|
||||||
"Install default OS",
|
"Install default OS",
|
||||||
installDefaultOS,
|
installDefaultOS,
|
||||||
},
|
},
|
||||||
|
{},
|
||||||
{
|
{
|
||||||
"Exit setup",
|
"Exit setup",
|
||||||
exit,
|
exit,
|
||||||
|
@ -127,21 +180,25 @@ local function setupScreen()
|
||||||
}
|
}
|
||||||
|
|
||||||
local selection = 1
|
local selection = 1
|
||||||
local function redraw()
|
local function redraw(noDrawSel)
|
||||||
term.setForeground(fg)
|
local w, h = term.getSize()
|
||||||
term.setBackground(bg)
|
term.setForeground(setupfg)
|
||||||
|
term.setBackground(setupbg)
|
||||||
term.clear()
|
term.clear()
|
||||||
term.setPos(1,2)
|
term.setPos(1,2)
|
||||||
writeCenter("Capy64 Setup")
|
writeCenter("Capy64 Setup")
|
||||||
|
|
||||||
term.setPos(1,3)
|
term.setPos(1,3)
|
||||||
|
|
||||||
|
term.setForeground(accent)
|
||||||
|
|
||||||
for k, v in ipairs(options) do
|
for k, v in ipairs(options) do
|
||||||
local _, y = term.getPos()
|
local _, y = term.getPos()
|
||||||
term.setPos(1, y + 1)
|
term.setPos(1, y + 1)
|
||||||
term.clearLine()
|
term.clearLine()
|
||||||
|
|
||||||
if selection == k then
|
if #v > 0 then
|
||||||
|
if selection == k and not noDrawSel then
|
||||||
writeCenter("[ " .. v[1] .. " ]")
|
writeCenter("[ " .. v[1] .. " ]")
|
||||||
else
|
else
|
||||||
writeCenter(v[1])
|
writeCenter(v[1])
|
||||||
|
@ -149,14 +206,31 @@ local function setupScreen()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
term.setForeground(setupfg)
|
||||||
|
|
||||||
|
term.setPos(1, h - 2)
|
||||||
|
term.write("\u{2190}\u{2191}\u{2192}\u{2193}: Move")
|
||||||
|
term.setPos(1, h - 1)
|
||||||
|
term.write("Escape: Exit")
|
||||||
|
term.setPos(1, h)
|
||||||
|
term.write("Enter: Select")
|
||||||
|
end
|
||||||
|
|
||||||
while true do
|
while true do
|
||||||
redraw()
|
redraw()
|
||||||
local ev = { coroutine.yield("key_down") }
|
local ev = { coroutine.yield("key_down") }
|
||||||
if ev[3] == "up" then
|
if ev[3] == "up" then
|
||||||
selection = selection - 1
|
selection = selection - 1
|
||||||
|
if options[selection] and #options[selection] == 0 then
|
||||||
|
selection = selection - 1
|
||||||
|
end
|
||||||
elseif ev[3] == "down" then
|
elseif ev[3] == "down" then
|
||||||
selection = selection + 1
|
selection = selection + 1
|
||||||
|
if options[selection] and #options[selection] == 0 then
|
||||||
|
selection = selection + 1
|
||||||
|
end
|
||||||
elseif ev[3] == "enter" then
|
elseif ev[3] == "enter" then
|
||||||
|
redraw(true)
|
||||||
options[selection][2]()
|
options[selection][2]()
|
||||||
elseif ev[3] == "escape" then
|
elseif ev[3] == "escape" then
|
||||||
exit()
|
exit()
|
||||||
|
|
Loading…
Reference in a new issue