Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 25 additions & 31 deletions src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -825,23 +825,13 @@ async fn check_updates(cfg: &Cfg<'_>, opts: CheckOpts) -> Result<ExitCode> {
Style::new()
};

let error = if use_colors {
AnsiColor::Red.on_default().bold()
} else {
Style::new()
};
let transient = if use_colors { TRANSIENT } else { Style::new() };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest doing it more like this:

let (transient, error, good, warn) = match use_colors {
     true => (TRANSIENT, ERROR, GOOD, WARN),
     false => (Style::new(), Style::new(), Style::new(), 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
Expand All @@ -850,13 +840,18 @@ async fn check_updates(cfg: &Cfg<'_>, opts: CheckOpts) -> Result<ExitCode> {
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();
Expand All @@ -866,30 +861,29 @@ async fn check_updates(cfg: &Cfg<'_>, opts: CheckOpts) -> Result<ExitCode> {
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))
}
});

Expand Down
7 changes: 4 additions & 3 deletions src/cli/self_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -1373,8 +1374,8 @@ pub(crate) async fn check_rustup_update(dl_cfg: &DownloadCfg<'_>) -> Result<bool
let available_version = get_available_rustup_version(dl_cfg).await?;

let bold = Style::new().bold();
let yellow = AnsiColor::Yellow.on_default().bold();
let green = AnsiColor::Green.on_default().bold();
let yellow = WARN;
let green = GOOD;

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

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.