Advertisement
Guest User

FreshAPI 1.1b

a guest
Jul 18th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. -- FreshApi (1.1b)
  2.  
  3.  
  4. function centerText (text)
  5. local w, h = term.getSize()
  6. term.setCursorPos(math.floor(w / 2 - text:len() / 2 + .5), math.floor(h / 2 + .5))
  7. write(text)
  8. end
  9.  
  10. function centerPrint (text)
  11. local textLen = string.len(text)
  12. local screenW,_ = term.getSize()
  13. local xCoords = tonumber(math.ceil((screenW / 2) - (textLen / 2)))
  14. local _,termY = term.getCursorPos()
  15. term.setCursorPos(xCoords,termY)
  16. print(text)
  17. return xCoords
  18. end
  19.  
  20. function drawLine ()
  21. term.write("---------------------------------------------------")
  22. end
  23.  
  24. function line ()
  25. return "---------------------------------------------------"
  26. end
  27.  
  28. function slowCenterPrint (text, time)
  29. local textLen = string.len(text)
  30. local screenW,_ = term.getSize()
  31. local xCoords = tonumber(math.ceil((screenW / 2) - (textLen / 2)))
  32. local _,termY = term.getCursorPos()
  33. term.setCursorPos(xCoords,termY)
  34. textutils.slowWrite(text, time)
  35. return xCoords
  36. end
  37.  
  38. function drawMenu(tab, t,d)
  39. wybor = 1
  40. w,h = term.getSize()
  41. scr = 0
  42. while true do
  43. c,v = term.getSize()
  44. if #tab > 10 then
  45. tabL = 10
  46. else
  47. tabL = #tab
  48. end
  49. a = 0
  50. for i=1,tabL do
  51. a = a + 1
  52. if t == nil and d == nil then
  53. term.setCursorPos(1, a + math.floor(h / 2 - .5) - #tab / 2 + .5)
  54. else
  55. term.setCursorPos(t, d + a - 1)
  56. end
  57. term.clearLine()
  58. if a+scr == wybor then
  59. if t == nil and d == nil then
  60. centerPrint("[".. tab[i+scr].. "]")
  61. else
  62. write("[".. tostring(tab[i+scr]).. "]")
  63. end
  64. else
  65. if t == nil and d == nil then
  66. centerPrint(tab[i+scr])
  67. else
  68. write(tostring(tab[i+scr]))
  69. end
  70. end
  71. end
  72. event, key = os.pullEvent("key")
  73. if key == 200 and wybor>1 then
  74. if wybor > 10 then
  75. scr = scr - 1
  76. end
  77. wybor = wybor - 1
  78. elseif key == 208 and wybor<#tab then
  79. wybor = wybor + 1
  80. if wybor > 10 then
  81. scr = scr + 1
  82. end
  83. elseif key == 28 then
  84. term.clear()
  85. return wybor
  86. end
  87. end
  88. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement