function menu(t,x,y,ht) local size={term.getSize()} ht=math.min(ht or 0,#t) local scrolled=0 local scroll=false if #t>ht then scroll=true end local max=0 for i=1,#t do max=math.max(max,#t[i]) end while true do for i=1,(scroll and ht or #t) do term.setCursorPos(x,y+i-1) write(string.rep(' ',max)) end for i=1,(scroll and ht or #t) do term.setCursorPos((scrolled>0 and i==1 and math.floor(max/2+x) or scrolled+ht<#t and i==ht and scroll and math.floor(max/2+x) or x),y+i-1) write(scrolled>0 and i==1 and '^' or scrolled+ht<#t and i==ht and scroll and 'v' or t[i+scrolled]) end --if scroll then term.setCursorPos(x,y+ht-1) write('v') end local input={os.pullEvent()} if input[1]=='mouse_click' and input[2]==1 and input[3]>=x and input[3]<=x+max-1 and input[4]>=y and input[4]<=y+ht-1 then if scrolled>0 and input[4]==y then scrolled=scrolled-1 elseif scrolled+ht<#t and scroll and input[4]==y+ht-1 then scrolled=scrolled+1 else return t[input[4]+scrolled-y+1] end end end end term.clear() print(menu({'111','222','333','444','555'},2,2,6))