feat(tui): clean up alert display
All checks were successful
Rust / build (push) Successful in 7m14s
ci/woodpecker/push/push-next Pipeline was successful
ci/woodpecker/push/cron-docker-builder Pipeline was successful
ci/woodpecker/push/tag-created Pipeline was successful
Release Please / Release-plz (push) Successful in 1m1s

This commit is contained in:
Paul Campbell 2024-09-01 07:35:58 +01:00
parent ca70c03e8b
commit 853b862f10
2 changed files with 27 additions and 20 deletions

View file

@ -103,7 +103,7 @@ impl Handler<ValidateRepo> 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<ValidateRepo> 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<ValidateRepo> 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);
}
}

View file

@ -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<Span<'a>> {
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<Identity<'a>> for Title<'a> {