Advertisement
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')
- spacesTable = {}
- table = {}
- printerTable = {}
- function check()
- assert(printer.newPage(),'please insert some paper!')
- paperWidth, paperHeight = printer.getPageSize()
- end
- function clearPage()
- for i = 1, 25 do
- for j = 1, 21 do
- printer.setCursorPos(i,j)
- printer.write(' ')
- end
- end
- printer.setCursorPos(1,1)
- end
- function printerTableFunction()
- local space1 = 0
- local l = 1
- local k = 1
- local i = 1
- while (space1 ~= nil) do -- Makes a table with all of the spaces' location
- space2 = space1
- space1 = string.find(text,' ', space2+1)
- spacesTable[i] = space2
- i = i + 1
- end
- repeat
- repeat
- table[l+1] = spacesTable[k]
- k = k + 1
- until ((spacesTable[k+1] == nil) or (spacesTable[k-1] -spacesTable[k]> paperWidth))
- l = l + 1
- until (spacesTable[k] == nil)
- table[1] = 0
- for i = 1, #table do
- printerTable[i] = string.sub(text,table[i],table[i+1])
- print(printerTable[i],table[i],table[i+1])
- end
- printerTable[#table] = string.sub(text,table[#table],string.len(text))
- return printerTable
- end
- check()
- clearPage()
- if paperWidth*paperHeight<string.len(text) then
- print('This text file won\'t fit on this page!')
- else
- for i, v in ipairs(printerTableFunction()) do
- printer.write(v)
- printer.setCursorPos(1,i+1)
- end
- end
- printer.endPage()
- print(text)
- --print(text)
- --print(paperWidth,paperHeight)
- --print(string.len(text))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement