Skip to content

Commit

Permalink
chore(cli): Use LUA STDIO instead of hijacking filenames and assuming…
Browse files Browse the repository at this point in the history
… UNIX dev nodes
  • Loading branch information
alerque committed Jul 1, 2022
1 parent 9879657 commit 560b991
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 7 deletions.
4 changes: 2 additions & 2 deletions core/cli.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ cli.parseArguments = function ()
end
if opts.INPUT then
if opts.INPUT == "STDIO" then
opts.INPUT = "/dev/stdin"
opts.INPUT = "-"
end
-- Turn slashes around in the event we get passed a path from a Windows shell
SILE.inputFile = opts.INPUT:gsub("\\", "/")
Expand Down Expand Up @@ -71,7 +71,7 @@ cli.parseArguments = function ()
end
if opts.output then
if opts.output == "STDIO" then
opts.output = "/dev/stdout"
opts.output = "-"
end
SILE.outputFilename = opts.output
end
Expand Down
3 changes: 2 additions & 1 deletion outputters/cairo.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ local cairo = pl.class(base)
cairo._name = "cairo"

function cairo:_init ()
local surface = cairolgi.PdfSurface.create(self:getOutputFilename("pdf"), SILE.documentState.paperSize[1], SILE.documentState.paperSize[2])
local fname = self:getOutputFilename("pdf")
local surface = cairolgi.PdfSurface.create(fname == "-" and "/dev/stdout" or fname, SILE.documentState.paperSize[1], SILE.documentState.paperSize[2])
cr = cairolgi.Context.create(surface)
move = cr.move_to
sgs = cr.show_glyph_string
Expand Down
3 changes: 2 additions & 1 deletion outputters/debug.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ debug._name = "debug"
function debug:_ensureInit ()
if not started then
started = true -- keep this before self:_writeline or it will be a race condition!
outfile = io.open(self:getOutputFilename("debug"), "w+")
local fname = self:getOutputFilename("debug")
outfile = fname == "-" and io.stdout or io.open(fname, "w+")
self:_writeline("Set paper size ", SILE.documentState.paperSize[1], SILE.documentState.paperSize[2])
self:_writeline("Begin page")
end
Expand Down
3 changes: 2 additions & 1 deletion outputters/libtexpdf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ libtexpdf._name = "libtexpdf"
function libtexpdf:_ensureInit ()
if not started then
local w, h = SILE.documentState.paperSize[1], SILE.documentState.paperSize[2]
pdf.init(self:getOutputFilename("pdf"), w, h, SILE.full_version)
local fname = self:getOutputFilename("pdf")
pdf.init(fname == "-" and "/dev/stdout" or fname, w, h, SILE.full_version)
pdf.beginpage()
started = true
end
Expand Down
3 changes: 2 additions & 1 deletion outputters/podofo.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ end

function podofo:finish ()
painter:FinishPage()
document:Write(self:getOutputFilename("pdf"))
local fname = self:getOutputFilename("pdf")
document:Write(fname == "-" and "/dev/stdout" or fname)
end

function podofo.getCursor (_)
Expand Down
3 changes: 2 additions & 1 deletion outputters/text.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ text._name = "text"

function text:_ensureInit ()
if not outfile then
outfile = io.open(self:getOutputFilename("txt"), "w+")
local fname = self:getOutputFilename("text")
outfile = fname == "-" and io.stdout or io.open(fname, "w+")
end
end

Expand Down

0 comments on commit 560b991

Please sign in to comment.