feat(tui): highlight user interventions in red
All checks were successful
Rust / build (push) Successful in 7m27s
ci/woodpecker/push/cron-docker-builder Pipeline was successful
ci/woodpecker/push/push-next Pipeline was successful
ci/woodpecker/push/tag-created Pipeline was successful
Release Please / Release-plz (push) Successful in 49s
All checks were successful
Rust / build (push) Successful in 7m27s
ci/woodpecker/push/cron-docker-builder Pipeline was successful
ci/woodpecker/push/push-next Pipeline was successful
ci/woodpecker/push/tag-created Pipeline was successful
Release Please / Release-plz (push) Successful in 49s
This commit is contained in:
parent
e489fb36e9
commit
d1a685ae34
1 changed files with 22 additions and 15 deletions
|
@ -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<Span<'a>> {
|
||||
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<Identity<'a>> 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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue