SHARE
TWEET

Menu MKV

Brodur Apr 9th, 2019 (edited) 21 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local term = require("term")
  2. local event = require("event")
  3. local methods = {}
  4.  
  5. function methods.list(m, header)
  6.   local header = header or "Menu List"
  7.   local n=1
  8.  
  9.   while(true) do
  10.     term.clear()
  11.     term.setCursor(1,1)
  12.     term.write(header)
  13.     term.setCursor(1,2)
  14.  
  15.     for i=1, #m, 1 do
  16.       if(i==n) then
  17.         term.write(" [" .. m[i] .. "]\n")
  18.       else
  19.         term.write("  " ..  m[i] .. "\n")
  20.       end
  21.     end
  22.  
  23.     local _,_,_,key = event.pull("key_down")  
  24.  
  25.     if(key==200 and n>1) then --go up
  26.       n = n-1
  27.     end
  28.     if(key==208 and n<#m) then --go down
  29.       n = n+1
  30.     end
  31.     if(key==28) then --exit
  32.       break
  33.     end
  34.   end
  35.  
  36.   term.clear()
  37.   term.setCursor(1,1)
  38.   return n
  39. end
  40.  
  41. function methods.dialog(prompt, lOpt, rOpt)
  42.   local prompt = prompt or "Continue"
  43.   local lOpt = lOpt or "YES"
  44.   local rOpt = rOpt or "NO"
  45.   local n = 1
  46.  
  47.   term.write(prompt.."\n")
  48.  
  49.   while true do
  50.     local x, y =term.getCursor()
  51.     term.clearLine()    
  52.    
  53.     if n==1 then
  54.       term.setCursor(x, y)
  55.       term.clearLine()
  56.       term.write ("["..lOpt.."]   "..rOpt)
  57.     else
  58.       term.setCursor(x, y)
  59.       term.clearLine()
  60.       term.write(" "..lOpt.."   ["..rOpt.."]")
  61.     end
  62.  
  63.     term.setCursor(x, y)  
  64.     local _,_,_,key = event.pull("key_down")  
  65.  
  66.     if key==203 then n=1 end
  67.     if key==205 then n=2 end
  68.     if key==28  then break end
  69.   end
  70.   term.write("\n")
  71.   return n
  72. end
  73.  
  74. return methods
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top