72 lines
1.5 KiB
Lua
72 lines
1.5 KiB
Lua
local component = require "component"
|
|
local printer = component.openprinter
|
|
local tA = {...}
|
|
|
|
local debug = tA[2]
|
|
|
|
local lc, title = 1
|
|
|
|
local function writeln(...)
|
|
if debug then return end
|
|
return printer.writeln(...)
|
|
end
|
|
local function printpg()
|
|
if debug then return end
|
|
local rv = {printer.print()}
|
|
printer.setTitle(title)
|
|
return table.unpack(rv)
|
|
end
|
|
|
|
local f = io.open(tA[1], "rb")
|
|
printer.clear()
|
|
local mw = printer.maxWidth()
|
|
for line in f:lines() do
|
|
local centre = nil
|
|
line=line:gsub("^##","§n")
|
|
line=line:gsub("^#","§l§n")
|
|
line=line:gsub("%*(.-)%*","§o%1§r")
|
|
line=line:gsub("$DATE",os.date("%Y-%m-%d"))
|
|
if line:sub(1,1) == "&" then
|
|
title = line:sub(2)
|
|
if lc > 1 then
|
|
print(printpg())
|
|
lc = 1
|
|
end
|
|
printer.setTitle(title)
|
|
line = ""
|
|
end
|
|
while #line > 0 do
|
|
local lb = 1
|
|
repeat
|
|
lb = lb + 1
|
|
until printer.width(line:sub(1,lb)) >= mw or lb >= #line
|
|
local ws,we = line:sub(1,lb):find("%s+(%S+)$")
|
|
if ws and we and printer.width(line:sub(1,lb)) >= mw then
|
|
local sw = line:match("%S+",ws)
|
|
for i = 1, ws-1 do
|
|
io.write(" ")
|
|
end
|
|
print("v",ws, lb, lb-ws, sw:len(),sw)
|
|
if lb - ws < 6 then
|
|
lb = ws
|
|
else
|
|
repeat
|
|
lb = lb - 1
|
|
until printer.width(line:sub(1,lb+2) .. "-") < mw
|
|
line = line:sub(1,lb) .. "-" .. line:sub(lb+1)
|
|
lb = lb + 1
|
|
end
|
|
end
|
|
writeln(line:sub(1,lb), nil, centre)
|
|
print(line:sub(1,lb))
|
|
line = line:sub(lb+1):gsub("^%s+","")
|
|
lc = lc + 1
|
|
if lc > 20 then
|
|
print(printpg())
|
|
lc = 1
|
|
end
|
|
end
|
|
end
|
|
print(printpg())
|
|
f:close()
|