Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- MenuAPI --
- local clr = function() term.clear() end
- local setText = function(col) term.setTextColor(colors[col]) end
- local setBack = function(col) term.setBackgroundColor(colors[col]) end
- local selector = {"[","]"}
- local selectorColor = "white"
- local selectedColor = "white"
- local l_color = {"white","orange","magenta","lightBlue","yellow","lime","pink","gray","lightGray","cyan","purple","blue","brown","green","red","black"}
- local upd = true
- local sel = 1
- version = 1
- function setSelector(x,y)
- selector = {x,y}
- end
- function setSelectorColor(col)
- if type(col) ~= "string" then error("Expected String, got "..type(col)) end
- local tmp = false
- for i=1, #l_color do
- if col == l_color[i] then tmp = true end
- end
- if tmp == false then
- error("Expect a Color, got "..type(col))
- end
- selectorColor = col
- end
- function setSelectedColor(col)
- if type(col) ~= "string" then error("Expected String, got "..type(col)) end
- local tmp = false
- for i=1, #l_color do
- if col == l_color[i] then tmp = true end
- end
- if tmp == false then
- error("Expect a Color, got "..type(col))
- end
- selectedColor = col
- end
- function resetPosition(bool)
- if type(bool) == "boolean" then
- setpos = bool
- else
- error("Expected boolean, got "..bool)
- end
- end
- function run(menu)
- if type(menu) ~= "table" then
- error("Expected Table, Got "..type(menu))
- end
- local running = true
- if setpos == nil or setpos == true then
- sel = 1
- end
- upd = true
- while running do
- if upd == true then
- clr()
- term.setCursorPos(1,1)
- for i=1, #menu do
- if sel == i then
- setText(selectorColor)
- write(selector[1].." ")
- setText(selectedColor)
- write(menu[i].." ")
- setText(selectorColor)
- print(selector[2].." ")
- else
- print(" "..menu[i].." ")
- end
- end
- upd = false
- end
- a,i = os.pullEvent("key")
- if i == keys.w or i == keys.up then
- if sel ~= 1 then sel = sel - 1 upd = true end
- elseif i == keys.s or i == keys.down then
- if sel ~= #menu then sel = sel + 1 upd = true end
- elseif i == keys.e or i == keys.enter then
- running = false
- end
- end
- return sel
- end
Advertisement
Add Comment
Please, Sign In to add comment