Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. --* Colors *--
  2. ACCENT_COLOR = colors.yellow
  3. ACCENT_TEXT_COLOR = colors.black
  4. BACKGROUND_COLOR = colors.black
  5. TEXT_COLOR = colors.yellow
  6.  
  7. --* Config *--
  8. LOG_DAY = true
  9.  
  10. --* Functions *--
  11.  
  12. --- @return a pretty timestamp for logging
  13. function timeStamp()
  14. if LOG_DAY then
  15. return ('d' .. os.day() .. ' ' .. textutils.formatTime(os.time(), true))
  16. else
  17. return (textutils.formatTime(os.time(), true))
  18. end
  19. end
  20.  
  21. --- logs a message and displays it on the term together with the current time
  22. function log(message)
  23. local x,y = term.getCursorPos()
  24. if (y == 19) then
  25. term.setCursorPos(1, 2)
  26. else
  27. term.setCursorPos(1, y + 1)
  28. end
  29. term.setBackgroundColor(BACKGROUND_COLOR)
  30. term.setTextColor(TEXT_COLOR)
  31. term.clearLine()
  32. term.write('[' .. timeStamp() .. ']: ' .. message)
  33. end
  34.  
  35. --- Displays a fancy headline with the current time on the term
  36. -- Must be called each second
  37. function fancyTerm()
  38. local x,y = term.getCursorPos()
  39. local t = timeStamp()
  40. local label = getLabel()
  41. term.setCursorPos(1, 1)
  42. term.setTextColor(ACCENT_COLOR)
  43. term.setBackgroundColor(ACCENT_TEXT_COLOR)
  44. term.write(label)
  45. for i = 1, (51 - string.len(t) - string.len(label)) do
  46. term.write(' ')
  47. end
  48. term.write(t)
  49. term.setCursorPos(x, y)
  50. term.setBackgroundColor(BACKGROUND_COLOR)
  51. term.setTextColor(TEXT_COLOR)
  52. end
  53.  
  54. --- Setup the term, display the fancy headline and change the background
  55. function setup()
  56. term.setBackgroundColor(BACKGROUND_COLOR)
  57. term.clear()
  58. fancyTerm()
  59. end
  60.  
  61. --- @return the label of the computer. If not set use the id
  62. local function getLabel()
  63. if os.getComputerLabel() == nil then
  64. os.setComputerLabel("#" .. os.getComputerID())
  65. end
  66. return os.getComputerLabel()
  67. end
  68.  
  69. --- Display some data on the term
  70. function writeData(line, label, value, labelColor, valueColor, valueBackgroundColor, labelLength, valueLength, indent)
  71. labelColor = labelColor or TEXT_COLOR
  72. valueColor = valueColor or ACCENT_TEXT_COLOR
  73. valueBackgroundColor = valueBackgroundColor or ACCENT_COLOR
  74. labelLength = labelLength or 14
  75. valueLength = valueLength or 12
  76. indent = indent or 3
  77. term.setCursorPos(indent,line)
  78. term.setBackgroundColor(BACKGROUND_COLOR)
  79. term.setTextColor(labelColor)
  80. term.write(label)
  81. term.write(":")
  82. for i = string.len(label), labelLength, 1 do
  83. term.write(" ")
  84. end
  85. term.setBackgroundColor(valueBackgroundColor)
  86. term.setTextColor(valueColor)
  87. for i = string.len(value), valueLength, 1 do
  88. term.write(" ")
  89. end
  90. term.write(value)
  91. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement