Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local x, y = term.getSize()
- local sel = 1
- menu = { "New", "Open", "Help", "About", "Quit"}
- mFuncs = {
- function()
- cls()
- print("New file")
- end,
- function()
- cls()
- print("Open file.")
- end,
- function()
- cls()
- print("You probably got how this works. Or else you can't get on this text :)")
- end,
- function()
- cls()
- print("This is a menu demo!")
- print("Made by Admicos!")
- end,
- function()
- cls()
- print("Goodbye!")
- end
- }
- if term.isColor() then
- highl = colors.yellow
- else
- highl = colors.white
- end
- function cls()
- term.clear()
- term.setCursorPos(1,1)
- end
- function centerPr(text, ny)
- -- _x, _y = term.getSize()
- term.setCursorPos(math.floor((x - #text) / 2), ny or y / 2)
- print(text)
- end
- function selector(n)
- t = menu[n]
- term.setCursorPos(math.floor(((x - math.floor(#t / 2)) / 2) - 4), ((y / 2) + n) - 2)
- term.setTextColor(highl)
- print("[")
- term.setCursorPos(math.floor(((x - math.floor(#t / 2)) / 2) + 4), ((y / 2) + n) - 2)
- term.setTextColor(highl)
- print("]")
- end
- function clsel()
- for n, t in ipairs(menu) do
- term.setCursorPos(math.floor(((x - math.floor(#t / 2)) / 2) - 4), ((y / 2) + n) - 2)
- print(" ")
- term.setCursorPos(math.floor(((x - math.floor(#t / 2)) / 2) + 4), ((y / 2) + n) - 2)
- print(" ")
- end
- end
- function showMenu(title)
- cls()
- term.setTextColor(highl)
- centerPr(title, 2)
- term.setTextColor(colors.white)
- for n, t in ipairs(menu) do
- centerPr(t, ((y / 2) + n) - 2)
- end
- --DEMO CODE
- -- for n, t in ipairs(menu) do
- -- clsel()
- -- selector(n)
- -- sleep(1)
- -- end
- end
- showMenu("Menu Demo")
- clsel()
- selector(sel)
- while true do
- local _, keyC = os.pullEvent("key")
- if keyC == 208 then
- sel = sel + 1
- if sel > #menu then
- sel = #menu
- end
- clsel()
- selector(sel)
- end
- if keyC == 200 then
- sel = sel - 1
- if sel < 1 then
- sel = 1
- end
- clsel()
- selector(sel)
- end
- if keyC == 28 then
- term.setTextColor(colors.white)
- mFuncs[sel]()
- break
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement