Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local rgui --recursive gui
- --##Key grabber##
- --local evt, key = os.pullEvent("key")
- local titleColor = colors.pink
- local menuColor = colors.purple
- local textColor = colors.white
- local highlightColor = colors.pink
- local menuColors = {
- title = titleColor,
- menu = menuColor,
- text = textColor,
- highlight = highlightColor
- }
- --Args: menu = array of strings, colorList = array of named colors
- --returns: int = cursor, string = name of menu item chosen, bool = true: user chose this option / false: user wants to exit menu
- local function openMenu(menu,colorList)
- local col = term.getTextColor()
- local cursor = 1
- term.clear()
- while true do
- term.setCursorPos(1,1)
- for i = 1, #menu do
- if cursor == i then
- term.setTextColor(colorList.highlight)
- print("{"..i.."} "..menu[i])
- else
- term.setTextColor(colorList.text)
- print("["..i.."] "..menu[i])
- end
- end
- local evt, key = os.pullEvent("key")
- key = keys.getName(key)
- if key == "up" and cursor > 1 then
- cursor = cursor - 1
- elseif key == "down" and cursor < #menu then
- cursor = cursor + 1
- --elseif key == "left" then
- --elseif key == "right" then
- elseif key == "enter" then
- term.setTextColor(col)
- return cursor, menu[cursor], true
- elseif key == "backspace" then
- term.setTextColor(col)
- return cursor, false
- end
- end
- end
- local menu = {"Quarry Miner", "Strip Miner","1","2","3","4","5"}
- while true do
- local cursor,item,val = openMenu(menu,menuColors)
- term.clear()
- print(cursor,item,val)
- print("Press 'enter' to continue")
- read()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement