diff --git a/Cargo.lock b/Cargo.lock index ba677e2c88..b772ab33aa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -328,9 +328,9 @@ dependencies = [ [[package]] name = "clap-cargo" -version = "0.18.2" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9c7f07f2b3c9fc1a21da5b4fa268083ac4d4d145a711b286055fdd70d149fcf" +checksum = "936551935c8258754bb8216aec040957d261f977303754b9bf1a213518388006" dependencies = [ "anstyle", "clap", @@ -653,7 +653,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] @@ -1471,7 +1471,7 @@ version = "0.50.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5" dependencies = [ - "windows-sys 0.61.2", + "windows-sys 0.59.0", ] [[package]] @@ -2061,7 +2061,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys", - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] @@ -2533,7 +2533,7 @@ dependencies = [ "getrandom 0.3.4", "once_cell", "rustix", - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] @@ -3206,7 +3206,7 @@ version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" dependencies = [ - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index d2dfbdc8c4..8d3e0e0d1c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,7 +47,7 @@ anyhow = "1.0.69" cfg-if = "1.0" chrono = { version = "0.4", default-features = false, features = ["std"] } clap = { version = "4", features = ["derive", "wrap_help", "string"] } -clap-cargo = "0.18.2" +clap-cargo = "0.18.3" clap_complete = "4" console = "0.16" curl = { version = "0.4.44", optional = true } diff --git a/src/cli/rustup_mode.rs b/src/cli/rustup_mode.rs index 52008e2197..111b3cdd74 100644 --- a/src/cli/rustup_mode.rs +++ b/src/cli/rustup_mode.rs @@ -11,9 +11,9 @@ use std::{ }; use anstream::ColorChoice; -use anstyle::Style; use anyhow::{Context, Error, Result, anyhow}; use clap::{Args, CommandFactory, Parser, Subcommand, ValueEnum, builder::PossibleValue}; +use clap_cargo::style::{CONTEXT, HEADER}; use clap_complete::Shell; use console::style; use futures_util::stream::StreamExt; @@ -1081,15 +1081,13 @@ async fn which( async fn show(cfg: &Cfg<'_>, verbose: bool) -> Result { common::warn_if_host_is_emulated(cfg.process); - let bold = Style::new().bold(); - // Print host triple { let t = cfg.process.stdout(); let mut t = t.lock(); writeln!( t, - "{bold}Default host: {bold:#}{}", + "{HEADER}Default host: {HEADER:#}{}", cfg.get_default_host_triple()? )?; } @@ -1100,7 +1098,7 @@ async fn show(cfg: &Cfg<'_>, verbose: bool) -> Result { let mut t = t.lock(); writeln!( t, - "{bold}rustup home: {bold:#}{}", + "{HEADER}rustup home: {HEADER:#}{}", cfg.rustup_dir.display() )?; writeln!(t)?; @@ -1155,7 +1153,7 @@ async fn show(cfg: &Cfg<'_>, verbose: bool) -> Result { (false, false) => "", }; - writeln!(t.lock(), "{toolchain_name}{status_str}")?; + writeln!(t.lock(), "{toolchain_name}{CONTEXT}{status_str}{CONTEXT:#}")?; if verbose { let toolchain = Toolchain::new(cfg, toolchain_name.into())?; @@ -1208,11 +1206,10 @@ async fn show(cfg: &Cfg<'_>, verbose: bool) -> Result { } fn print_header(t: &mut ColorableTerminal, text: &str) -> Result<(), Error> { - let bold = Style::new().bold(); let divider = "-".repeat(text.len()); let mut term_lock = t.lock(); - writeln!(term_lock, "{bold}{text}{bold:#}")?; - writeln!(term_lock, "{bold}{divider}{bold:#}")?; + writeln!(term_lock, "{HEADER}{text}{HEADER:#}")?; + writeln!(term_lock, "{HEADER}{divider}{HEADER:#}")?; Ok(()) } diff --git a/src/process/terminal_source.rs b/src/process/terminal_source.rs index 3e91e65252..abdf050aef 100644 --- a/src/process/terminal_source.rs +++ b/src/process/terminal_source.rs @@ -59,7 +59,11 @@ impl ColorableTerminal { StreamSelector::Stdout => TerminalInner::Stdout(AutoStream::new(io::stdout(), choice)), StreamSelector::Stderr => TerminalInner::Stderr(AutoStream::new(io::stderr(), choice)), #[cfg(feature = "test")] - StreamSelector::TestWriter(w) => TerminalInner::TestWriter(w), + StreamSelector::TestWriter(w) if choice == ColorChoice::Always => { + TerminalInner::StyledTestWriter(w) + } + #[cfg(feature = "test")] + StreamSelector::TestWriter(w) => TerminalInner::TestWriter(StripStream::new(w)), }; let width = process .var("RUSTUP_TERM_WIDTH") @@ -84,9 +88,13 @@ impl ColorableTerminal { self.color_choice, )), #[cfg(feature = "test")] - TerminalInner::TestWriter(w) => { - ColorableTerminalLocked::TestWriter(StripStream::new(Box::new(w.clone()))) + TerminalInner::StyledTestWriter(w) => { + ColorableTerminalLocked::StyledTestWriter(Box::new(w.clone())) } + #[cfg(feature = "test")] + TerminalInner::TestWriter(w) => ColorableTerminalLocked::TestWriter(StripStream::new( + Box::new(w.as_inner().clone()), + )), } } @@ -189,6 +197,8 @@ pub enum ColorableTerminalLocked { Stdout(AutoStream>), Stderr(AutoStream>), #[cfg(feature = "test")] + StyledTestWriter(Box), + #[cfg(feature = "test")] TestWriter(StripStream>), } @@ -198,6 +208,8 @@ impl ColorableTerminalLocked { Self::Stdout(s) => s, Self::Stderr(s) => s, #[cfg(feature = "test")] + Self::StyledTestWriter(w) => w, + #[cfg(feature = "test")] Self::TestWriter(w) => w, } } @@ -230,7 +242,9 @@ enum TerminalInner { Stdout(AutoStream), Stderr(AutoStream), #[cfg(feature = "test")] - TestWriter(TestWriter), + StyledTestWriter(TestWriter), + #[cfg(feature = "test")] + TestWriter(StripStream), } /// Select what stream to make a terminal on diff --git a/tests/suite/cli_rustup_ui.rs b/tests/suite/cli_rustup_ui.rs index b48971939f..9a5c832931 100644 --- a/tests/suite/cli_rustup_ui.rs +++ b/tests/suite/cli_rustup_ui.rs @@ -1,6 +1,7 @@ use std::fs::create_dir_all; use std::path::Path; +use rustup::test::{CliTestContext, Scenario}; use snapbox::Data; use snapbox::cmd::{Command, cargo_bin}; @@ -240,6 +241,26 @@ fn rustup_set_cmd_profile_cmd_help_flag() { ); } +#[tokio::test] +async fn rustup_show_toolchain() { + let name = "rustup_show_toolchain"; + let cx = CliTestContext::new(Scenario::SimpleV2).await; + cx.config + .expect(["rustup", "default", "nightly"]) + .await + .is_ok(); + cx.config + .expect_with_env(["rustup", "show"], [("RUSTUP_TERM_COLOR", "always")]) + .await + .extend_redactions([("[RUSTUP_DIR]", &cx.config.rustupdir.to_string())]) + .with_stdout(Data::read_from( + Path::new(&format!("tests/suite/cli_rustup_ui/{name}.stdout.term.svg")), + None, + )) + .with_stderr("") + .is_ok(); +} + #[test] fn rustup_show_cmd_help_flag() { test_help("rustup_show_cmd_help_flag", &["show", "--help"]); diff --git a/tests/suite/cli_rustup_ui/rustup_show_toolchain.stdout.term.svg b/tests/suite/cli_rustup_ui/rustup_show_toolchain.stdout.term.svg new file mode 100644 index 0000000000..1dda66273f --- /dev/null +++ b/tests/suite/cli_rustup_ui/rustup_show_toolchain.stdout.term.svg @@ -0,0 +1,52 @@ + + + + + + + Default host: [HOST_TRIPLE] + + rustup home: [RUSTUP_DIR] + + + + installed toolchains + + -------------------- + + nightly-[HOST_TRIPLE] (active, default) + + + + active toolchain + + ---------------- + + name: nightly-[HOST_TRIPLE] + + active because: it's the default toolchain + + installed targets: + + [HOST_TRIPLE] + + + + + +