mirror of
https://seed.radicle.dev/rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5.git
synced 2026-11-29 05:50:31 +08:00
cli: Simplify & improve CLI output
Improvements to the CLI output as well as converging towards `termion` as a backend. The crates we were using for prompting and spinners were based on a terminal backend called `console`, which is not really used anywhere else. There were also limitations in terms of the output of these crates. Therefore, we switched to the `inquire` crate for prompting, using the `termion` backend, which is very standard. Additionally, we simplify the terminal output to use symbols: ! for Warning ✓ for Success ✗ for Error ... Instead of a mix of words and symbols. We also include a modified version of the `yansi` crate which plays well with our table formatting functions by automatically truncating and padding output in a unicode-aware way.
This commit is contained in:
@@ -127,7 +127,7 @@ pub fn pretty_sync_status(
|
||||
) -> anyhow::Result<String> {
|
||||
let (a, b) = repo.graph_ahead_behind(revision_oid, head_oid)?;
|
||||
if a == 0 && b == 0 {
|
||||
return Ok(term::format::dim("up to date"));
|
||||
return Ok(term::format::dim("up to date").to_string());
|
||||
}
|
||||
|
||||
let ahead = term::format::positive(a);
|
||||
@@ -143,7 +143,7 @@ pub fn pretty_commit_version(
|
||||
revision_oid: &Oid,
|
||||
repo: &Option<git::raw::Repository>,
|
||||
) -> anyhow::Result<String> {
|
||||
let mut oid = term::format::secondary(term::format::oid(*revision_oid));
|
||||
let mut oid = term::format::secondary(term::format::oid(*revision_oid)).to_string();
|
||||
let mut branches: Vec<String> = vec![];
|
||||
|
||||
if let Some(repo) = repo {
|
||||
@@ -216,6 +216,8 @@ pub fn push_to_storage(
|
||||
if options.verbose {
|
||||
spinner.finish();
|
||||
term::blob(output);
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
spinner.finish();
|
||||
|
||||
@@ -5,6 +5,7 @@ use radicle::git;
|
||||
use radicle::prelude::*;
|
||||
use radicle::profile::Profile;
|
||||
use radicle::storage::git::Repository;
|
||||
use unicode_width::UnicodeWidthStr;
|
||||
|
||||
use crate::terminal as term;
|
||||
|
||||
@@ -39,10 +40,7 @@ pub fn run(
|
||||
}
|
||||
}
|
||||
term::blank();
|
||||
term::print(format!(
|
||||
"-{}-",
|
||||
term::format::badge_secondary("YOU PROPOSED")
|
||||
));
|
||||
term::print(term::format::badge_secondary("YOU PROPOSED"));
|
||||
|
||||
if own.is_empty() {
|
||||
term::blank();
|
||||
@@ -55,10 +53,7 @@ pub fn run(
|
||||
}
|
||||
}
|
||||
term::blank();
|
||||
term::print(format!(
|
||||
"-{}-",
|
||||
term::format::badge_secondary("OTHERS PROPOSED")
|
||||
));
|
||||
term::print(term::format::badge_secondary("OTHERS PROPOSED"));
|
||||
|
||||
if other.is_empty() {
|
||||
term::blank();
|
||||
@@ -94,11 +89,9 @@ fn print(
|
||||
)];
|
||||
|
||||
if you {
|
||||
author_info.push(term::format::secondary("(you)"));
|
||||
author_info.push(term::format::secondary("(you)").to_string());
|
||||
}
|
||||
author_info.push(term::format::dim(term::format::timestamp(
|
||||
&patch.timestamp(),
|
||||
)));
|
||||
author_info.push(term::format::dim(term::format::timestamp(&patch.timestamp())).to_string());
|
||||
|
||||
let (_, revision) = patch
|
||||
.latest()
|
||||
@@ -120,17 +113,17 @@ fn print(
|
||||
let mut badges = Vec::new();
|
||||
|
||||
if peer.delegate {
|
||||
badges.push(term::format::secondary("(delegate)"));
|
||||
badges.push(term::format::secondary("(delegate)").to_string());
|
||||
}
|
||||
if peer.id == *whoami {
|
||||
badges.push(term::format::secondary("(you)"));
|
||||
badges.push(term::format::secondary("(you)").to_string());
|
||||
}
|
||||
|
||||
timeline.push((
|
||||
merge.timestamp,
|
||||
format!(
|
||||
"{}{} by {} {}",
|
||||
" ".repeat(term::text_width(prefix)),
|
||||
" ".repeat(prefix.width()),
|
||||
term::format::secondary(term::format::dim("✓ merged")),
|
||||
term::format::tertiary(peer.id),
|
||||
badges.join(" "),
|
||||
@@ -147,17 +140,17 @@ fn print(
|
||||
let mut badges = Vec::new();
|
||||
|
||||
if peer.delegate {
|
||||
badges.push(term::format::secondary("(delegate)"));
|
||||
badges.push(term::format::secondary("(delegate)").to_string());
|
||||
}
|
||||
if peer.id == *whoami {
|
||||
badges.push(term::format::secondary("(you)"));
|
||||
badges.push(term::format::secondary("(you)").to_string());
|
||||
}
|
||||
|
||||
timeline.push((
|
||||
review.timestamp(),
|
||||
format!(
|
||||
"{}{} by {} {}",
|
||||
" ".repeat(term::text_width(prefix)),
|
||||
" ".repeat(prefix.width()),
|
||||
verdict,
|
||||
term::format::tertiary(reviewer),
|
||||
badges.join(" "),
|
||||
|
||||
Reference in New Issue
Block a user