here is the code
:
local w,h = term.getSize()
local select = 1
--this is specifying printing positions
local function printCentered(str, ypos)
term.setCursorPos(w/2 - #str/2, ypos)
term.write(str)
end
local function printTopCentered(str, ypos)
term.setCursorPos(w/2 - #str/2, ypos)
term.write(str)
end
local function printBottomCentered(str)
term.setCursorPos(h - #str, w/2 - #str/2)
term.write(str)
end
local function printRight(str, ypos)
term.setCursorPos(w - #str, ypos)
term.write(str)
end
local function printRightcentered(str)
term.setCursorPos(w - #str)
term.setCursorPos(h/2 - #str/2)
term.write(str)
end
local function printRightTop(str, ypos)
term.setCursorPos(w - #str, ypos)
term.write(str)
end
local function printRightBottom(str)
term.setCursorPos(h - #str)
term.setCursorPos(w - #str)
term.write(str)
end
local function printLeft(str, ypos)
term.setCursorPos(w/4 - #str/4, ypos)
term.write(str)
end
local function printLeftTop(str, ypos)
term.setCursorPos(w/4 - #str/4, ypos)
term.write(str)
end
local function printLeftBottom(str)
term.setCursorPos(h - #str)
term.setCursorPos(w/4 - #str/4)
term.write(str)
end
--setup menu options
function drawSetupMenu()
printCentered("register new", 8)
printCentered("non-locked", 12)
printCentered("Quit", h-2)
local ypos = 9
if select == 2 then ypos = 13
elseif select == 3 then ypos = h-1 end
printCentered("---------", ypos)
end
function drawSetupHeader()
printTopCentered("Cnet OS Setup", 1)
printCentered(string.rep("-", w), 2)
printBottomCentered("coded by: connor murry")
end
--menu state
local menustate = "setup"
local mopt = {
["main"] = {
options = {"register new", "non-locked", "quit"}
}
}
--run setup function
function runSetup()
while true do
term.clear()
drawSetupHeader()
drawSetupMenu()
local id, key = os.pullEvent("key")
--UP = 200, DOWN = 208, ENTER = 28
if key == 200 and select > 1 then select = select-1
elseif key == 208 and select < #mopt[menustate].options then select = select-1
elseif key == 28 then
if #mopt[menustate].options[select] == "quit" then break end
menustate = mopt[menustate].options[select]
end
end
end
runSetup()
--this was created in part of the NitrogenFingers GUI tutorial