Skip to content

Commit

Permalink
Merge pull request sile-typesetter#2198 from alerque/empty-not-error
Browse files Browse the repository at this point in the history
Fix empty output regression
  • Loading branch information
alerque authored Dec 13, 2024
2 parents d737b26 + 5a7694d commit ed6a745
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 6 deletions.
2 changes: 1 addition & 1 deletion core/utilities/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ function utilities.error (message, isbug)
utilities.warn(message, isbug)
_skip_traceback_levels = 2
io.stderr:flush()
SILE.outputter:finish()
SILE.outputter:abort()
SILE.scratch.caughterror = true
error("", 2)
end
Expand Down
4 changes: 4 additions & 0 deletions outputters/base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ end

function outputter.newPage () end

function outputter:abort ()
return self:finish() -- unless otherwise defined
end

function outputter:finish ()
self:runHooks("prefinish")
end
Expand Down
9 changes: 9 additions & 0 deletions outputters/debug.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ function outputter:newPage ()
self:_writeline("New page")
end

function outputter:abort ()
if started then
self:_writeline("Aborted")
outfile:close()
started = false
end
end

function outputter:finish ()
if SILE.status.unsupported then
self:_writeline("UNSUPPORTED")
Expand All @@ -54,6 +62,7 @@ function outputter:finish ()
self:runHooks("prefinish")
self:_writeline("Finish")
outfile:close()
started = false
end

function outputter.getCursor (_)
Expand Down
15 changes: 12 additions & 3 deletions outputters/libtexpdf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,25 @@ end
-- pdf structure package needs a tie in here
function outputter._endHook (_) end

function outputter:finish ()
function outputter.abort ()
if started then
pdf.endpage()
self:runHooks("prefinish")
pdf.finish()
started = false
lastkey = nil
lastkey = false
end
end

function outputter:finish ()
-- allows generation of empty PDFs
self:_ensureInit()
pdf.endpage()
self:runHooks("prefinish")
pdf.finish()
started = false
lastkey = false
end

function outputter.getCursor (_)
return cursorX, cursorY
end
Expand Down
11 changes: 9 additions & 2 deletions outputters/text.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ outputter.extension = "txt"
-- function outputter:_init () end

function outputter:_ensureInit ()
if not outfile then
if not started then
started = true
local fname = self:getOutputFilename()
outfile = fname == "-" and io.stdout or io.open(fname, "w+")
end
Expand All @@ -34,10 +35,17 @@ function outputter:newPage ()
outfile:write(" ")
end

function outputter.abort ()
if started then
outfile:close()
started = false
end
end
function outputter:finish ()
self:_ensureInit()
self:runHooks("prefinish")
outfile:close()
started = false
end

function outputter.getCursor (_)
Expand Down Expand Up @@ -79,7 +87,6 @@ function outputter:drawHbox (value, width)
end
self:_writeline(value.text)
if width > 0 then
started = true
cursorX = cursorX + width
end
end
Expand Down

0 comments on commit ed6a745

Please sign in to comment.