Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- term.clear()
- local arg = {...}
- printer = peripheral.wrap(arg[1])
- io.input(arg[2])
- text = io.read('*all')
- function check()
- assert(printer.newPage(),'please insert some paper!')
- paperWidth, paperHeight = printer.getPageSize()
- end
- function printerTable(text,paperWidth)
- table = {}
- i = 1
- local space1 = 0
- local space2 = 0
- local lowerSpace = 0
- local printerTable = {}
- while (space1 ~= nil) and (space2 ~= nil) do
- while (space2 ~= nil) and (space1 ~= nil) and (space1 < i*paperWidth) and (space2 < i*paperWidth) do
- space1 = string.find(text,' ', space2+1)
- space2 = string.find(text,' ', space1+1)
- if (space1 ~= nil) and (space2 ~= nil) then
- lowerSpace = math.min(space1,space2)
- elseif space1 ~= nil then
- lowerSpace = space1
- else
- lowerSpace = space2
- end
- end
- table[1] = 0
- table[i+1] = lowerSpace
- i = i+1
- print(#table)
- end
- for i = 1, #table-1 do
- printerTable[i] = string.sub(text,table[i],table[i+1]-1)
- return printerTable
- end
- end
- check()
- if paperWidth*paperHeight<string.len(text) then
- print('This text file won\'t fit on this page!')
- else
- print(#printerTable(text,paperWidth))
- for i, v in ipairs(printerTable(text,paperWidth)) do
- print(v)
- printer.write(v)
- printer.setCursorPos(i+1,i)
- end
- end
- printer.endPage()
- print(text)
- print(paperWidth,paperHeight)
- print(string.len(text))
Add Comment
Please, Sign In to add comment