It's nice to have Cargo's native progress bars when building. To achieve this I used a slightly different approach to the current one: firstpage
will detect if a Cargo subcommand is being used that supports the option --message-format=json-diagnostic-rendered-ansi
. If not, it will simply run the inner command unchanged, but if so, it will pass that option in.
The Cargo subcommand will then output diagnostic JSON to stdout and its UI stuff (like green "Compiling" messages and the progress bar) to stderr. Only stdout will be piped, and firstpage
can then process this JSON and to display it once it has been line-wrapped and limited in vertical size.
I had all the diagnostics be emitted after Cargo finished its compilation fully (instead of during) which is a slight change in behaviour, but there isn't really another option since printing it out as it comes in results in the two processes racing to stdout and message tearing. It's also arguably more useful because the message "could not compile {crate name}
due to N previous errors" will be actually visible instead of cut off at the bottom.
I added a help menu also. Mostly because I needed something to do if cargo firstpage
was run without arguments, since I can no longer rely on Cargo to cause the error itself.