Skip to content

Commit 9ebdb25

Browse files
committed
fix(check): Use Cargo's colors
With `rustup check`s colors being testable (#4561), this updates it to match Cargo's colors
1 parent 82884ce commit 9ebdb25

File tree

3 files changed

+14
-25
lines changed

3 files changed

+14
-25
lines changed

src/cli/rustup_mode.rs

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ use std::{
1111
};
1212

1313
use anstream::ColorChoice;
14-
use anstyle::{AnsiColor, Style};
14+
use anstyle::Style;
1515
use anyhow::{Context, Error, Result, anyhow};
1616
use clap::{Args, CommandFactory, Parser, Subcommand, ValueEnum, builder::PossibleValue};
17-
use clap_cargo::style::{CONTEXT, HEADER};
17+
use clap_cargo::style::{CONTEXT, ERROR, GOOD, HEADER, WARN};
1818
use clap_complete::Shell;
1919
use futures_util::stream::StreamExt;
2020
use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
@@ -825,23 +825,11 @@ async fn check_updates(cfg: &Cfg<'_>, opts: CheckOpts) -> Result<ExitCode> {
825825
Style::new()
826826
};
827827

828-
let error = if use_colors {
829-
AnsiColor::Red.on_default().bold()
830-
} else {
831-
Style::new()
832-
};
828+
let error = if use_colors { ERROR } else { Style::new() };
833829

834-
let good = if use_colors {
835-
AnsiColor::Green.on_default().bold()
836-
} else {
837-
Style::new()
838-
};
830+
let good = if use_colors { GOOD } else { Style::new() };
839831

840-
let warn = if use_colors {
841-
AnsiColor::Yellow.on_default().bold()
842-
} else {
843-
Style::new()
844-
};
832+
let warn = if use_colors { WARN } else { Style::new() };
845833

846834
// Ensure that `.buffered()` is never called with 0 as this will cause a hang.
847835
// See: https://github.com/rust-lang/futures-rs/pull/1194#discussion_r209501774
@@ -852,7 +840,7 @@ async fn check_updates(cfg: &Cfg<'_>, opts: CheckOpts) -> Result<ExitCode> {
852840
let channels = tokio_stream::iter(channels.into_iter()).map(|(name, distributable)| {
853841
let msg = format!("{bold}{name} - {bold:#}");
854842
let status = "Checking...";
855-
let template = format!("{{msg}}{status} {{spinner:.green}}");
843+
let template = format!("{{msg}}{status} {good}{{spinner}}{good:#}");
856844
let pb = multi_progress_bars.add(ProgressBar::new(1));
857845
pb.set_style(
858846
ProgressStyle::with_template(template.as_str())

src/cli/self_update.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,12 @@ use std::process::Command;
4040
use std::str::FromStr;
4141
use std::{fmt, fs};
4242

43-
use anstyle::{AnsiColor, Style};
43+
use anstyle::Style;
4444
use anyhow::{Context, Result, anyhow};
4545
use cfg_if::cfg_if;
4646
use clap::ValueEnum;
4747
use clap::builder::PossibleValue;
48+
use clap_cargo::style::{GOOD, WARN};
4849
use itertools::Itertools;
4950
use same_file::Handle;
5051
use serde::{Deserialize, Serialize};
@@ -1373,8 +1374,8 @@ pub(crate) async fn check_rustup_update(dl_cfg: &DownloadCfg<'_>) -> Result<bool
13731374
let available_version = get_available_rustup_version(dl_cfg).await?;
13741375

13751376
let bold = Style::new().bold();
1376-
let yellow = AnsiColor::Yellow.on_default().bold();
1377-
let green = AnsiColor::Green.on_default().bold();
1377+
let yellow = WARN;
1378+
let green = GOOD;
13781379

13791380
write!(t, "{bold}rustup - {bold:#}")?;
13801381

tests/suite/cli_rustup_ui/rustup_check_updates_none.stdout.term.svg

Lines changed: 4 additions & 4 deletions
Loading

0 commit comments

Comments
 (0)