From c089727e9058d7412c6ce92dc4a598bff19661a4 Mon Sep 17 00:00:00 2001 From: Lorenz Leutgeb Date: Wed, 13 Aug 2025 09:48:48 +0200 Subject: [PATCH] term, cli, remote-helper: Status Symbols MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Symbols signaling status of a process and similar are duplicated in three different crates. Also two different symbols to signal success are used: 1. ✓ ( Check Mark, U+2713) 2. ✔ (Heavy Check Mark, U+2714) Work against that by referring to `radicle-term` from the other crates. --- .../examples/rad-merge-via-push.md | 6 ++-- crates/radicle-cli/examples/rad-patch.md | 2 +- crates/radicle-cli/src/commands/id.rs | 4 +-- .../radicle-cli/src/commands/node/control.rs | 6 ++-- crates/radicle-cli/src/commands/patch/list.rs | 2 +- crates/radicle-cli/src/terminal/format.rs | 4 +-- .../src/terminal/patch/timeline.rs | 6 ++-- crates/radicle-remote-helper/src/push.rs | 14 ++++----- crates/radicle-term/src/io.rs | 29 +++++++++++-------- crates/radicle-term/src/spinner.rs | 12 ++++---- 10 files changed, 45 insertions(+), 40 deletions(-) diff --git a/crates/radicle-cli/examples/rad-merge-via-push.md b/crates/radicle-cli/examples/rad-merge-via-push.md index b365f107..5e2bea06 100644 --- a/crates/radicle-cli/examples/rad-merge-via-push.md +++ b/crates/radicle-cli/examples/rad-merge-via-push.md @@ -79,8 +79,8 @@ $ rad patch --merged ╭─────────────────────────────────────────────────────────────────────────────╮ │ ● ID Title Author Reviews Head + - Updated │ ├─────────────────────────────────────────────────────────────────────────────┤ -│ ✔ [ ... ] Second change alice (you) - daf349f +0 -0 now │ -│ ✔ [ ... ] First change alice (you) - 20aa5dd +0 -0 now │ +│ ✓ [ ... ] Second change alice (you) - daf349f +0 -0 now │ +│ ✓ [ ... ] First change alice (you) - 20aa5dd +0 -0 now │ ╰─────────────────────────────────────────────────────────────────────────────╯ $ rad patch show 696ec5508494692899337afe6713fe1796d0315c ╭────────────────────────────────────────────────────────────────╮ @@ -158,6 +158,6 @@ $ rad patch --all │ ● ID Title Author Reviews Head + - Updated │ ├─────────────────────────────────────────────────────────────────────────────┤ │ ● 356f738 Second change alice (you) - daf349f +0 -0 now │ -│ ✔ 696ec55 First change alice (you) - 20aa5dd +0 -0 now │ +│ ✓ 696ec55 First change alice (you) - 20aa5dd +0 -0 now │ ╰─────────────────────────────────────────────────────────────────────────────╯ ``` diff --git a/crates/radicle-cli/examples/rad-patch.md b/crates/radicle-cli/examples/rad-patch.md index aaef9fef..b038fa67 100644 --- a/crates/radicle-cli/examples/rad-patch.md +++ b/crates/radicle-cli/examples/rad-patch.md @@ -206,7 +206,7 @@ $ rad patch list ╭─────────────────────────────────────────────────────────────────────────────────────────╮ │ ● ID Title Author Reviews Head + - Updated │ ├─────────────────────────────────────────────────────────────────────────────────────────┤ -│ ● aa45913 Define power requirements alice (you) ✔ 27857ec +0 -0 now │ +│ ● aa45913 Define power requirements alice (you) ✓ 27857ec +0 -0 now │ ╰─────────────────────────────────────────────────────────────────────────────────────────╯ ``` diff --git a/crates/radicle-cli/src/commands/id.rs b/crates/radicle-cli/src/commands/id.rs index 45d9281a..943d3758 100644 --- a/crates/radicle-cli/src/commands/id.rs +++ b/crates/radicle-cli/src/commands/id.rs @@ -588,7 +588,7 @@ fn print_meta(revision: &Revision, previous: &Doc, profile: &Profile) -> anyhow: for id in accepted { let author = term::format::Author::new(&id, profile); signatures.push([ - term::format::positive("✓").into(), + term::PREFIX_SUCCESS.into(), id.to_string().into(), author.alias().unwrap_or_default(), author.you().unwrap_or_default(), @@ -597,7 +597,7 @@ fn print_meta(revision: &Revision, previous: &Doc, profile: &Profile) -> anyhow: for id in rejected { let author = term::format::Author::new(&id, profile); signatures.push([ - term::format::negative("✗").into(), + term::PREFIX_ERROR.into(), id.to_string().into(), author.alias().unwrap_or_default(), author.you().unwrap_or_default(), diff --git a/crates/radicle-cli/src/commands/node/control.rs b/crates/radicle-cli/src/commands/node/control.rs index bf36367d..37ab71e4 100644 --- a/crates/radicle-cli/src/commands/node/control.rs +++ b/crates/radicle-cli/src/commands/node/control.rs @@ -412,15 +412,15 @@ fn state_initial() -> term::Paint { } fn state_attempted() -> term::Paint { - term::format::yellow("!".to_string()) + term::PREFIX_WARNING.into() } fn state_connected() -> term::Paint { - term::format::positive("✓".to_string()) + term::PREFIX_SUCCESS.into() } fn state_disconnected() -> term::Paint { - term::format::negative("✗".to_string()) + term::PREFIX_ERROR.into() } fn link_direction_label() -> term::Paint { diff --git a/crates/radicle-cli/src/commands/patch/list.rs b/crates/radicle-cli/src/commands/patch/list.rs index 6a8c8e41..8673fbb4 100644 --- a/crates/radicle-cli/src/commands/patch/list.rs +++ b/crates/radicle-cli/src/commands/patch/list.rs @@ -142,7 +142,7 @@ pub fn row( patch::State::Open { .. } => term::format::positive("●").into(), patch::State::Archived => term::format::yellow("●").into(), patch::State::Draft => term::format::dim("●").into(), - patch::State::Merged { .. } => term::format::primary("✔").into(), + patch::State::Merged { .. } => term::PREFIX_SUCCESS.into(), }, term::format::tertiary(term::format::cob(id)).into(), term::format::default(patch.title().to_owned()).into(), diff --git a/crates/radicle-cli/src/terminal/format.rs b/crates/radicle-cli/src/terminal/format.rs index 3cce6b73..3dc6deaf 100644 --- a/crates/radicle-cli/src/terminal/format.rs +++ b/crates/radicle-cli/src/terminal/format.rs @@ -341,8 +341,8 @@ pub mod patch { pub fn verdict(v: Option) -> term::Paint { match v { - Some(Verdict::Accept) => term::format::positive("✔".to_string()), - Some(Verdict::Reject) => term::format::negative("✗".to_string()), + Some(Verdict::Accept) => term::PREFIX_SUCCESS.into(), + Some(Verdict::Reject) => term::PREFIX_ERROR.into(), None => term::format::dim("-".to_string()), } } diff --git a/crates/radicle-cli/src/terminal/patch/timeline.rs b/crates/radicle-cli/src/terminal/patch/timeline.rs index 14da594e..e4dc4eda 100644 --- a/crates/radicle-cli/src/terminal/patch/timeline.rs +++ b/crates/radicle-cli/src/terminal/patch/timeline.rs @@ -290,8 +290,8 @@ impl Update<'_> { Update::Reviewed { review } => { let verdict = review.verdict(); let verdict_symbol = match verdict { - Some(Verdict::Accept) => term::format::positive("✓"), - Some(Verdict::Reject) => term::format::negative("✗"), + Some(Verdict::Accept) => term::PREFIX_SUCCESS, + Some(Verdict::Reject) => term::PREFIX_ERROR, None => term::format::dim("⋄"), }; let verdict_verb = match verdict { @@ -310,7 +310,7 @@ impl Update<'_> { Update::Merged { author, merge } => { let (alias, nid) = author.labels(); term::Line::spaced([ - term::format::primary("✓").bold().into(), + term::PREFIX_SUCCESS.bold().into(), term::format::default("merged by").into(), alias, nid, diff --git a/crates/radicle-remote-helper/src/push.rs b/crates/radicle-remote-helper/src/push.rs index f085926a..53a0e278 100644 --- a/crates/radicle-remote-helper/src/push.rs +++ b/crates/radicle-remote-helper/src/push.rs @@ -390,7 +390,7 @@ pub fn run( let print_update = || { eprintln!( "{} Canonical reference {} updated to target {kind} {}", - term::format::positive("✓"), + term::PREFIX_SUCCESS, term::format::secondary(refname), term::format::secondary(oid), ) @@ -530,7 +530,7 @@ where eprintln!( "{} Patch {} {action}", - term::format::positive("✓"), + term::PREFIX_SUCCESS, term::format::tertiary(patch), ); @@ -630,7 +630,7 @@ where eprintln!( "{} Patch {} updated to revision {}", - term::format::positive("✓"), + term::PREFIX_SUCCESS, term::format::tertiary(term::format::cob(&patch_id)), term::format::dim(revision.id()) ); @@ -745,13 +745,13 @@ where Ok(()) => { eprintln!( "{} Patch {} reverted at revision {}", - term::format::yellow("!"), + term::PREFIX_WARNING, term::format::tertiary(&id), term::format::dim(term::format::oid(*revision_id)), ); } Err(e) => { - eprintln!("{} Error reverting patch {id}: {e}", term::ERROR_PREFIX); + eprintln!("{} Error reverting patch {id}: {e}", term::PREFIX_ERROR); } } break; @@ -833,13 +833,13 @@ where if revision == latest { eprintln!( "{} Patch {} merged", - term::format::positive("✓"), + term::PREFIX_SUCCESS, term::format::tertiary(merged.patch) ); } else { eprintln!( "{} Patch {} merged at revision {}", - term::format::positive("✓"), + term::PREFIX_SUCCESS, term::format::tertiary(merged.patch), term::format::dim(term::format::oid(revision)), ); diff --git a/crates/radicle-term/src/io.rs b/crates/radicle-term/src/io.rs index 3eeb66d1..ebcf2ee0 100644 --- a/crates/radicle-term/src/io.rs +++ b/crates/radicle-term/src/io.rs @@ -17,9 +17,14 @@ use crate::{style, Paint, Size}; pub use inquire; pub use inquire::Select; -pub const ERROR_PREFIX: Paint<&str> = Paint::red("✗"); -pub const ERROR_HINT_PREFIX: Paint<&str> = Paint::yellow("✗ Hint:"); -pub const WARNING_PREFIX: Paint<&str> = Paint::yellow("!"); +pub(crate) const SYMBOL_ERROR: &str = "✗"; +pub(crate) const SYMBOL_SUCCESS: &str = "✓"; +pub(crate) const SYMBOL_WARNING: &str = "!"; + +pub const PREFIX_ERROR: Paint<&str> = Paint::red(SYMBOL_ERROR); +pub const PREFIX_SUCCESS: Paint<&str> = Paint::green(SYMBOL_SUCCESS); +pub const PREFIX_WARNING: Paint<&str> = Paint::yellow(SYMBOL_WARNING); + pub const TAB: &str = " "; /// Passphrase input. @@ -29,15 +34,15 @@ pub type Passphrase = Zeroizing; pub static CONFIG: LazyLock = LazyLock::new(|| RenderConfig { prompt: StyleSheet::new().with_fg(Color::LightCyan), prompt_prefix: Styled::new("?").with_fg(Color::LightBlue), - answered_prompt_prefix: Styled::new("✓").with_fg(Color::LightGreen), + answered_prompt_prefix: Styled::new(SYMBOL_SUCCESS).with_fg(Color::LightGreen), answer: StyleSheet::new(), - highlighted_option_prefix: Styled::new("✓").with_fg(Color::LightYellow), + highlighted_option_prefix: Styled::new(SYMBOL_SUCCESS).with_fg(Color::LightYellow), selected_option: Some(StyleSheet::new().with_fg(Color::LightYellow)), option: StyleSheet::new(), help_message: StyleSheet::new().with_fg(Color::DarkGrey), default_value: StyleSheet::new().with_fg(Color::LightBlue), error_message: ErrorMessageRenderConfig::default_colored() - .with_prefix(Styled::new("✗").with_fg(Color::LightRed)), + .with_prefix(Styled::new(SYMBOL_ERROR).with_fg(Color::LightRed)), ..RenderConfig::default_colored() }); @@ -87,7 +92,7 @@ pub use success; pub use tip; pub fn success_args(w: &mut W, args: fmt::Arguments) { - writeln!(w, "{} {args}", Paint::green("✓")).ok(); + writeln!(w, "{PREFIX_SUCCESS} {args}").ok(); } pub fn tip_args(args: fmt::Arguments) { @@ -99,7 +104,7 @@ pub fn tip_args(args: fmt::Arguments) { } pub fn notice_args(w: &mut W, args: fmt::Arguments) { - writeln!(w, "{} {args}", Paint::new("!").dim()).ok(); + writeln!(w, "{} {args}", Paint::new(SYMBOL_WARNING).dim()).ok(); } pub fn columns() -> Option { @@ -167,7 +172,7 @@ pub fn manual(name: &str) -> io::Result { pub fn usage(name: &str, usage: &str) { println!( "{} {}\n{}", - ERROR_PREFIX, + PREFIX_ERROR, Paint::red(format!("Error: rad-{name}: invalid usage")), Paint::red(prefixed(TAB, usage)).dim() ); @@ -188,17 +193,17 @@ pub fn subcommand(msg: impl fmt::Display) { pub fn warning(warning: impl fmt::Display) { println!( "{} {} {warning}", - WARNING_PREFIX, + PREFIX_WARNING, Paint::yellow("Warning:").bold(), ); } pub fn error(error: impl fmt::Display) { - println!("{ERROR_PREFIX} {} {error}", Paint::red("Error:")); + println!("{PREFIX_ERROR} {} {error}", Paint::red("Error:")); } pub fn hint(hint: impl fmt::Display) { - println!("{ERROR_HINT_PREFIX} {}", format::hint(hint)); + println!("{}", format::hint(format!("{SYMBOL_ERROR} Hint: {hint}"))); } pub fn ask(prompt: D, default: bool) -> bool { diff --git a/crates/radicle-term/src/spinner.rs b/crates/radicle-term/src/spinner.rs index e3fa276b..c5ad8e2e 100644 --- a/crates/radicle-term/src/spinner.rs +++ b/crates/radicle-term/src/spinner.rs @@ -3,7 +3,7 @@ use std::mem::ManuallyDrop; use std::sync::{Arc, Mutex}; use std::{fmt, io, thread, time}; -use crate::io::{ERROR_PREFIX, WARNING_PREFIX}; +use crate::io::{PREFIX_ERROR, PREFIX_WARNING}; use crate::Paint; /// How much time to wait between spinner animation updates. @@ -161,7 +161,7 @@ pub fn spinner_to( write!(animation, "\r{CLEAR_UNTIL_NEWLINE}").ok(); writeln!( completion, - "{ERROR_PREFIX} {} {}", + "{PREFIX_ERROR} {} {}", &progress.message, Paint::red("") ) @@ -190,7 +190,7 @@ pub fn spinner_to( message, } => { write!(animation, "\r{CLEAR_UNTIL_NEWLINE}").ok(); - writeln!(completion, "{} {message}", Paint::green("✓")).ok(); + writeln!(completion, "{} {message}", super::PREFIX_SUCCESS).ok(); break; } Progress { @@ -200,7 +200,7 @@ pub fn spinner_to( write!(animation, "\r{CLEAR_UNTIL_NEWLINE}").ok(); writeln!( completion, - "{ERROR_PREFIX} {message} {}", + "{PREFIX_ERROR} {message} {}", Paint::red("") ) .ok(); @@ -211,7 +211,7 @@ pub fn spinner_to( message, } => { write!(animation, "\r{CLEAR_UNTIL_NEWLINE}").ok(); - writeln!(completion, "{WARNING_PREFIX} {message}").ok(); + writeln!(completion, "{PREFIX_WARNING} {message}").ok(); break; } Progress { @@ -219,7 +219,7 @@ pub fn spinner_to( message, } => { write!(animation, "\r{CLEAR_UNTIL_NEWLINE}").ok(); - writeln!(completion, "{ERROR_PREFIX} {message}").ok(); + writeln!(completion, "{PREFIX_ERROR} {message}").ok(); break; } }