diff --git a/src/commands/restore.rs b/src/commands/restore.rs index e2538275..dd80cded 100644 --- a/src/commands/restore.rs +++ b/src/commands/restore.rs @@ -30,6 +30,9 @@ pub struct RestoreCmd { #[clap(from_global)] cache: Option, + #[clap(from_global)] + no_emoji: bool, + /// Prefer copying files over hard linking them. /// /// On filesystems that don't support copy-on-write/reflinks (usually NTFS @@ -62,7 +65,7 @@ pub struct RestoreCmd { impl OroCommand for RestoreCmd { async fn execute(self) -> Result<()> { let total_time = std::time::Instant::now(); - let emoji = Emoji::new(); + let emoji = Emoji::new(!self.no_emoji); let root = self .root .as_deref() @@ -265,8 +268,8 @@ fn hackerish_encouragement() -> &'static str { struct Emoji(bool); impl Emoji { - fn new() -> Self { - Self(supports_unicode::on(supports_unicode::Stream::Stderr)) + fn new(use_emoji: bool) -> Self { + Self(use_emoji) } const PACKAGE: &'static str = "📦 "; @@ -276,7 +279,11 @@ impl Emoji { const TADA: &'static str = "🎉 "; fn package(&self) -> &'static str { - Self::PACKAGE + if self.0 { + Self::PACKAGE + } else { + "" + } } fn magnifying_glass(&self) -> &'static str { diff --git a/src/lib.rs b/src/lib.rs index fe322624..b74a9647 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -105,6 +105,10 @@ pub struct Orogene { #[arg(help_heading = "Global Options", global = true, long)] no_progress: bool, + /// Disables all emoji usage. + #[arg(help_heading = "Global Options", global = true, long)] + no_emoji: bool, + #[command(subcommand)] subcommand: OroCmd, } @@ -204,6 +208,10 @@ impl Orogene { let mut cfg_builder = OroConfigOptions::new() .set_default("registry", "https://registry.npmjs.org")? .set_default("loglevel", "warn")? + .set_default( + "no_emoji", + &format!("{}", !supports_unicode::on(supports_unicode::Stream::Stderr)), + )? .set_default("root", &root.to_string_lossy())?; if let Some(cache) = dirs.as_ref().map(|d| d.cache_dir().to_owned()) { cfg_builder = cfg_builder.set_default("cache", &cache.to_string_lossy())?; diff --git a/tests/snapshots/help__ping.snap b/tests/snapshots/help__ping.snap index a70ff490..729e7aab 100644 --- a/tests/snapshots/help__ping.snap +++ b/tests/snapshots/help__ping.snap @@ -67,4 +67,8 @@ Format output as JSON Disable progress bar display +#### `--no-emoji` + +Disables all emoji usage + diff --git a/tests/snapshots/help__restore.snap b/tests/snapshots/help__restore.snap index faaa5793..10ab3189 100644 --- a/tests/snapshots/help__restore.snap +++ b/tests/snapshots/help__restore.snap @@ -85,4 +85,8 @@ Format output as JSON Disable progress bar display +#### `--no-emoji` + +Disables all emoji usage + diff --git a/tests/snapshots/help__view.snap b/tests/snapshots/help__view.snap index cbe00ac0..8d960c05 100644 --- a/tests/snapshots/help__view.snap +++ b/tests/snapshots/help__view.snap @@ -73,4 +73,8 @@ Format output as JSON Disable progress bar display +#### `--no-emoji` + +Disables all emoji usage +