feat(tui): remove duplicate messages from repo body
All checks were successful
Rust / build (push) Successful in 7m12s
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 1m22s
ci/woodpecker/cron/cron-docker-builder Pipeline was successful
ci/woodpecker/cron/push-next Pipeline was successful
ci/woodpecker/cron/tag-created Pipeline was successful

The latest message is still displayed in the repo header
This commit is contained in:
Paul Campbell 2024-08-26 08:39:33 +01:00
parent d1a685ae34
commit 95e9209e17
4 changed files with 12 additions and 72 deletions

View file

@ -118,10 +118,8 @@ impl From<ValidAppConfig> for ServerState {
RepoState::Configured { RepoState::Configured {
repo_alias, repo_alias,
message: "configured".into(), message: "configured".into(),
messages: Vec::new(),
alert: None, alert: None,
branches: rc.branches().clone(), branches: rc.branches().clone(),
histories: None,
log: git::graph::Log::default(), log: git::graph::Log::default(),
}, },
), ),
@ -130,7 +128,6 @@ impl From<ValidAppConfig> for ServerState {
RepoState::Identified { RepoState::Identified {
repo_alias, repo_alias,
message: "identified".into(), message: "identified".into(),
messages: Vec::new(),
alert: None, alert: None,
}, },
), ),
@ -180,25 +177,20 @@ pub enum RepoState {
Identified { Identified {
repo_alias: RepoAlias, repo_alias: RepoAlias,
message: String, message: String,
messages: Vec<String>,
alert: Option<String>, alert: Option<String>,
}, },
Configured { Configured {
repo_alias: RepoAlias, repo_alias: RepoAlias,
message: String, message: String,
messages: Vec<String>,
alert: Option<String>, alert: Option<String>,
branches: RepoBranches, branches: RepoBranches,
histories: Option<git::commit::Histories>,
log: Log, log: Log,
}, },
Ready { Ready {
repo_alias: RepoAlias, repo_alias: RepoAlias,
message: String, message: String,
messages: Vec<String>,
alert: Option<String>, alert: Option<String>,
branches: RepoBranches, branches: RepoBranches,
histories: Option<git::commit::Histories>,
view_state: ViewState, view_state: ViewState,
main: Commit, main: Commit,
next: Commit, next: Commit,
@ -243,16 +235,9 @@ impl RepoState {
tracing::info!("new tui message"); tracing::info!("new tui message");
let msg: String = msg.into(); let msg: String = msg.into();
match self { match self {
Self::Identified { Self::Identified { message, .. }
message, messages, .. | Self::Configured { message, .. }
} | Self::Ready { message, .. } => {
| Self::Configured {
message, messages, ..
}
| Self::Ready {
message, messages, ..
} => {
messages.push(msg.clone());
*message = msg; *message = msg;
} }
} }
@ -283,29 +268,23 @@ impl RepoState {
Self::Identified { Self::Identified {
repo_alias, repo_alias,
message, message,
messages,
alert, alert,
} => Self::Identified { } => Self::Identified {
repo_alias, repo_alias,
message, message,
messages,
alert, alert,
}, },
Self::Configured { Self::Configured {
repo_alias, repo_alias,
message, message,
messages,
alert, alert,
branches, branches,
histories,
log, log,
} => Self::Ready { } => Self::Ready {
repo_alias, repo_alias,
message, message,
messages,
alert, alert,
branches, branches,
histories,
view_state: ViewState::Expanded, view_state: ViewState::Expanded,
main, main,
next, next,
@ -315,20 +294,16 @@ impl RepoState {
Self::Ready { Self::Ready {
repo_alias, repo_alias,
message, message,
messages,
alert, alert,
branches, branches,
histories,
view_state, view_state,
log, log,
.. // drop existing main, next and dev to use parameters .. // drop existing main, next and dev to use parameters
} => Self::Ready { } => Self::Ready {
repo_alias, repo_alias,
message, message,
messages,
alert, alert,
branches, branches,
histories,
view_state, view_state,
main, main,
next, next,

View file

@ -1,12 +1,11 @@
// //
use std::fmt::Display;
use git_next_core::{RepoAlias, RepoBranches}; use git_next_core::{RepoAlias, RepoBranches};
use ratatui::{ use ratatui::{
layout::Alignment, layout::Alignment,
style::{Color, Style, Styled, Stylize as _}, style::{Color, Style, Stylize as _},
text::{Line, Span, Text}, text::{Line, Span},
widgets::{block::Title, Widget}, widgets::block::Title,
}; };
pub struct Identity<'a> { pub struct Identity<'a> {

View file

@ -1,26 +0,0 @@
//
use ratatui::{
text::{Line, Text},
widgets::Widget,
};
pub struct Messages<'a>(&'a Vec<String>);
impl<'a> Messages<'a> {
pub const fn new(messages: &'a Vec<String>) -> Self {
Self(messages)
}
}
impl<'a> Widget for Messages<'a> {
fn render(self, area: ratatui::prelude::Rect, buf: &mut ratatui::prelude::Buffer)
where
Self: Sized,
{
Text::from(
self.0
.iter()
.map(|m| Line::from(format!("- {m}")))
.collect::<Vec<_>>(),
)
.render(area, buf);
}
}

View file

@ -1,6 +1,5 @@
// //
mod identity; mod identity;
mod messages;
use std::string::String; use std::string::String;
@ -12,7 +11,6 @@ use crate::{
}; };
use identity::Identity; use identity::Identity;
use messages::Messages;
use ratatui::{ use ratatui::{
buffer::Buffer, buffer::Buffer,
@ -32,14 +30,12 @@ impl<'a> Widget for RepoWidget<'a> {
RepoState::Identified { RepoState::Identified {
repo_alias, repo_alias,
message, message,
messages,
alert, alert,
} => { } => {
InnerRepoWidget { InnerRepoWidget {
label: "identified", label: "identified",
repo_alias, repo_alias,
message, message,
messages,
alert: alert.as_ref().map(String::as_str), alert: alert.as_ref().map(String::as_str),
branches: None, branches: None,
log: None, log: None,
@ -50,16 +46,13 @@ impl<'a> Widget for RepoWidget<'a> {
RepoState::Configured { RepoState::Configured {
repo_alias, repo_alias,
message, message,
messages,
alert, alert,
branches, branches,
log, log,
..
} => InnerRepoWidget { } => InnerRepoWidget {
label: "configured", label: "configured",
repo_alias, repo_alias,
message, message,
messages,
alert: alert.as_ref().map(String::as_str), alert: alert.as_ref().map(String::as_str),
branches: Some(branches), branches: Some(branches),
log: Some(log), log: Some(log),
@ -69,7 +62,6 @@ impl<'a> Widget for RepoWidget<'a> {
RepoState::Ready { RepoState::Ready {
repo_alias, repo_alias,
message, message,
messages,
alert, alert,
branches, branches,
log, log,
@ -82,7 +74,6 @@ impl<'a> Widget for RepoWidget<'a> {
label: "ready", label: "ready",
repo_alias, repo_alias,
message, message,
messages,
alert: alert.as_ref().map(String::as_str), alert: alert.as_ref().map(String::as_str),
branches: Some(branches), branches: Some(branches),
log: Some(log), log: Some(log),
@ -101,7 +92,6 @@ struct InnerRepoWidget<'a> {
pub label: &'a str, pub label: &'a str,
pub repo_alias: &'a RepoAlias, pub repo_alias: &'a RepoAlias,
pub message: &'a str, pub message: &'a str,
pub messages: &'a Vec<String>,
pub alert: Option<&'a str>, pub alert: Option<&'a str>,
pub branches: Option<&'a RepoBranches>, pub branches: Option<&'a RepoBranches>,
pub log: Option<&'a git::graph::Log>, pub log: Option<&'a git::graph::Log>,
@ -124,16 +114,18 @@ impl<'a> Widget for InnerRepoWidget<'a> {
self.branches, self.branches,
)) ))
.borders(Borders::ALL); .borders(Borders::ALL);
let log_len: u16 = self.log.map_or_else(
|| 0,
|log| u16::try_from(log.len()).map_or(u16::MAX, |len| len),
);
let layout_repo = Layout::default() let layout_repo = Layout::default()
.direction(Direction::Vertical) .direction(Direction::Vertical)
.constraints(vec![Constraint::Fill(1), Constraint::Fill(1)]) .constraints(vec![Constraint::Length(log_len)])
.split(block.inner(area)); .split(block.inner(area));
block.render(area, buf); block.render(area, buf);
Messages::new(self.messages).render(layout_repo[0], buf);
if let Some(log) = self.log { if let Some(log) = self.log {
CommitLog { log }.render(layout_repo[1], buf); CommitLog { log }.render(layout_repo[0], buf);
} }
} }
} }