Forum Samples, Tips and Tricks

(Yet Another?) Progress Metre

revence27
When you are building large stuff, and the build takes a while, you print the current page, and remember the maximum. That way, you know where you are.
I modified that a little bit to show percentages; attached is both the CoffeeScript (which is what I prefer to write) and the JavaScript. It involves a lot of dancing with the quirks of the system.

If console.log didn’t put the new-line automatically, it would be a much better situation, with a real progress tracker, rather than a running print-out of the current completed percentage. I think this is as close as anybody can get to a working progress metre.
Prove me weak!
  1. rhema.coffee0.5 kB
    CoffeeScript
  2. rhema.js0.6 kB
    JavaScript
mikeday
Smart! :)
revence27
Alas, since Prince doesn’t bother printing console.log when running without a TTY, it is impossible to wrap it in a progress-metre script built for the purpose. (I tried.)
I wonder if there is a logging function that either will print without a new-line or print even when !isatty(stdout). With that, I could improve my build experience. :-)

Edited by revence27

mikeday
You could try the (undocumented) --server option, which includes a progress meter. I'm surprised Prince isn't printing to the console though, we pipe Prince output to other programs all the time.
revence27
I guess it is console.log that doesn’t print, while you probably use the Prince.something options. Am I right?
I am looking at --server’s output now. Informative enough, and I may start exploiting it.
trevordevore
@mikeday - the --server options is great. I was able to quickly add progress feedback to my desktop application using it.

For those reading, the output looks like this:

sta|Loading document...
sta|Running scripts...
sta|Applying style sheets...
sta|Preparing document...
sta|Applying style sheets...
sta|Converting document...
prg|0
prg|16
prg|19
prg|22
prg|26
prg|30
...
prg|77
prg|87
prg|91
prg|94
prg|100
fin|success


There may also be an error message present:

msg|err|/layout.html:1|Opening and ending tag mismatch: td line 1 and tr

Trevor DeVore
ScreenSteps
http://www.screensteps.com

Edited by trevordevore

trevordevore
@mikeday - what other messages can we see under "msg|"? I imagine there is one for warnings as well?

Trevor DeVore
ScreenSteps
http://www.screensteps.com

revence27
Because he said “undocumented”, my strategy has been to just force-feed it weird files until it has even told me where its second cousin is buried.
As it stands, there isn’t much other data coming out. But that is nice data
mikeday
Yes you can have msg|err, msg|wrn, msg|inf, and msg|dbg.
trevordevore
Thanks @mikeday.

Trevor DeVore
ScreenSteps
http://www.screensteps.com

revence27
I have incorporated that --server into a small script which will run under Ruby, and provide nice intuitive progress-tracking without throwing away the other output. Since it started here, it should end here. Usage:

prince --server --javascript -s rhema.css --script=rhema.js -o rhema.pdf rhema.html 2>&1 | ruby tracker.rb
  1. tracker.rb1.3 kB
    --server tracker
qbane
I am really interested in the example above. Recently I've been working with some large documents and the progress bar is indeed necessary. Besides the `--server` option, I also tried the script you attached but unfortunately I couldn't make it work. How to use it?

By the way, aside from `complete`, I am also curious if there is any other event for the `Prince` object?
mikeday
Progress messages are now available via a new option in Prince latest builds, --structured-log=progress.

The complete event is the only event currently available on the Prince object.
qbane
Thanks for the quick response!