Skip to content

Commit

Permalink
XTS: Better output message
Browse files Browse the repository at this point in the history
  • Loading branch information
pgundlach committed Jan 19, 2024
1 parent 2ad65a3 commit 3dabc5b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
10 changes: 10 additions & 0 deletions core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ func (xd *xtsDocument) setupPage() {
}
}

// PublishingInfo contains information about a previous publishing run.
type PublishingInfo struct {
Pages int
FileSize int64
}

// XTSConfig is the configuration file for PDF generation.
type XTSConfig struct {
Datafile io.Reader
Expand All @@ -186,6 +192,7 @@ type XTSConfig struct {
SuppressInfo bool
Tracing []string
Variables map[string]any
Info PublishingInfo
}

// RunXTS is the entry point
Expand Down Expand Up @@ -320,6 +327,9 @@ func RunXTS(cfg *XTSConfig) error {
if err = d.writeAuxXML(); err != nil {
return err
}
d.cfg.Info.Pages = d.currentPagenumber
d.cfg.Info.FileSize = d.document.Doc.PDFWriter.Size()

return nil
}

Expand Down
1 change: 1 addition & 0 deletions core/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func clearPage(xd *xtsDocument) {
xd.currentPage = nil
}

// newPage returns the new page object, the AtPageCreation function and an error.
func newPage(xd *xtsDocument) (*page, func(), error) {
slog.Debug("New page")
xd.currentPagenumber++
Expand Down
15 changes: 13 additions & 2 deletions xts/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ type config struct {
VariablesMap map[string]any `mapstructure:"-" toml:"variables"`
}

// pluralize returns n and the text and "s" if n != 1
func pluralize(n int, text string) string {
if n == 1 {
return "1 " + text
}
return fmt.Sprintf("%d %ss", n, text)
}

func listFonts() error {
ff := core.FindFontFiles()
ret := make([]string, len(ff))
Expand Down Expand Up @@ -334,6 +342,7 @@ func dothings() error {
if err != nil {
return err
}
var info core.PublishingInfo
switch cmd {
case "clean":
jobname := configuration.Jobname
Expand Down Expand Up @@ -463,7 +472,9 @@ func dothings() error {
xc.DumpFile = w

}
if err = core.RunXTS(xc); err != nil {
err = core.RunXTS(xc)
info = xc.Info
if err != nil {
goto finished
}
}
Expand All @@ -480,7 +491,7 @@ func dothings() error {
finished:
dur := time.Now().Sub(starttime)
slog.Info(fmt.Sprintf("Finished in %s", dur))
fmt.Printf("Finished with %d error(s) and %d warning(s) in %s.\nOutput written to %s\n and protocol file to %s.\n", errCount, warnCount, dur, configuration.Jobname+".pdf", protocolFilename)
fmt.Printf("Finished with %s and %s in %s.\nOutput written to %s (%s, %d bytes)\n and protocol file to %s.\n", pluralize(errCount, "error"), pluralize(warnCount, "warning"), dur, configuration.Jobname+".pdf", pluralize(info.Pages, "page"), info.FileSize, protocolFilename)
if errCount > 0 {
return core.TypesettingError{Logged: true}
}
Expand Down

0 comments on commit 3dabc5b

Please sign in to comment.