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 {
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<ValidAppConfig> 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<String>,
alert: Option<String>,
},
Configured {
repo_alias: RepoAlias,
message: String,
messages: Vec<String>,
alert: Option<String>,
branches: RepoBranches,
histories: Option<git::commit::Histories>,
log: Log,
},
Ready {
repo_alias: RepoAlias,
message: String,
messages: Vec<String>,
alert: Option<String>,
branches: RepoBranches,
histories: Option<git::commit::Histories>,
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,

View file

@ -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> {

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 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<String>,
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);
}
}
}