DabDaddy6223

monitor_api

Aug 3rd, 2026 (edited)
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.71 KB | None | 0 0
  1. MONITOR = peripheral.find("monitor")
  2.  
  3. function mon_ClearAndPrint(str)
  4.     MONITOR.clear()
  5.     MONITOR.setCursorPos(1, 1)
  6.     MONITOR.write(str)
  7. end
  8.  
  9. function mon_SetTextColor(color)
  10.     MONITOR.setTextColor(color)
  11. end
  12.  
  13. function mon_PrintCentred(str)
  14.     local x, y = MONITOR.getCursorPos()
  15.     local width, _ = MONITOR.getSize()
  16.  
  17.     local startX = math.floor((width - #str) / 2) + 1
  18.     MONITOR.setCursorPos(startX, y)
  19.     MONITOR.write(str)
  20. end
  21.  
  22. function mon_PrintLineOn(str, line_number)
  23.     MONITOR.setCursorPos(1, line_number)
  24.     MONITOR.clearLine()
  25.     MONITOR.write(str)
  26. end
  27.  
  28. function mon_PrintLineOnCentred(str, line_number)
  29.     MONITOR.setCursorPos(1, line_number)
  30.     MONITOR.clearLine()
  31.     mon_PrintCentred(str)
  32. end
  33.  
  34. function mon_PrintScrollingTextFromBottom(text, gap_in_seconds)
  35.     MONITOR.clear()
  36.     local _, height = MONITOR.getSize()
  37.     for i, line in ipairs(text) do
  38.         if line:sub(1, 3) == "(g)" then
  39.             MONITOR.setTextColor(colors.green)
  40.             line = line:sub(4)
  41.         elseif line:sub(1, 3) == "(r)" then
  42.             MONITOR.setTextColor(colors.red)
  43.             line = line:sub(4)
  44.         elseif line:sub(1, 3) == "(y)" then
  45.             MONITOR.setTextColor(colors.yellow)
  46.             line = line:sub(4)
  47.         elseif line:sub(1, 3) == "(b)" then
  48.             MONITOR.setTextColor(colors.blue)
  49.             line = line:sub(4)
  50.         else
  51.             MONITOR.setTextColor(colors.white)
  52.         end
  53.  
  54.         mon_PrintLineOn(line, height)
  55.         MONITOR.scroll(1)
  56.  
  57.         local sleep_time = gap_in_seconds
  58.         if line:find("...", 1, true) then
  59.             sleep_time = sleep_time * 5
  60.         end
  61.  
  62.         sleep(sleep_time)
  63.     end
  64. end
Advertisement
Add Comment
Please, Sign In to add comment