5bitesofcookies

visualshell

Mar 26th, 2015
302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.38 KB | None | 0 0
  1. --variables
  2. local selected =1
  3. local startposes = {}
  4. local startys = {}
  5. local pcolor = colors.blue
  6. local tcolor = colors.lime
  7. local bgcolor = colors.black
  8.  
  9.  
  10.  
  11. function drawSelections(sel)
  12.     term.setTextColor(tcolor)
  13.     term.setBackgroundColor(bgcolor)
  14.     term.setCursorPos(1,1)
  15.     term.clear()
  16.     local maxL = -1
  17.     for i=1,table.maxn(sel) do
  18.         maxL = math.max(#sel[i],maxL)
  19.     end
  20.     --maxL = maxL/2
  21.     maxL = maxL+1
  22.     --maxL is now the spacing
  23.     local area = 0
  24.     local _,y = term.getSize()
  25.     for i=1,table.maxn(sel) do
  26.         if (i)-(area*y)>y then
  27.             area=area+1
  28.             term.setCursorPos(1,1)
  29.         end
  30.         local _,oy=term.getCursorPos()
  31.         term.setCursorPos(((maxL)/2)+(maxL*area),oy)
  32.         startposes[i] = ((maxL)/2)+(maxL*area)
  33.         startys[i]=oy
  34.         term.write(sel[i])--more effecient than print
  35.         term.setCursorPos(1,oy+1)
  36.     end
  37.        
  38.    
  39.    
  40. end
  41. function drawPointer(sel,start,endc)
  42.     term.setTextColor(pcolor)
  43.     term.setBackgroundColor(bgcolor)
  44.     --draw starter
  45.     term.setCursorPos(startposes[selected]-1,startys[selected])
  46.     term.write(start)
  47.     term.setCursorPos(startposes[selected]+#sel[selected],startys[selected])
  48.     term.write(endc)
  49.    
  50.    
  51.    
  52. end
  53. function movePointer(amm,sel)
  54.     --undo previous pointer\
  55.     if not sel[selected+amm] then
  56.         return false
  57.     end
  58.     drawPointer(sel," "," ")
  59.     --add to pointer
  60.     selected = selected+amm
  61.     drawPointer(sel,"[","]")
  62. end
  63.  
  64.  
  65.  
  66.  
  67.  
  68. --test code
  69.  
  70. local a = shell.programs()--{"Hi!","bye...","Hi!","bye...","Hi!","bye...","Hi!","bye...","Hi!","bye...","Hi!","bye...","Hi!","bye...","Hi!","bye...","Hi!","bye...","Hi!","bye...","Hi!","bye...","Hi!","bye...","Hi!","bye...","Hi!","bye...","Hi!","bye...","Hi!","bye...","Hi!","bye...","Hi!","bye...","Hi!","bye...","Hi!","bye...","Hi!","bye...","Hi!","bye...",}
  71. table.insert(a,"Return")
  72. drawSelections(a)
  73. movePointer(0,a)
  74. local _,y=term.getSize()
  75. while true do
  76.     local b = {os.pullEvent()}
  77.     if b[1]=="key" then
  78.         if b[2] == 208 then
  79.             movePointer(1,a)
  80.         elseif b[2] ==28 then
  81.             term.clear()
  82.             term.setCursorPos(1,1)
  83.             if selected ==#a then
  84.                 error()
  85.             end
  86.             term.write"Args: "
  87.             term.setTextColor(tcolor)
  88.             local args = read()
  89.             shell.run(a[selected].." "..args)
  90.             sleep(1)
  91.             drawSelections(a)
  92.             movePointer(0,a)
  93.         elseif b[2]==200 then
  94.             movePointer(-1,a)
  95.         elseif b[2]==205 then
  96.             movePointer(y,a)
  97.         elseif b[2]==203 then
  98.             movePointer(0-y,a)
  99.         end
  100.     end
  101. end
Advertisement
Add Comment
Please, Sign In to add comment