From 95e9209e17cf933acb2dbce8d9fc784ca7ea9851 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 26 Aug 2024 08:39:33 +0100 Subject: [PATCH] feat(tui): remove duplicate messages from repo body The latest message is still displayed in the repo header --- crates/cli/src/tui/actor/model.rs | 31 ++----------------- .../cli/src/tui/components/repo/identity.rs | 7 ++--- .../cli/src/tui/components/repo/messages.rs | 26 ---------------- crates/cli/src/tui/components/repo/mod.rs | 20 ++++-------- 4 files changed, 12 insertions(+), 72 deletions(-) delete mode 100644 crates/cli/src/tui/components/repo/messages.rs diff --git a/crates/cli/src/tui/actor/model.rs b/crates/cli/src/tui/actor/model.rs index c98d788..6b15a97 100644 --- a/crates/cli/src/tui/actor/model.rs +++ b/crates/cli/src/tui/actor/model.rs @@ -118,10 +118,8 @@ impl From for ServerState { RepoState::Configured { repo_alias, message: "configured".into(), - messages: Vec::new(), alert: None, branches: rc.branches().clone(), - histories: None, log: git::graph::Log::default(), }, ), @@ -130,7 +128,6 @@ impl From for ServerState { RepoState::Identified { repo_alias, message: "identified".into(), - messages: Vec::new(), alert: None, }, ), @@ -180,25 +177,20 @@ pub enum RepoState { Identified { repo_alias: RepoAlias, message: String, - messages: Vec, alert: Option, }, Configured { repo_alias: RepoAlias, message: String, - messages: Vec, alert: Option, branches: RepoBranches, - histories: Option, log: Log, }, Ready { repo_alias: RepoAlias, message: String, - messages: Vec, alert: Option, branches: RepoBranches, - histories: Option, view_state: ViewState, main: Commit, next: Commit, @@ -243,16 +235,9 @@ impl RepoState { tracing::info!("new tui message"); let msg: String = msg.into(); match self { - Self::Identified { - message, messages, .. - } - | Self::Configured { - message, messages, .. - } - | Self::Ready { - message, messages, .. - } => { - messages.push(msg.clone()); + Self::Identified { message, .. } + | Self::Configured { message, .. } + | Self::Ready { message, .. } => { *message = msg; } } @@ -283,29 +268,23 @@ impl RepoState { Self::Identified { repo_alias, message, - messages, alert, } => Self::Identified { repo_alias, message, - messages, alert, }, Self::Configured { repo_alias, message, - messages, alert, branches, - histories, log, } => Self::Ready { repo_alias, message, - messages, alert, branches, - histories, view_state: ViewState::Expanded, main, next, @@ -315,20 +294,16 @@ impl RepoState { Self::Ready { repo_alias, message, - messages, alert, branches, - histories, view_state, log, .. // drop existing main, next and dev to use parameters } => Self::Ready { repo_alias, message, - messages, alert, branches, - histories, view_state, main, next, diff --git a/crates/cli/src/tui/components/repo/identity.rs b/crates/cli/src/tui/components/repo/identity.rs index b9e6c13..d7b64d7 100644 --- a/crates/cli/src/tui/components/repo/identity.rs +++ b/crates/cli/src/tui/components/repo/identity.rs @@ -1,12 +1,11 @@ // -use std::fmt::Display; use git_next_core::{RepoAlias, RepoBranches}; use ratatui::{ layout::Alignment, - style::{Color, Style, Styled, Stylize as _}, - text::{Line, Span, Text}, - widgets::{block::Title, Widget}, + style::{Color, Style, Stylize as _}, + text::{Line, Span}, + widgets::block::Title, }; pub struct Identity<'a> { diff --git a/crates/cli/src/tui/components/repo/messages.rs b/crates/cli/src/tui/components/repo/messages.rs deleted file mode 100644 index 38fa8d5..0000000 --- a/crates/cli/src/tui/components/repo/messages.rs +++ /dev/null @@ -1,26 +0,0 @@ -// -use ratatui::{ - text::{Line, Text}, - widgets::Widget, -}; - -pub struct Messages<'a>(&'a Vec); -impl<'a> Messages<'a> { - pub const fn new(messages: &'a Vec) -> 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::>(), - ) - .render(area, buf); - } -} diff --git a/crates/cli/src/tui/components/repo/mod.rs b/crates/cli/src/tui/components/repo/mod.rs index 4379438..c418c48 100644 --- a/crates/cli/src/tui/components/repo/mod.rs +++ b/crates/cli/src/tui/components/repo/mod.rs @@ -1,6 +1,5 @@ // mod identity; -mod messages; use std::string::String; @@ -12,7 +11,6 @@ use crate::{ }; use identity::Identity; -use messages::Messages; use ratatui::{ buffer::Buffer, @@ -32,14 +30,12 @@ impl<'a> Widget for RepoWidget<'a> { RepoState::Identified { repo_alias, message, - messages, alert, } => { InnerRepoWidget { label: "identified", repo_alias, message, - messages, alert: alert.as_ref().map(String::as_str), branches: None, log: None, @@ -50,16 +46,13 @@ impl<'a> Widget for RepoWidget<'a> { RepoState::Configured { repo_alias, message, - messages, alert, branches, log, - .. } => InnerRepoWidget { label: "configured", repo_alias, message, - messages, alert: alert.as_ref().map(String::as_str), branches: Some(branches), log: Some(log), @@ -69,7 +62,6 @@ impl<'a> Widget for RepoWidget<'a> { RepoState::Ready { repo_alias, message, - messages, alert, branches, log, @@ -82,7 +74,6 @@ impl<'a> Widget for RepoWidget<'a> { label: "ready", repo_alias, message, - messages, alert: alert.as_ref().map(String::as_str), branches: Some(branches), log: Some(log), @@ -101,7 +92,6 @@ struct InnerRepoWidget<'a> { pub label: &'a str, pub repo_alias: &'a RepoAlias, pub message: &'a str, - pub messages: &'a Vec, pub alert: Option<&'a str>, pub branches: Option<&'a RepoBranches>, pub log: Option<&'a git::graph::Log>, @@ -124,16 +114,18 @@ impl<'a> Widget for InnerRepoWidget<'a> { self.branches, )) .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() .direction(Direction::Vertical) - .constraints(vec![Constraint::Fill(1), Constraint::Fill(1)]) + .constraints(vec![Constraint::Length(log_len)]) .split(block.inner(area)); block.render(area, buf); - Messages::new(self.messages).render(layout_repo[0], buf); - if let Some(log) = self.log { - CommitLog { log }.render(layout_repo[1], buf); + CommitLog { log }.render(layout_repo[0], buf); } } }