diff --git a/crates/radicle-cli/src/terminal/format.rs b/crates/radicle-cli/src/terminal/format.rs index 71b5e40f..78a42390 100644 --- a/crates/radicle-cli/src/terminal/format.rs +++ b/crates/radicle-cli/src/terminal/format.rs @@ -32,11 +32,44 @@ pub fn node_id_human(node: &NodeId) -> Paint { Paint::new(node.to_human()) } -/// Format a git Oid. +/// Format a Git object identifier. +/// To format a Git object identifier in short form, see [`oid`]. +pub fn oid_long(oid: impl Into) -> Paint { + Paint::new(format!("{}", oid.into())) +} + +/// Format a Git object identifier, shortened to the first 7 characters. +/// To format a Git object identifier in long form, see [`oid_long`]. pub fn oid(oid: impl Into) -> Paint { Paint::new(format!("{:.7}", oid.into())) } +fn double_dot(base: impl std::fmt::Display, head: impl std::fmt::Display) -> Paint { + Paint::new(format!("{}..{}", base, head)) +} + +/// Format a range between Git object identifiers (usually commits). +/// Both object identifiers are formatted in their long form, +/// see [`oid_long`]. +/// To format a range in short form, see [`range`]. +pub fn range_long(base: IntoOid, head: IntoOid) -> Paint +where + IntoOid: Into, +{ + double_dot(oid_long(base), oid_long(head)) +} + +/// Format a range between Git object identifiers (usually commits). +/// Both object identifiers are formatted in short form, +/// see [`oid`]. +/// To format a range in long form, see [`range_long`]. +pub fn range(base: IntoOid, head: IntoOid) -> Paint +where + IntoOid: Into, +{ + double_dot(oid(base), oid(head)) +} + /// Wrap parenthesis around styled input, eg. `"input"` -> `"(input)"`. pub fn parens(input: Paint) -> Paint { Paint::new(format!("({})", input.item)).with_style(input.style) diff --git a/crates/radicle-cli/src/terminal/patch/timeline.rs b/crates/radicle-cli/src/terminal/patch/timeline.rs index b7a8e834..9cf6a47f 100644 --- a/crates/radicle-cli/src/terminal/patch/timeline.rs +++ b/crates/radicle-cli/src/terminal/patch/timeline.rs @@ -209,7 +209,9 @@ impl Update<'_> { line.pad( 2 // alignment + 2 // parens - + LENGTH_OF_SHORT_COMMIT_HASH + + LENGTH_OF_SHORT_COMMIT_HASH // base + + 2 // .. + + LENGTH_OF_SHORT_COMMIT_HASH // head + LENGTH_OF_SPACES, ); }