From 853b862f10d9c08d366dd2bf39c88e3674f9d817 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sun, 1 Sep 2024 07:35:58 +0100 Subject: [PATCH] feat(tui): clean up alert display --- crates/cli/src/repo/handlers/validate_repo.rs | 6 +-- .../cli/src/tui/components/repo/identity.rs | 41 +++++++++++-------- 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/crates/cli/src/repo/handlers/validate_repo.rs b/crates/cli/src/repo/handlers/validate_repo.rs index 9390963..f3f710a 100644 --- a/crates/cli/src/repo/handlers/validate_repo.rs +++ b/crates/cli/src/repo/handlers/validate_repo.rs @@ -103,7 +103,7 @@ impl Handler for RepoActor { } Err(Error::Retryable(message)) => { info!(?message, "Retryable"); - self.alert_tui(format!("[retryable: {message}]")); + self.alert_tui(format!("retryable: {message}")); logger(self.log.as_ref(), message); let addr = ctx.address(); let message_token = self.message_token; @@ -122,7 +122,7 @@ impl Handler for RepoActor { } Err(Error::UserIntervention(user_notification)) => { info!(?user_notification, "User Intervention"); - self.alert_tui(format!("[USER INTERVENTION: {user_notification}]")); + self.alert_tui(format!("USER INTERVENTION: {user_notification}")); if let UserNotification::CICheckFailed { log, .. } | UserNotification::DevNotBasedOnMain { log, .. } = &user_notification { @@ -136,7 +136,7 @@ impl Handler for RepoActor { } Err(Error::NonRetryable(message)) => { info!(?message, "NonRetryable"); - self.alert_tui(format!("[Error: {message}]")); + self.alert_tui(format!("Error: {message}")); logger(self.log.as_ref(), message); } } diff --git a/crates/cli/src/tui/components/repo/identity.rs b/crates/cli/src/tui/components/repo/identity.rs index 8a48e03..6bfa3f5 100644 --- a/crates/cli/src/tui/components/repo/identity.rs +++ b/crates/cli/src/tui/components/repo/identity.rs @@ -1,3 +1,5 @@ +use std::string::ToString; + // use git_next_core::{RepoAlias, RepoBranches}; use ratatui::{ @@ -32,16 +34,10 @@ impl<'a> Identity<'a> { } impl<'a> Identity<'a> { fn spans(self) -> Vec> { - let repo_alias = Span::from(self.repo_alias.to_string()).style(if self.alert.is_some() { - Style::default().fg(Color::Black).bg(Color::Red) - } else { - Style::default().fg(Color::Cyan).bg(Color::Black) - }); let alert = self .alert - .map_or(String::new(), |a| format!("{a} ")) - .fg(Color::Black) - .bg(Color::Red); + .map(ToString::to_string) + .map(|alert| alert.fg(Color::White).bg(Color::Red)); let message = self.message; let main = self .repo_branches @@ -55,15 +51,26 @@ impl<'a> Identity<'a> { .repo_branches .map(RepoBranches::dev) .map_or_else(|| "_".to_string(), |b| b.to_string()); - vec![ - " ".into(), - repo_alias, - " ".into(), - alert, - format!("({main} -> {next} -> {dev}) ").into(), - message.into(), - " ".into(), - ] + let mut spans = vec![" ".into()]; + match alert { + None => spans.push( + Span::from(self.repo_alias.to_string()) + .style(Style::default().fg(Color::Cyan).bg(Color::Black)), + ), + Some(alert) => { + spans.push( + Span::from(self.repo_alias.to_string()) + .style(Style::default().fg(Color::White).bg(Color::Red)), + ); + spans.push(" ".into()); + spans.push(alert); + } + } + spans.push(" ".into()); + spans.push(format!("({main} -> {next} -> {dev}) ").into()); + spans.push(message.into()); + spans.push(" ".into()); + spans } } impl<'a> From> for Title<'a> {