diff --git a/src/cli/rustup_mode.rs b/src/cli/rustup_mode.rs index bb91e4c0a4..985809157b 100644 --- a/src/cli/rustup_mode.rs +++ b/src/cli/rustup_mode.rs @@ -11,10 +11,10 @@ use std::{ }; use anstream::ColorChoice; -use anstyle::{AnsiColor, Style}; +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_cargo::style::{CONTEXT, ERROR, GOOD, HEADER, TRANSIENT, WARN}; use clap_complete::Shell; use futures_util::stream::StreamExt; use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; @@ -825,23 +825,13 @@ async fn check_updates(cfg: &Cfg<'_>, opts: CheckOpts) -> Result { Style::new() }; - let error = if use_colors { - AnsiColor::Red.on_default().bold() - } else { - Style::new() - }; + let transient = if use_colors { TRANSIENT } else { Style::new() }; - let good = if use_colors { - AnsiColor::Green.on_default().bold() - } else { - Style::new() - }; + let error = if use_colors { ERROR } else { Style::new() }; - let warn = if use_colors { - AnsiColor::Yellow.on_default().bold() - } else { - Style::new() - }; + let good = if use_colors { GOOD } else { Style::new() }; + + let warn = if use_colors { WARN } else { Style::new() }; // Ensure that `.buffered()` is never called with 0 as this will cause a hang. // See: https://github.com/rust-lang/futures-rs/pull/1194#discussion_r209501774 @@ -850,13 +840,18 @@ async fn check_updates(cfg: &Cfg<'_>, opts: CheckOpts) -> Result { MultiProgress::with_draw_target(cfg.process.progress_draw_target()); let semaphore = Arc::new(Semaphore::new(concurrent_downloads)); let channels = tokio_stream::iter(channels.into_iter()).map(|(name, distributable)| { + let msg = format!("{bold}{name} - {bold:#}"); + let status = "Checking..."; + let template = format!( + "{{msg}}{transient}{status}{transient:#} {transient}{{spinner}}{transient:#}" + ); let pb = multi_progress_bars.add(ProgressBar::new(1)); pb.set_style( - ProgressStyle::with_template("{msg:.bold} - Checking... {spinner:.green}") + ProgressStyle::with_template(template.as_str()) .unwrap() .tick_chars(r"|/-\ "), ); - pb.set_message(format!("{name}")); + pb.set_message(msg.clone()); pb.enable_steady_tick(Duration::from_millis(100)); let sem = semaphore.clone(); @@ -866,30 +861,29 @@ async fn check_updates(cfg: &Cfg<'_>, opts: CheckOpts) -> Result { let dist_version = distributable.show_dist_version().await?; let mut update_a = false; - let styled_name = format!("{bold}{name} - {bold:#}"); - let message = match (current_version, dist_version) { + let template = match (current_version, dist_version) { (None, None) => { - let m = "Cannot identify installed or update versions"; - format!("{styled_name}{error}{m}{error:#}") + let status = "Cannot identify installed or update versions"; + format!("{msg}{error}{status}{error:#}") } (Some(cv), None) => { - let m = "Up to date"; - format!("{styled_name}{good}{m}{good:#} : {cv}") + let status = "Up to date"; + format!("{msg}{good}{status}{good:#} : {cv}") } (Some(cv), Some(dv)) => { - let m = "Update available"; + let status = "Update available"; update_a = true; - format!("{styled_name}{warn}{m}{warn:#} : {cv} -> {dv}") + format!("{msg}{warn}{status}{warn:#} : {cv} -> {dv}") } (None, Some(dv)) => { - let m = "Update available"; + let status = "Update available"; update_a = true; - format!("{styled_name}{warn}{m}{warn:#} : (Unknown version) -> {dv}") + format!("{msg}{warn}{status}{warn:#} : (Unknown version) -> {dv}") } }; - pb.set_style(ProgressStyle::with_template(message.as_str()).unwrap()); + pb.set_style(ProgressStyle::with_template(template.as_str()).unwrap()); pb.finish(); - Ok::<(bool, String), Error>((update_a, message)) + Ok::<(bool, String), Error>((update_a, template)) } }); diff --git a/src/cli/self_update.rs b/src/cli/self_update.rs index ee09c72537..f14a5a7740 100644 --- a/src/cli/self_update.rs +++ b/src/cli/self_update.rs @@ -40,11 +40,12 @@ use std::process::Command; use std::str::FromStr; use std::{fmt, fs}; -use anstyle::{AnsiColor, Style}; +use anstyle::Style; use anyhow::{Context, Result, anyhow}; use cfg_if::cfg_if; use clap::ValueEnum; use clap::builder::PossibleValue; +use clap_cargo::style::{GOOD, WARN}; use itertools::Itertools; use same_file::Handle; use serde::{Deserialize, Serialize}; @@ -1373,8 +1374,8 @@ pub(crate) async fn check_rustup_update(dl_cfg: &DownloadCfg<'_>) -> Result .fg { fill: #AAAAAA } .bg { fill: #000000 } - .fg-green { fill: #00AA00 } + .fg-bright-green { fill: #55FF55 } .container { padding: 0 10px; line-height: 18px; @@ -18,11 +18,11 @@ - stable-[HOST_TRIPLE] - Up to date : 1.1.0 (hash-stable-1.1.0) + stable-[HOST_TRIPLE] - Up to date : 1.1.0 (hash-stable-1.1.0) - beta-[HOST_TRIPLE] - Up to date : 1.2.0 (hash-beta-1.2.0) + beta-[HOST_TRIPLE] - Up to date : 1.2.0 (hash-beta-1.2.0) - nightly-[HOST_TRIPLE] - Up to date : 1.3.0 (hash-nightly-2) + nightly-[HOST_TRIPLE] - Up to date : 1.3.0 (hash-nightly-2)