-
Notifications
You must be signed in to change notification settings - Fork 412
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
Mini RFC: wasm-pack should use progressive enhancement in its output #298
Comments
There was some discussion of this at todays WG meeting. Consensus was that where possible, we should push this into upstream crates, but also generally do wahtever it takes to get the behavior described here at the end of the day. |
I have I have also not written any of this down publicly in a coherent way -- up until now. Well, actually, I don't know if this is going to be coherent. You be the judge of that. (Here are some earlier notes.) What's the status quo?Please bear with me while I describe some very general stuff first. I promise I get to concrete suggestions eventually!
What to do about itI can see the following:
From a "classical" software engineering perspective I'd thus suggest the following:
Quick aside: The most trivial but valuable presenter is probably Writing a terminal output presenterAssuming the data model is trivial (a string) or something you already have, the question quickly becomes: How do you write these presenters. This is a good step in the right direction. I'd try and make this be based on some common traits instead of function that handle stuff. Let's introduce a trait TerminalOutput {
type Handle = ();
fn output(&self, f: &mut TerminalFormatter) -> Result<Self::Handle, TerminalFormatterError>
} In addition to the data in The return type is a result that optionally gives you a handle to the instance of the presenter -- this is how I'd support progress bars and other interactive elements. Using the handle you can for example update the element on screen (or render a new line of output if that's what the formatter does). I'm not entirely sure how to best represent this, and would welcome suggestions here. So far this hinges on "each data format has a different presenter trait", but "human output" is one such trait that then uses conditionals in its implementation to differentiate between environments and do something akin to progressive enhancement. Alternatively, we could split this into two: RawTextOutput and HumanTerminalOutput. I think this will yield a worse developer experience and introduce a maintenance burden because often you want to keep these two outputs in sync. Nested renderingOne more aspect of this I'd like share is the idea to nest rendering components: Instead of having an This would drastically reduce the need to think about what the current output supports and allows for progressive enhancement to be dealt with in a few code components. This is similar to what @fitzgen's proposed "terminal module" does. LoggingLogging with the usual macros will need to be wrapped in a way so we can dynamically dispatch calls to the appropriate presenters. Same as above, JSON will be quite trivial (and I believe slog-json already supports Serializable types), but terminal output will need to use nested rendering or another form of composition, as well as have a good default adapter for external crates that use the regular "just write a string" way of logging. Actually designing that
|
Started some implementation work at https://github.com/killercup/output-rs. Very much WIP and subject to rapid change. |
I wanted to try to kick the tires on this again recently, and it looks like changes to fix smaller bugs are starting to be blocked on this sort of larger scale revamp of the output. I wanted to jot down some notes that I've personally noticed, as well as an idea of how to make progress. Some sample output I just saw from
Some notes I'd have on this output are:
My personal opinion on what should be done to solve these issues is:
Overall what I'd like to see is something like the following for a first run:
wasm-pack's primary output here is indicating that tools are being downloaded
No extra informational messages are printed to the terminal, and it's largely Some known problems with this strategy I can think of are:
I think these issues are far more minor than the ones above, though, and are I'm curious what others think about this though! If there's general consensus I'm fine signing myself up for implementing all this. |
This is a great write up, thanks @alexcrichton! I would like to add that I think we should also be doing a better job of testing output than we are right now. We do a pretty good job of testing functionality, but have basically zero tests for output that we emit. We do have #18 on file to start doing this sort of thing, but it looks like that crate has been deprecated since that issue was filed and |
True! I would be more than willing to set up a test harness as well for the output. Fixing all of these associated issues will also be required to write tests, because if you try to write a test today the output will always be empty! |
Just for reference for this issue, I am posting the wasm-pack output on Windows Console (containing many notdef glyphs). The latest Windows Console (and hence Powershell) does not display emoji glyphs - although support is coming soon. |
I believe this has all since been implemented, so closing! |
What version was this fixed in? I just downloaded 0.10.3 and still see no way to remove colour. I did notice that piping it triggers no colour (is this the only way to control it). This is a strange, and as far as I can tell undocumented behaviour. |
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 tostdout
.We should use the
atty
crate and the$TERM
environment variable to determine whetherstdout
is a fully featured terminal. Ifatty::is(atty::Stream::Stdout)
is true and the$TERM
environment variable is not set to"dumb"
, thenwasm-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 someformat!
ed string messages used to construct someError
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.Related Issues
References
The text was updated successfully, but these errors were encountered: