Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an alternative to emoji spinners #146

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
7 changes: 5 additions & 2 deletions src/command/apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 5 additions & 2 deletions src/command/apply_local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 5 additions & 2 deletions src/command/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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());

Expand Down
4 changes: 2 additions & 2 deletions src/command/test_progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/progress/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down
25 changes: 18 additions & 7 deletions src/progress/spinner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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();
Expand All @@ -65,6 +71,7 @@ impl SpinnerOutput {
meta_bar,
meta_style: LineStyle::Normal,
label_width: DEFAULT_LABEL_WIDTH,
emoji,
sender: Some(sender),
receiver,
}
Expand Down Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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
Expand All @@ -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(),
}
Expand Down