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 | ||
7 | function check() | |
8 | assert(printer.newPage(),'please insert some paper!') | |
9 | paperWidth, paperHeight = printer.getPageSize() | |
10 | end | |
11 | ||
12 | function printerTable(text,paperWidth) | |
13 | table = {} | |
14 | i = 1 | |
15 | local space1 = 0 | |
16 | local space2 = 0 | |
17 | local lowerSpace = 0 | |
18 | local printerTable = {} | |
19 | while (space1 ~= nil) and (space2 ~= nil) do | |
20 | while (space2 ~= nil) and (space1 ~= nil) and (space1 < i*paperWidth) and (space2 < i*paperWidth) do | |
21 | space1 = string.find(text,' ', space2+1) | |
22 | space2 = string.find(text,' ', space1+1) | |
23 | if (space1 ~= nil) and (space2 ~= nil) then | |
24 | lowerSpace = math.min(space1,space2) | |
25 | elseif space1 ~= nil then | |
26 | lowerSpace = space1 | |
27 | else | |
28 | lowerSpace = space2 | |
29 | end | |
30 | end | |
31 | table[1] = 0 | |
32 | table[i+1] = lowerSpace | |
33 | i = i+1 | |
34 | print(#table) | |
35 | end | |
36 | for i = 1, #table-1 do | |
37 | printerTable[i] = string.sub(text,table[i],table[i+1]-1) | |
38 | return printerTable | |
39 | end | |
40 | end | |
41 | ||
42 | check() | |
43 | ||
44 | if paperWidth*paperHeight<string.len(text) then | |
45 | print('This text file won\'t fit on this page!') | |
46 | else | |
47 | print(#printerTable(text,paperWidth)) | |
48 | for i, v in ipairs(printerTable(text,paperWidth)) do | |
49 | print(v) | |
50 | printer.write(v) | |
51 | printer.setCursorPos(i+1,i) | |
52 | end | |
53 | end | |
54 | ||
55 | printer.endPage() | |
56 | print(text) | |
57 | print(paperWidth,paperHeight) | |
58 | print(string.len(text)) |