Skip to content

Conversation

epage
Copy link
Contributor

@epage epage commented Oct 8, 2025

anstream is an existing dependency through clap that allows a simpler, more natural way of writing styled text by making ANSI escape codes the API for styling, rather than a stream.set_color(_). You write ANSI escape codes unconditionally, and anstream will automatically strip them if needed (or convert them to wincon API calls for old Windows 8 systems). The caller can use whatever styling API they want and don't have to worry about what stream type they are ultimately written to.

This will unblock clap output being styled. Clap can either directly handle writing output to the terminal, write unstyled output to a string, or write styled output to a string. With Rustup requiring all output to go through custom, termcolor-like streams for testing, this limited Rustup to only getting unstyled output. With this change, Rustup can get Clap's styled output and then have anstream process it as needed.

To generate ANSI escape codes, this uses anstyle which is primarily intended to be a low-policy API for ANSI escape codes so they are API stable for theming in APIs like clap or annotate-snippets. Using the formatting alternate though provides a nice way to reset the stream.

To simplify the transition for callers of ColorableTerminal through this transition, intermediate steps are taken, including adding the anstyle-termcolor adapter and then removing it.

I manually tested what I could of Rustup's output to spot check the styling. Cargo uses snapbox (the core of trycmd) to perform snapshot testing of ANSI escape codes by rendering them as SVGs which get rendered in GitHub diffs. Rustc integrated the lower level anstyle-svg package into their existing snapshotting system. I have considered SVG support for trycmd but haven't implemented it yet.

@epage
Copy link
Contributor Author

epage commented Oct 8, 2025

---- suite::cli_self_upd::as_rustup_setup stdout ----
ran: rustup ["set", "default-host", "aarch64-unknown-linux-gnu"]
inprocess: true
status: Some(0)
duration: 0.014s
stdout:
====

====

stderr:
====

====

ran: rustup ["set", "auto-self-update", "disable"]
inprocess: true
status: Some(0)
duration: 0.006s
stdout:
====

====

stderr:
====
info: auto-self-update mode set to 'disable'

====


thread 'suite::cli_self_upd::as_rustup_setup' panicked at /checkout/src/test/clitools.rs:373:18:
Unable to run test command: Os { code: 26, kind: ExecutableFileBusy, message: "Text file busy" }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


failures:
    suite::cli_self_upd::as_rustup_setup

Not all jobs saw this failure and I can't reproduce this locally. Anyone have insight into this?

@rami3l
Copy link
Member

rami3l commented Oct 9, 2025

Not all jobs saw this failure and I can't reproduce this locally. Anyone have insight into this?

@epage This looks like someone lingering problem from the past (before my joining the team). Is that frequent?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants