Advertisement
Ale2610

Untitled

Jan 31st, 2015
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. local startY = 6
  2. local height = h - startY - 1
  3. local scroll = 0
  4. local selected = 1
  5.  
  6. local draw = function()
  7. fill(1, startY, w, height + 1, theme.background)
  8.  
  9. for i = scroll + 1, scroll + height do
  10. if results[i] then
  11. if i == selected + scroll then
  12. term.setCursorPos(3, (i - scroll) + startY)
  13. term.write("> " .. currentProtocol .. "://" .. results[i])
  14. else
  15. term.setCursorPos(5, (i - scroll) + startY)
  16. term.write(currentProtocol .. "://" .. results[i])
  17. end
  18. end
  19. end
  20. end
  21.  
  22. draw()
  23. while true do
  24. local event, but, x, y = os.pullEvent()
  25.  
  26. if event == "key" then
  27. if but == keys.up and selected + scroll > 1 then
  28. if selected > 1 then
  29. selected = selected - 1
  30. else
  31. scroll = math.max(0, scroll - 1)
  32. end
  33. elseif but == keys.down and selected + scroll < #results then
  34. if selected < height then
  35. selected = selected + 1
  36. else
  37. scroll = math.min(scroll + 1, #results - height)
  38. end
  39. elseif but == keys.enter then
  40. local item = results[scroll + selected]
  41. if item then
  42. os.queueEvent(redirectEvent, item)
  43. coroutine.yield()
  44. end
  45. end
  46.  
  47. draw()
  48. elseif event == "mouse_scroll" then
  49. if but > 0 then
  50. os.queueEvent("key", keys.down)
  51. else
  52. os.queueEvent("key", keys.up)
  53. end
  54. end
  55. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement