Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local TextFile
- MonitorSide = "bottom"
- Monitor = peripheral.wrap(MonitorSide)
- MonitorLinePosition = 1
- MonitorCaretPosition = 1
- MonitorLength = 0
- CurrentColour = colours.white
- function OpenFile()
- return fs.open("text", "r")
- end
- function PrintLine(str, textColour)
- Monitor.setCursorPos(1, MonitorLinePosition)
- Monitor.setTextColour(textColour)
- Monitor.write(str)
- MonitorLinePosition = MonitorLinePosition + 1
- end
- function Print(str, textColour)
- Monitor.setCursorPos(MonitorCaretPosition, MonitorLinePosition)
- Monitor.setTextColour(textColour)
- Monitor.write(str)
- MonitorCaretPosition = MonitorCaretPosition + 1
- if (MonitorCaretPosition >= MonitorLength) then
- MonitorCaretPosition = 1
- MonitorLinePosition = MonitorLinePosition + 1
- end
- end
- function ParseColour(code)
- if (code == "0") then return colours.black end
- if (code == "1") then return colours.blue end
- if (code == "2") then return colours.green end
- if (code == "3") then return colours.cyan end
- if (code == "4") then return colours.red end
- if (code == "5") then return colours.purple end
- if (code == "6") then return colours.orange end
- if (code == "7") then return colours.lightGrey end
- if (code == "8") then return colours.grey end
- if (code == "9") then return colours.lightBlue end
- if (code == "a") then return colours.lime end
- if (code == "b") then return colours.lightBlue end
- if (code == "c") then return colours.red end
- if (code == "d") then return colours.pink end
- if (code == "e") then return colours.yellow end
- if (code == "f") then return colours.white
- else return colours.white end
- end
- function ParseAndPrintTextLine(line)
- if (line == "" or line == nil) then
- return
- end
- for i = 1, string.len(line), 1 do
- local character = string.sub(line, i, i + 1)
- if (character == "&") then
- i = i + 1
- local colourCode = string.sub(line, i, i + 1)
- CurrentColour = ParseColour(colourCode)
- else
- Print(character, CurrentColour)
- end
- end
- MonitorLinePosition = MonitorLinePosition + 1
- MonitorCaretPosition = 1
- end
- function Main()
- TextFile = OpenFile()
- local monX, monY = Monitor.getSize()
- MonitorLength = monX
- print("Carrot's monitor thingy.")
- print("Writing text...")
- Monitor.setBackgroundColor(colours.black)
- Monitor.setTextColor(colours.black)
- Monitor.clear()
- Monitor.setTextColor(colours.white)
- local index = 0
- while (true) do
- local line = TextFile.readLine()
- ParseAndPrintTextLine(line)
- if (line == nil) then
- break
- end
- index = index + 1
- end
- print("Wrote all text to the the monitor")
- end
- Main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement