Advertisement
King0fGamesYami

minimenu

Nov 2nd, 2014
570
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.14 KB | None | 0 0
  1. local function minimenu( ... )
  2.     local tArgs = { ... }
  3.     local tSelections = {}
  4.     local _, y = term.getSize()
  5.     local n = 1
  6.     for i, str in ipairs( tArgs ) do
  7.         tSelections[ i ] = { str = str }
  8.         tSelections[ i ][ "x1" ] = n
  9.         tSelections[ i ][ "x2" ] = n + #str + 1
  10.         n = n + 2 + #str
  11.     end
  12.     for k, v in ipairs( tSelections ) do
  13.         term.setCursorPos( v["x1"], y )
  14.         term.write( ' ' .. v.str )
  15.     end
  16.     local slc = 1
  17.     local last = 1
  18.     while true do
  19.         term.setCursorPos( tSelections[ last ]["x1"], y )
  20.         term.write( ' ' )
  21.         term.setCursorPos( tSelections[ last ]["x2"], y )
  22.         term.write( ' ' )
  23.         term.setCursorPos( tSelections[ slc ]["x1"], y )
  24.         term.setTextColor( term.isColor() and colors.yellow or colors.white )
  25.         term.write( "[" )
  26.         term.setCursorPos( tSelections[ slc ]["x2"], y )
  27.         term.write( "]" )
  28.         while true do
  29.             local event, key = os.pullEvent( "key" )
  30.             if key == 203 and tSelections[ slc - 1 ] then
  31.                 last = slc
  32.                 slc = slc - 1
  33.                 break
  34.             elseif key == 205 and tSelections[ slc + 1 ] then
  35.                 last = slc
  36.                 slc = slc + 1
  37.                 break
  38.             elseif key == 28 then
  39.                 return tSelections[ slc ].str
  40.             end
  41.         end
  42.     end
  43. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement