diff --git a/crates/cli/src/tui/components/repo/identity.rs b/crates/cli/src/tui/components/repo/identity.rs index 5e88dc2..b9e6c13 100644 --- a/crates/cli/src/tui/components/repo/identity.rs +++ b/crates/cli/src/tui/components/repo/identity.rs @@ -4,7 +4,8 @@ use std::fmt::Display; use git_next_core::{RepoAlias, RepoBranches}; use ratatui::{ layout::Alignment, - text::Text, + style::{Color, Style, Styled, Stylize as _}, + text::{Line, Span, Text}, widgets::{block::Title, Widget}, }; @@ -32,19 +33,14 @@ impl<'a> Identity<'a> { } } } -impl<'a> Widget for Identity<'a> { - fn render(self, area: ratatui::prelude::Rect, buf: &mut ratatui::prelude::Buffer) - where - Self: Sized, - { - Text::from(self.to_string()).render(area, buf); - } -} -impl<'a> Display for Identity<'a> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl<'a> Identity<'a> { + fn spans(self) -> Vec> { let label = self.label; let repo_alias = self.repo_alias; - let alert = self.alert.unwrap_or(""); + let alert = self + .alert + .map_or(String::new(), |a| format!("{a} ")) + .fg(Color::Red); let message = self.message; let main = self .repo_branches @@ -58,12 +54,23 @@ impl<'a> Display for Identity<'a> { .repo_branches .map(RepoBranches::dev) .map_or_else(|| "_".to_string(), |b| b.to_string()); - let text = format!("{repo_alias} ({label}) {alert} ({main}/{next}/{dev}) [{message}]"); - f.write_str(text.as_str()) + vec![ + Span::from(format!(" {repo_alias} ({label}) ")), + alert, + Span::from(format!("({main}/{next}/{dev}) [{message}] ")), + ] } } impl<'a> From> for Title<'a> { fn from(identity: Identity<'a>) -> Self { - Self::from(identity.to_string()).alignment(Alignment::Left) + Self { + content: Line { + spans: identity.spans(), + style: Style::reset(), + alignment: None, + }, + alignment: Some(Alignment::Left), + position: None, + } } }