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')
- function check()
- if printer.newPage() == false then
- term.clear()
- term.setCursorPos(1,1)
- io.write('Please insert some paper!')
- else paperWidth, paperHeight = printer.getPageSize()
- end
- end
- local function printerTable(text,paperWidth)
- local table = {}
- local 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
- print(space1,space2,lowerSpace)
- end
- table[i] = lowerSpace
- i = i+1
- end
- for i = 1, #table 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
- 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))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement