Thomas9666

[LUA] Tom.API

Feb 26th, 2018
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. --Tom API V0.1.0--
  2. function getVersion(s)
  3. v = "TomOS_0.1.0"
  4. return v
  5. end
  6.  
  7. -- GUI Generating function --
  8. tX, tY = term.getSize()
  9.  
  10. function gui()
  11. term.setTextColor(colors.green)
  12. term.setBackgroundColour(colours.black)
  13. term.clear()
  14. term.setCursorPos(1,1)
  15. v = tom.getVersion()
  16. write("+" .. string.rep("-", tX-2) .."+")
  17. for i = 2, tY -1 do
  18. term.setCursorPos(1,i)
  19. write("|")
  20. term.setCursorPos(tX,i)
  21. write("|")
  22. end
  23. term.setCursorPos(1,tY)
  24. write("+" .. string.rep("-", tX -2).. "+")
  25. term.setTextColor(colors.blue)
  26. term.setBackgroundColor(colors.lightBlue)
  27. term.setCursorPos(tX -( string.len(v)+1),1)
  28. term.write(v)
  29. term.setTextColor(colors.green)
  30. term.setBackgroundColor(colors.black)
  31. term.setCursorPos(2,2)
  32. end
  33.  
  34. -- Print in centre of screen function --
  35.  
  36. function header(s)
  37. term.setCursorPos(math.ceil(((tX - string.len(s))/2)+1),2)
  38. term.write(s)
  39. end
  40.  
  41. -- newline fits gui function --
  42.  
  43. function newl()
  44. tx, ty = term.getCursorPos()
  45. term.setCursorPos(2,ty+1)
  46. end
  47.  
  48. -- Centre text after header --
  49. function centre(s)
  50. tx, t = term.getSize()
  51. t, ty = term.getCursorPos()
  52. term.setCursorPos(math.ceil(((tx - string.len(s))/2)+1),ty +1)
  53. term.write(s)
  54. end
  55.  
  56. -- Centre function for menu items --
  57. function menuc(s)
  58. mx,my = term.getSize()
  59. t, my = term.getCursorPos()
  60. x = (mx/2) - 4
  61. term.setCursorPos(x,my+1)
  62. term.write(s)
  63. end
  64.  
  65. -- Find active user name --
  66. function user()
  67. file = io.open("/os/.logon","r")
  68. f = file:read()
  69. return f
  70. end
  71.  
  72. -- Print a welcome for the user as header --
  73. function welcome()
  74. user = tom.user()
  75. welc = ("Welcome ".. user)
  76. tom.header(welc)
  77. end
Add Comment
Please, Sign In to add comment