Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --variables
- local selected =1
- local startposes = {}
- local startys = {}
- local pcolor = colors.blue
- local tcolor = colors.lime
- local bgcolor = colors.black
- function drawSelections(sel)
- term.setTextColor(tcolor)
- term.setBackgroundColor(bgcolor)
- term.setCursorPos(1,1)
- term.clear()
- local maxL = -1
- for i=1,table.maxn(sel) do
- maxL = math.max(#sel[i],maxL)
- end
- --maxL = maxL/2
- maxL = maxL+1
- --maxL is now the spacing
- local area = 0
- local _,y = term.getSize()
- for i=1,table.maxn(sel) do
- if (i)-(area*y)>y then
- area=area+1
- term.setCursorPos(1,1)
- end
- local _,oy=term.getCursorPos()
- term.setCursorPos(((maxL)/2)+(maxL*area),oy)
- startposes[i] = ((maxL)/2)+(maxL*area)
- startys[i]=oy
- term.write(sel[i])--more effecient than print
- term.setCursorPos(1,oy+1)
- end
- end
- function drawPointer(sel,start,endc)
- term.setTextColor(pcolor)
- term.setBackgroundColor(bgcolor)
- --draw starter
- term.setCursorPos(startposes[selected]-1,startys[selected])
- term.write(start)
- term.setCursorPos(startposes[selected]+#sel[selected],startys[selected])
- term.write(endc)
- end
- function movePointer(amm,sel)
- --undo previous pointer\
- if not sel[selected+amm] then
- return false
- end
- drawPointer(sel," "," ")
- --add to pointer
- selected = selected+amm
- drawPointer(sel,"[","]")
- end
- --test code
- 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...",}
- table.insert(a,"Return")
- drawSelections(a)
- movePointer(0,a)
- local _,y=term.getSize()
- while true do
- local b = {os.pullEvent()}
- if b[1]=="key" then
- if b[2] == 208 then
- movePointer(1,a)
- elseif b[2] ==28 then
- term.clear()
- term.setCursorPos(1,1)
- if selected ==#a then
- error()
- end
- term.write"Args: "
- term.setTextColor(tcolor)
- local args = read()
- shell.run(a[selected].." "..args)
- sleep(1)
- drawSelections(a)
- movePointer(0,a)
- elseif b[2]==200 then
- movePointer(-1,a)
- elseif b[2]==205 then
- movePointer(y,a)
- elseif b[2]==203 then
- movePointer(0-y,a)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment