bobmarley12345

computersign

Dec 12th, 2020 (edited)
611
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local TextFile
  2. MonitorSide = "bottom"
  3. Monitor = peripheral.wrap(MonitorSide)
  4. MonitorLinePosition = 1
  5. MonitorCaretPosition = 1
  6. MonitorLength = 0
  7. CurrentColour = colours.white
  8.  
  9. function OpenFile()
  10.     return fs.open("text", "r")
  11. end
  12.  
  13. function PrintLine(str, textColour)
  14.     Monitor.setCursorPos(1, MonitorLinePosition)
  15.     Monitor.setTextColour(textColour)
  16.     Monitor.write(str)
  17.     MonitorLinePosition = MonitorLinePosition + 1
  18. end
  19.  
  20. function Print(str, textColour)
  21.     Monitor.setCursorPos(MonitorCaretPosition, MonitorLinePosition)
  22.     Monitor.setTextColour(textColour)
  23.     Monitor.write(str)
  24.     MonitorCaretPosition = MonitorCaretPosition + 1
  25.     if (MonitorCaretPosition >= MonitorLength) then
  26.         MonitorCaretPosition = 1
  27.         MonitorLinePosition = MonitorLinePosition + 1
  28.     end
  29. end
  30.  
  31. function ParseColour(code)
  32.     if (code == "0") then return colours.black end
  33.     if (code == "1") then return colours.blue end
  34.     if (code == "2") then return colours.green end
  35.     if (code == "3") then return colours.cyan end
  36.     if (code == "4") then return colours.red end
  37.     if (code == "5") then return colours.purple end
  38.     if (code == "6") then return colours.orange end
  39.     if (code == "7") then return colours.lightGrey end
  40.     if (code == "8") then return colours.grey end
  41.     if (code == "9") then return colours.lightBlue end
  42.     if (code == "a") then return colours.lime end
  43.     if (code == "b") then return colours.lightBlue end
  44.     if (code == "c") then return colours.red end
  45.     if (code == "d") then return colours.pink end
  46.     if (code == "e") then return colours.yellow end
  47.     if (code == "f") then return colours.white
  48.     else return colours.white end
  49. end
  50.  
  51. function ParseAndPrintTextLine(line)
  52.     if (line == "" or line == nil) then
  53.         return
  54.     end
  55.     for i = 1, string.len(line), 1 do
  56.         local character = string.sub(line, i, i + 1)
  57.         if (character == "&") then
  58.             i = i + 1
  59.             local colourCode = string.sub(line, i, i + 1)
  60.             CurrentColour = ParseColour(colourCode)
  61.         else
  62.             Print(character, CurrentColour)
  63.         end
  64.     end
  65.     MonitorLinePosition = MonitorLinePosition + 1
  66.     MonitorCaretPosition = 1
  67. end
  68.  
  69. function Main()
  70.     TextFile = OpenFile()
  71.     local monX, monY = Monitor.getSize()
  72.     MonitorLength = monX
  73.     print("Carrot's monitor thingy.")
  74.     print("Writing text...")
  75.     Monitor.setBackgroundColor(colours.black)
  76.     Monitor.setTextColor(colours.black)
  77.     Monitor.clear()
  78.     Monitor.setTextColor(colours.white)
  79.     local index = 0
  80.     while (true) do
  81.         local line = TextFile.readLine()
  82.         ParseAndPrintTextLine(line)
  83.         if (line == nil) then
  84.             break
  85.         end
  86.         index = index + 1
  87.     end
  88.     print("Wrote all text to the the monitor")
  89. end
  90.  
  91. Main()
RAW Paste Data