Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix empty output regression #2198

Merged
merged 2 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading