Advertisement
Cobra_Tomtrein-temp-

Untitled

Jul 23rd, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. function go()
  2. local tw,th = term.getSize()
  3. local selected = 0
  4. local inp = {}
  5. local lbl_locs = {{16,3,"Name:"},{16,6,"Author:"},{16,9,"Install Dir:"},{16,12,"Files:"}}
  6. local inp_locs = {{16,4,8},{16,7,8},{16,10,10}}
  7. local btn_locs = {{tw-6,th,"accept"}}
  8. function getInput(type,key)
  9. if selected == 0 then return end
  10. inp[selected] = inp[selected] or ""
  11. if type == "char" then
  12. inp[selected] = inp[selected]..key
  13. elseif type == "key" then
  14. if key == keys.enter then
  15. selected = 0
  16. elseif key == keys.backspace then
  17. inp[selected] = inp[selected]:sub(1,-2)
  18. end
  19. end
  20. end
  21. function getMouseClick(x,y)
  22. for i,v in pairs(inp_locs) do
  23. if x >= v[1] and x <= v[1]+v[3]-1 and y == v[2] then
  24. selected = i
  25. return
  26. end
  27. end
  28. for i,v in pairs(btn_locs) do
  29. if x >= v[1] and x <= v[1]+#(v[3])-1 and y == v[2] then
  30. return "end"
  31. end
  32. end
  33. end
  34. function disp()
  35. term.setBackgroundColor(colors.black)
  36. term.clear()
  37. term.setBackgroundColor(colors.gray)
  38. term.setTextColor(colors.lightGray)
  39. for i,v in pairs(inp_locs) do
  40. term.setCursorPos(v[1], v[2])
  41. term.write(string.rep(" ",v[3]))
  42. term.setCursorPos(v[1], v[2])
  43. term.write(string.sub((inp[i] or ""),-v[3]))
  44. end
  45. term.setTextColor(colors.white)
  46. for i,v in pairs(btn_locs) do
  47. term.setCursorPos(v[1], v[2])
  48. term.write(v[3])
  49. end
  50. term.setBackgroundColor(colors.black)
  51. for i,v in pairs(lbl_locs) do
  52. term.setCursorPos(v[1], v[2])
  53. term.write(v[3])
  54. end
  55. end
  56. while true do
  57. disp()
  58. local ev,a1,a2,a3 = os.pullEvent()
  59. if ev == "char" or ev == "key" then
  60. getInput(ev,a1)
  61. elseif ev == "mouse_click" then
  62. if getMouseClick(a2,a3) == "end" then
  63. return inp
  64. end
  65. end
  66. end
  67. end
  68.  
  69. go()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement