cli: Allow disabling emoji spinners

This commit is contained in:
Agatha V. Lovelace 2023-04-13 21:22:30 +02:00
parent c61bebae1d
commit f279530ba0
No known key found for this signature in database
GPG Key ID: 01D0B3AB10CED4F8
7 changed files with 45 additions and 18 deletions

View File

@ -182,7 +182,14 @@ It's also possible to specify the preference using environment variables. See <h
.value_name("WHEN")
.value_parser(value_parser!(ColorWhen))
.default_value("auto")
.global(true));
.global(true))
.arg(Arg::new("disable-emoji")
.long("disable-emoji")
.help("Disable emoji spinners in output").long_help("Use plain braille pattern spinners instead of emoji")
.display_order(HELP_ORDER_LOW)
.global(true)
.num_args(0)
);
if include_internal {
app = app.subcommand(

View File

@ -158,7 +158,7 @@ Same as the targets for switch-to-configuration, with the following extra pseudo
util::register_selector_args(command)
}
pub async fn run(_global_args: &ArgMatches, local_args: &ArgMatches) -> Result<(), ColmenaError> {
pub async fn run(global_args: &ArgMatches, local_args: &ArgMatches) -> Result<(), ColmenaError> {
let hive = util::hive_from_args(local_args).await?;
let ssh_config = env::var("SSH_CONFIG_FILE").ok().map(PathBuf::from);
@ -189,7 +189,10 @@ pub async fn run(_global_args: &ArgMatches, local_args: &ArgMatches) -> Result<(
let n_targets = targets.len();
let verbose = local_args.get_flag("verbose") || goal == Goal::DryActivate;
let mut output = SimpleProgressOutput::new(verbose);
let mut output = SimpleProgressOutput::new(
verbose,
!global_args.get_one("disable-emoji").unwrap_or(&false),
);
let progress = output.get_sender();
let mut deployment = Deployment::new(hive, targets, goal, progress);

View File

@ -59,7 +59,7 @@ By default, Colmena will deploy keys set in `deployment.keys` before activating
.num_args(1))
}
pub async fn run(_global_args: &ArgMatches, local_args: &ArgMatches) -> Result<(), ColmenaError> {
pub async fn run(global_args: &ArgMatches, local_args: &ArgMatches) -> Result<(), ColmenaError> {
if local_args.contains_id("sudo-command") {
log::error!("--sudo-command has been removed. Please configure it in deployment.privilegeEscalationCommand in the node configuration.");
quit::with_code(1);
@ -133,7 +133,10 @@ pub async fn run(_global_args: &ArgMatches, local_args: &ArgMatches) -> Result<(
let mut targets = HashMap::new();
targets.insert(hostname.clone(), target);
let mut output = SimpleProgressOutput::new(verbose);
let mut output = SimpleProgressOutput::new(
verbose,
!global_args.get_one("disable-emoji").unwrap_or(&false),
);
let progress = output.get_sender();
let mut deployment = Deployment::new(hive, targets, goal, progress);

View File

@ -59,7 +59,7 @@ It's recommended to use -- to separate Colmena options from the command to run.
util::register_selector_args(command)
}
pub async fn run(_global_args: &ArgMatches, local_args: &ArgMatches) -> Result<(), ColmenaError> {
pub async fn run(global_args: &ArgMatches, local_args: &ArgMatches) -> Result<(), ColmenaError> {
let hive = util::hive_from_args(local_args).await?;
let ssh_config = env::var("SSH_CONFIG_FILE").ok().map(PathBuf::from);
@ -89,7 +89,10 @@ pub async fn run(_global_args: &ArgMatches, local_args: &ArgMatches) -> Result<(
.collect(),
);
let mut output = SimpleProgressOutput::new(local_args.get_flag("verbose"));
let mut output = SimpleProgressOutput::new(
local_args.get_flag("verbose"),
!global_args.get_one("disable-emoji").unwrap_or(&false),
);
let (mut monitor, meta) = JobMonitor::new(output.get_sender());

View File

@ -20,8 +20,8 @@ pub fn subcommand() -> ClapCommand {
.hide(true)
}
pub async fn run(_global_args: &ArgMatches, _local_args: &ArgMatches) -> Result<(), ColmenaError> {
let mut output = SpinnerOutput::new();
pub async fn run(global_args: &ArgMatches, _local_args: &ArgMatches) -> Result<(), ColmenaError> {
let mut output = SpinnerOutput::new(!global_args.get_one("disable-emoji").unwrap_or(&false));
let (monitor, meta) = JobMonitor::new(output.get_sender());
let meta_future = meta.run(|meta| async move {

View File

@ -89,13 +89,13 @@ pub enum LineStyle {
}
impl SimpleProgressOutput {
pub fn new(verbose: bool) -> Self {
pub fn new(verbose: bool, emoji: bool) -> Self {
let tty = atty::is(atty::Stream::Stdout);
if verbose || !tty {
Self::Plain(PlainOutput::new())
} else {
Self::Spinner(SpinnerOutput::new())
Self::Spinner(SpinnerOutput::new(emoji))
}
}

View File

@ -29,6 +29,9 @@ pub struct SpinnerOutput {
/// Maximum label width for alignment.
label_width: usize,
/// Determines if emoji should be used
emoji: bool,
multi: MultiProgress,
sender: Option<Sender>,
receiver: Receiver,
@ -50,10 +53,13 @@ struct JobState {
}
impl SpinnerOutput {
pub fn new() -> Self {
pub fn new(emoji: bool) -> Self {
let meta_bar = {
ProgressBar::new(100)
.with_style(get_spinner_style(DEFAULT_LABEL_WIDTH, LineStyle::Normal))
ProgressBar::new(100).with_style(get_spinner_style(
DEFAULT_LABEL_WIDTH,
LineStyle::Normal,
emoji,
))
};
let (sender, receiver) = create_channel();
@ -65,6 +71,7 @@ impl SpinnerOutput {
meta_bar,
meta_style: LineStyle::Normal,
label_width: DEFAULT_LABEL_WIDTH,
emoji,
sender: Some(sender),
receiver,
}
@ -157,7 +164,7 @@ impl SpinnerOutput {
}
fn get_spinner_style(&self, style: LineStyle) -> ProgressStyle {
get_spinner_style(self.label_width, style)
get_spinner_style(self.label_width, style, self.emoji)
}
}
@ -219,7 +226,7 @@ impl JobState {
}
}
fn get_spinner_style(label_width: usize, style: LineStyle) -> ProgressStyle {
fn get_spinner_style(label_width: usize, style: LineStyle, emoji: bool) -> ProgressStyle {
let template = format!(
"{{prefix:>{}.bold.dim}} {{spinner}} {{elapsed}} {{wide_msg}}",
label_width
@ -228,12 +235,16 @@ fn get_spinner_style(label_width: usize, style: LineStyle) -> ProgressStyle {
match style {
LineStyle::Normal | LineStyle::Success | LineStyle::SuccessNoop => {
ProgressStyle::default_spinner()
.tick_chars("🕛🕐🕑🕒🕓🕔🕕🕖🕗🕘🕙🕚✅")
.tick_chars(if emoji {
"🕛🕐🕑🕒🕓🕔🕕🕖🕗🕘🕙🕚✅"
} else {
"⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏✔"
})
.template(&template)
.unwrap()
}
LineStyle::Failure => ProgressStyle::default_spinner()
.tick_chars("❌❌")
.tick_chars(if emoji { "❌❌" } else { "✖✖" })
.template(&template)
.unwrap(),
}