Guest User

TUI ComputerCraft API

a guest
Jun 5th, 2013
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.09 KB | None | 0 0
  1. function yn()
  2. local position = 1
  3. while true do
  4. local x ,  y = term.getCursorPos()
  5. term.clearLine()
  6. if position == 1 then write("                    >Yes<    No") else write ("                     Yes    >No<") end
  7. term.setCursorPos(x,y)
  8. a, b = os.pullEvent("key")
  9. if b == 203 and position == 2 then position = 1 end
  10. if b == 205 and position == 1 then position = 2 end
  11. if b == 57 then print(" ") break end
  12. end
  13. if position == 1 then return true end
  14. if position == 2 then return false end
  15. end
  16.  
  17. function ynTitleTop(title)
  18. local position = 1
  19. while true do
  20. local x ,  y = term.getCursorPos()
  21. term.clearLine()
  22. print(title[1])
  23. if position == 1 then write("                    >Yes<    No") else write ("                     Yes    >No<") end
  24. term.setCursorPos(x,y)
  25. a, b = os.pullEvent("key")
  26. if b == 203 and position == 2 then position = 1 end
  27. if b == 205 and position == 1 then position = 2 end
  28. if b == 57 then print(" ") break end
  29. end
  30. if position == 1 then return true end
  31. if position == 2 then return false end
  32. end
  33.  
  34. function ynTitleBottom(title)
  35. local position = 1
  36. while true do
  37. local x ,  y = term.getCursorPos()
  38. term.clearLine()
  39. if position == 1 then write("                    >Yes<    No") else write ("                     Yes    >No<") end
  40. print(" ")
  41. write(title[1])
  42. term.setCursorPos(x,y)
  43. a, b = os.pullEvent("key")
  44. if b == 203 and position == 2 then position = 1 end
  45. if b == 205 and position == 1 then position = 2 end
  46. if b == 57 then print(" ") break end
  47. end
  48. if position == 1 then return true end
  49. if position == 2 then return false end
  50. end
  51.  
  52. function ynTitleBoth(titleTop, titleBottom)
  53. local position = 1
  54. while true do
  55. local x ,  y = term.getCursorPos()
  56. term.clearLine()
  57. print(titleTop[1])
  58. if position == 1 then write("                    >Yes<    No") else write ("                     Yes    >No<") end
  59. print(" ")
  60. write(titleBottom[1])
  61. term.setCursorPos(x,y)
  62. a, b = os.pullEvent("key")
  63. if b == 203 and position == 2 then position = 1 end
  64. if b == 205 and position == 1 then position = 2 end
  65. if b == 57 then print(" ") break end
  66. end
  67. if position == 1 then return true end
  68. if position == 2 then return false end
  69. end
  70.  
  71. function custom(options)
  72. position = 1
  73. while true do
  74. term.clear()
  75. term.setCursorPos(1,2)
  76. for i = 1, #options, 1 do
  77. if i == position then print(" >"..options[i].."<") else print( " ".. options[i]) end
  78. end
  79. a, b = os.pullEvent("key")
  80. if b == 200 and position > 1 then position = position - 1 end
  81. if b == 208 and position < #options then position = position + 1 end
  82. if b == 57 then break end
  83. end
  84. term.clear()
  85. term.setCursorPos(1,2)
  86. return position
  87. end
  88.  
  89. function customTitleTop(options , title)
  90. position = 1
  91. while true do
  92. term.clear()
  93. term.setCursorPos(1,2)
  94. print(title[1])
  95. for i = 1, #options, 1 do
  96. if i == position then print(" >"..options[i].."<") else print( " ".. options[i]) end
  97. end
  98. a, b = os.pullEvent("key")
  99. if b == 200 and position > 1 then position = position - 1 end
  100. if b == 208 and position < #options then position = position + 1 end
  101. if b == 57 then break end
  102. end
  103. term.clear()
  104. term.setCursorPos(1,2)
  105. return position
  106. end
  107.  
  108. function customTitleBottom(options, title)
  109. position = 1
  110. while true do
  111. term.clear()
  112. term.setCursorPos(1,2)
  113. for i = 1, #options, 1 do
  114. if i == position then print(" >"..options[i].."<") else print( " ".. options[i]) end
  115. end
  116. print(title[1])
  117. a, b = os.pullEvent("key")
  118. if b == 200 and position > 1 then position = position - 1 end
  119. if b == 208 and position < #options then position = position + 1 end
  120. if b == 57 then break end
  121. end
  122. term.clear()
  123. term.setCursorPos(1,2)
  124. return position
  125. end
  126.  
  127. function customTitleBoth(options, titleTop,titleBottom)
  128. position = 1
  129. while true do
  130. term.clear()
  131. term.setCursorPos(1,2)
  132. print(titleTop[1])
  133. for i = 1, #options, 1 do
  134. if i == position then print(" >"..options[i].."<") else print( " ".. options[i]) end
  135. end
  136. print(titleBottom[1])
  137. a, b = os.pullEvent("key")
  138. if b == 200 and position > 1 then position = position - 1 end
  139. if b == 208 and position < #options then position = position + 1 end
  140. if b == 57 then break end
  141. end
  142. term.clear()
  143. term.setCursorPos(1,2)
  144. return position
  145. end
Advertisement
Add Comment
Please, Sign In to add comment