hey I'm trying to make a menu based os that you navigate with the arrow keys and enter button
it should look like this
command
programs
[shutdown]
reinstall
it's bringing up this error
too long without yielding:
stack traceback:
machine:809: in function 'xpcall'
/lib/process.lua:63: in function </lib/process.lua:59>
here's the code I can't for the the life of me figure out what's wrong
local kb = require("keyboard")
local event = require("event")
local component = require("component")
local gpu = component.gpu
local term = require("term")
local w,h = gpu.getResolution()
function printCentered (y,s)
local x = math.floor((w - string.len(s)) / 2)
term.setCursor(x,y)
term.clearLine()
term.write(s)
end
--menu up
local function up()
keyboard.keys.up = up()
end
--menu down
local function down()
keyboard.keys.down = down()
end
--menu enter
local function enter()
keyboard.key.enter = enter()
end
--draw menu
local nOption = 1
local function drawMenu()
term.clear()
term.setCursor(1,1)
term.write("perdOS")
term.setCursor(w-11,1)
if nOption == 1 then
term.write("Command")
elseif nOption == 2 then
term.write("programs")
elseif nOption == 3 then
term.write("shutdown")
elseif nOption == 4 then
term.write("uninstall")
else
end
end
--gui
term.clear()
local function drawFE()
printCentered(math.floor(h/2) - 3, "")
printCentered(math.floor(h/2) - 2, "start menu")
printCentered(math.floor(h/2) - 1, "")
printCentered(math.floor(h/2) + 0, ((nOption == 1) and "[command ]") or "command")
printCentered(math.floor(h/2) + 1, ((nOption == 2) and "[programs ]") or "programs")
printCentered(math.floor(h/2) + 2, ((nOption == 3) and "[shutdown ]") or "shutdown")
printCentered(math.floor(h/2) + 3, ((nOption == 4) and "[uninstall]") or "uninstall")
end
--display
drawMenu()
drawFE()
while true do
local e,p = kb.isKeyDown("")
if e == "key" then
local key = p
if key == down() then
if nOption > 1 then
nOption = nOption - 1
drawMenu()
drawFE()
end
elseif key == up() then
if nOption < 4 then
nOption = nOption + 1
drawMenu()
drawFE()
end
elseif key == enter() then
break
end
end
end
--conditions
if nOption == 1 then
shell.run("os/.command")
elseif nOption == 2 then
shell.run("os/.programs")
elseif nOption == 3 then
os.shutdown()
else
shell.run("os/.uninstall")
end
You can post now and register later.
If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.
hey I'm trying to make a menu based os that you navigate with the arrow keys and enter button
it should look like this
command
programs
[shutdown]
reinstall
it's bringing up this error
too long without yielding:
stack traceback:
machine:809: in function 'xpcall'
/lib/process.lua:63: in function </lib/process.lua:59>
here's the code I can't for the the life of me figure out what's wrong
local kb = require("keyboard")
local event = require("event")
local component = require("component")
local gpu = component.gpu
local term = require("term")
local w,h = gpu.getResolution()
function printCentered (y,s)
local x = math.floor((w - string.len(s)) / 2)
term.setCursor(x,y)
term.clearLine()
term.write(s)
end
--menu up
local function up()
keyboard.keys.up = up()
end
--menu down
local function down()
keyboard.keys.down = down()
end
--menu enter
local function enter()
keyboard.key.enter = enter()
end
--draw menu
local nOption = 1
local function drawMenu()
term.clear()
term.setCursor(1,1)
term.write("perdOS")
term.setCursor(w-11,1)
if nOption == 1 then
term.write("Command")
elseif nOption == 2 then
term.write("programs")
elseif nOption == 3 then
term.write("shutdown")
elseif nOption == 4 then
term.write("uninstall")
else
end
end
--gui
term.clear()
local function drawFE()
printCentered(math.floor(h/2) - 3, "")
printCentered(math.floor(h/2) - 2, "start menu")
printCentered(math.floor(h/2) - 1, "")
printCentered(math.floor(h/2) + 0, ((nOption == 1) and "[command ]") or "command")
printCentered(math.floor(h/2) + 1, ((nOption == 2) and "[programs ]") or "programs")
printCentered(math.floor(h/2) + 2, ((nOption == 3) and "[shutdown ]") or "shutdown")
printCentered(math.floor(h/2) + 3, ((nOption == 4) and "[uninstall]") or "uninstall")
end
--display
drawMenu()
drawFE()
while true do
local e,p = kb.isKeyDown("")
if e == "key" then
local key = p
if key == down() then
if nOption > 1 then
nOption = nOption - 1
drawMenu()
drawFE()
end
elseif key == up() then
if nOption < 4 then
nOption = nOption + 1
drawMenu()
drawFE()
end
elseif key == enter() then
break
end
end
end
--conditions
if nOption == 1 then
shell.run("os/.command")
elseif nOption == 2 then
shell.run("os/.programs")
elseif nOption == 3 then
os.shutdown()
else
shell.run("os/.uninstall")
end
Link to post
Share on other sites