View difference between Paste ID: MfRkwHMU and h1eNt3MT
SHOW: | | - or go back to the newest paste.
1
term.clear()
2
local arg = {...}
3
printer = peripheral.wrap(arg[1])
4
io.input(arg[2])
5
text = io.read('*all')
6
function check()
7
    if printer.newPage() == false then
8
        term.clear()
9
        term.setCursorPos(1,1) 
10
        io.write('Please insert some paper!')
11
    else paperWidth, paperHeight = printer.getPageSize()
12
    end
13
end
14
15
local function printerTable(text,paperWidth)
16
    local table = {}
17
    local i = 1
18
    local space1 = 0
19
    local space2 = 0
20
    local lowerSpace = 0
21
    local printerTable = {}
22
    while (space1 ~= nil) and (space2 ~= nil) do
23
        while (space2 ~= nil) and (space1 ~= nil) and (space1 < i*paperWidth) and (space2 < i*paperWidth) do
24
            space1 = string.find(text,' ', space2+1)    
25
            space2 = string.find(text,' ', space1+1)
26
            if (space1 ~= nil) and (space2 ~= nil) then
27
                lowerSpace = math.min(space1,space2)
28
            elseif space1 ~= nil then
29
                lowerSpace = space1
30
            else
31
                lowerSpace = space2
32
            end
33
            print(space1,space2,lowerSpace)    
34
        end
35
        table[i] = lowerSpace
36
        i = i+1
37
    end
38
    for i = 1, #table do
39
        printerTable[i] = string.sub(text,table[i],table[i+1]-1) 
40
        return printerTable
41
    end
42
end
43
check()
44
if paperWidth*paperHeight<string.len(text) then
45
    print('This text file won\'t fit on this page!')
46
else
47
    for i, v in ipairs(printerTable(text,paperWidth)) do
48
        print(v)
49
        printer.write(v)
50
        printer.setCursorPos(i+1,i)
51
    end
52
end
53
54
printer.endPage()
55
print(text)
56
print(paperWidth,paperHeight)
57
print(string.len(text))