Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local printer = peripheral.find("printer")
- local maxwidth, maxheight = 0
- function checkInk()
- print("Ink needed")
- while printer.getInkLevel() == 0 do
- sleep(1)
- end
- end
- function checkPaper()
- print("Wanna paper")
- while printer.getPaperLevel() == 0 do
- sleep(1)
- end
- end
- function writeLine(line, text)
- if text == nil then
- return line
- end
- if text:sub(1, 1) == "#" then
- text = text:sub(2)
- printer.setPageTitle(text)
- return line
- end
- printer.setCursorPos(1, line)
- if text:len() > maxwidth then
- printer.write(text:sub(1, maxwidth))
- line = writeLine(line + 1, text:sub(maxwidth + 1))
- else
- printer.write(text)
- line = line + 1
- end
- return line
- end
- function writePage(filename)
- if not fs.exists(filename) then
- print("There is no "..filename.." file")
- printer = false
- return
- end
- local file = fs.open(filename, "r")
- if not file then
- print("There is no "..filename.." file")
- printer = false
- return
- end
- checkInk()
- checkPaper()
- printer.newPage()
- printer.setPageTitle(filename)
- maxwidth, maxheight = printer.getPageSize()
- local ln = 1
- local line = file.readLine()
- print("Printing "..filename.." file")
- repeat
- ln = writeLine(ln, line)
- if ln > maxheight then
- return
- end
- line = file.readLine()
- until line == nil
- sleep(1)
- end
- while printer do
- local event, p1, p2 = os.pullEvent("redstone")
- writePage("greetings")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement