diff --git a/radicle-cli/src/terminal/format.rs b/radicle-cli/src/terminal/format.rs index 61ddf910..bf80bbac 100644 --- a/radicle-cli/src/terminal/format.rs +++ b/radicle-cli/src/terminal/format.rs @@ -136,7 +136,7 @@ pub struct Author<'a> { impl<'a> Author<'a> { pub fn new(nid: &'a NodeId, profile: &Profile) -> Author<'a> { - let alias = profile.aliases().alias(nid); + let alias = profile.alias(nid); Self { nid, @@ -157,28 +157,31 @@ impl<'a> Author<'a> { } } + /// Get the labels of the `Author`. The labels can take the following forms: + /// + /// * `(, (you))` -- the `Author` is the local peer and has an alias + /// * `(, (you))` -- the `Author` is the local peer and has no alias + /// * `(, )` -- the `Author` is another peer and has an alias + /// * `(, )` -- the `Author` is another peer and has no alias pub fn labels(self) -> (term::Label, term::Label) { - let alias = match &self.alias { + let alias = match self.alias.as_ref() { Some(alias) => term::format::primary(alias).into(), - None => term::format::primary(term::format::node(self.nid)) + None if self.you => term::format::primary(term::format::node(self.nid)) .dim() .into(), + None => term::Label::blank(), }; - if let Some(you) = self.you() { - (alias, you) - } else { - ( - alias, - term::format::primary(term::format::node(self.nid)) - .dim() - .into(), - ) - } + let author = self.you().unwrap_or_else(|| { + term::format::primary(term::format::node(self.nid)) + .dim() + .into() + }); + (alias, author) } pub fn line(self) -> Line { - let (first, second) = self.labels(); - Line::spaced([first, second]) + let (alias, author) = self.labels(); + Line::spaced([alias, author]) } } diff --git a/radicle-term/src/element.rs b/radicle-term/src/element.rs index 6b504fd9..9432b4d9 100644 --- a/radicle-term/src/element.rs +++ b/radicle-term/src/element.rs @@ -186,6 +186,10 @@ impl Line { pub fn spaced(items: impl IntoIterator) -> Self { let mut line = Self::default(); for item in items.into_iter() { + // Don't create spaces around empty labels. + if item.is_blank() { + continue; + } line.push(item); line.push(Label::space()); } diff --git a/radicle-term/src/label.rs b/radicle-term/src/label.rs index cd43c1f2..10e44058 100644 --- a/radicle-term/src/label.rs +++ b/radicle-term/src/label.rs @@ -17,6 +17,11 @@ impl Label { Self(Paint::default()) } + /// Is this label empty. + pub fn is_blank(&self) -> bool { + self.content().is_empty() + } + /// Get unstyled content. pub fn content(&self) -> &str { self.0.content()