diff --git a/src/cli.rs b/src/cli.rs index 2741032..58c8fa7 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -182,7 +182,14 @@ It's also possible to specify the preference using environment variables. See 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); diff --git a/src/command/apply_local.rs b/src/command/apply_local.rs index b712a7e..80487e5 100644 --- a/src/command/apply_local.rs +++ b/src/command/apply_local.rs @@ -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); diff --git a/src/command/exec.rs b/src/command/exec.rs index b723f6b..07d9b1b 100644 --- a/src/command/exec.rs +++ b/src/command/exec.rs @@ -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()); diff --git a/src/command/test_progress.rs b/src/command/test_progress.rs index df21980..62d313b 100644 --- a/src/command/test_progress.rs +++ b/src/command/test_progress.rs @@ -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 { diff --git a/src/progress/mod.rs b/src/progress/mod.rs index a1330f9..372ef93 100644 --- a/src/progress/mod.rs +++ b/src/progress/mod.rs @@ -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)) } } diff --git a/src/progress/spinner.rs b/src/progress/spinner.rs index 530851a..fdf63b0 100644 --- a/src/progress/spinner.rs +++ b/src/progress/spinner.rs @@ -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, 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(), }