feat(tui): highlight user interventions in red
This commit is contained in:
parent
e489fb36e9
commit
9acfd4edb9
1 changed files with 23 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,15 @@ 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} "))
|
||||
// .bg(Color::White)
|
||||
.fg(Color::Red);
|
||||
let message = self.message;
|
||||
let main = self
|
||||
.repo_branches
|
||||
|
@ -58,12 +55,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