Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local cmp = require("component")
- local fs = require("filesystem")
- local shell = require("shell")
- local args = shell.parse(...)
- local printer = cmp.openprinter
- local paddr = printer.address
- local printLines = {}
- function splitAdd(ln)
- local line
- ln:gsub('(%s*)(%S+)',
- function(spc, word)
- local len = 0
- if line then
- len = printer.charCount(line)
- end
- len = len + #spc + #word
- if not line or len > 29 then
- table.insert(printLines, line)
- line = word
- else
- line = line..spc..word
- end
- end
- )
- table.insert(printLines, line)
- end
- function doPrint()
- printer.setTitle(args[1])
- for i=1, #printLines do
- printer.writeln(printLines[i])
- end
- printer.print()
- end
- if #args < 2 then
- print("Usage: fileprinter [title] [filepath]")
- else
- if not fs.exists(args[2]) then
- print("File not found: "..args[2])
- else
- local file = io.open(args[2], "r")
- for line in file:lines() do
- --ln = line:gsub("(?:§[0-9a-fk-or])+","")
- if printer.charCount(line) > 29 then
- splitAdd(line)
- else
- table.insert(printLines, line)
- end
- end
- doPrint()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement