Description
Summary
wasm-pack
should default to plain text output and use progressive enhancement to add bells and whistles such as colors, bold, and progress bars when the functionality is available.
Motivation
wasm-pack
should work seamlessly with all terminals on all platforms, and when its output is piped to another process or a log file. Users should never see garbled characters or color codes.
Details
By default, wasm-pack
should emit only plain text output to stdout
.
We should use the atty
crate and the $TERM
environment variable to determine whether stdout
is a fully featured terminal. If atty::is(atty::Stream::Stdout)
is true and the $TERM
environment variable is not set to "dumb"
, then wasm-pack
should also emit colors, bold styles, and show progress bars when it makes sense.
To enforce consistency with these rules across the code base, there should be one central place that manages whether colors are printed or progress bars are displayed. All other code should be able to assume that the colors are used and progress bars are displayed, and be none the wiser if that is not actually the case under the covers. Luckily, we already have most of the printing logic isolated into the progressbar
module. The exception is some format!
ed string messages used to construct some Error
instances.
To move forward, we should create a new terminal
module that encapsulates all terminal output, progressive enhancement, and feature detection.
-
For styling text, we should refactor all existing usage of
style(...).bold().dim()
etc to use our ownterminal
utility function(s) that only apply thestyle(...)
when the terminal supports it. -
For progress bars, we should have a utility in
terminal
that creates the progress bars for the caller. Ifstdout
is not a tty or$TERM
is"dumb"
, then it should return a progress bar created withindicatif::ProgressBar::hidden
, which is a no-op progress bar.