From 65002a725e5c981ec800a5faf3dad4bb4a2fa6d7 Mon Sep 17 00:00:00 2001 From: Erik Kundt Date: Thu, 28 Nov 2024 16:17:28 +0100 Subject: [PATCH] bin(patch-review): Improve hunk list --- bin/commands/patch.rs | 4 +- bin/commands/patch/review.rs | 21 +++++--- bin/ui.rs | 1 + bin/ui/items.rs | 97 ++++++++++++++---------------------- bin/ui/span.rs | 15 ++++++ 5 files changed, 69 insertions(+), 69 deletions(-) create mode 100644 bin/ui/span.rs diff --git a/bin/commands/patch.rs b/bin/commands/patch.rs index 2a68d68b..2ad01a98 100644 --- a/bin/commands/patch.rs +++ b/bin/commands/patch.rs @@ -306,8 +306,7 @@ mod interface { let (_, revision) = opts.revision_or_latest(&patch, &repo)?; let brain = Brain::load_or_new(patch_id, revision, repo.raw(), &signer)?; - let builder = ReviewBuilder::new(&repo).hunks(&brain, revision)?; - let hunks = builder; + let hunks = ReviewBuilder::new(&repo).hunks(&brain, revision)?; let drafts = DraftStore::new(&repo, *signer.public_key()); let mut patches = cob::patch::Cache::no_cache(&drafts)?; @@ -358,6 +357,7 @@ mod interface { ) .run() .await?; + log::info!("Received selection from TUI: {:?}", selection); if let Some(selection) = selection.as_ref() { diff --git a/bin/commands/patch/review.rs b/bin/commands/patch/review.rs index a428367e..ca5f18ce 100644 --- a/bin/commands/patch/review.rs +++ b/bin/commands/patch/review.rs @@ -197,7 +197,7 @@ impl<'a> App<'a> { ); } - Ok(Self { + let mut app = App { profile, rid, patch, @@ -210,7 +210,11 @@ impl<'a> App<'a> { help: HelpState { text: TextViewState::new(help_text(), Position::default()), }, - }) + }; + + app.reload_states()?; + + Ok(app) } pub fn accept_current_hunk(&mut self) -> Result<()> { @@ -290,17 +294,18 @@ impl<'a> App<'a> { impl<'a> App<'a> { fn show_hunk_list(&self, ui: &mut Ui, frame: &mut Frame) { - let queue = self.queue.lock().unwrap(); - + let header = [Column::new(" Hunks ", Constraint::Fill(1))].to_vec(); let columns = [ - Column::new(" ", Constraint::Length(1)), - Column::new(" ", Constraint::Fill(1)), - Column::new(" ", Constraint::Length(15)), + Column::new("", Constraint::Length(2)), + Column::new("", Constraint::Fill(1)), + Column::new("", Constraint::Length(15)), ] .to_vec(); + + let queue = self.queue.lock().unwrap(); let mut selected = queue.1.selected(); - let table = ui.table(frame, &mut selected, &queue.0, columns, Some(Borders::All)); + let table = ui.headered_table(frame, &mut selected, &queue.0, header, columns); if table.changed { ui.send_message(Message::ItemChanged { state: TableState::new(selected), diff --git a/bin/ui.rs b/bin/ui.rs index 976e0374..e2ed9508 100644 --- a/bin/ui.rs +++ b/bin/ui.rs @@ -2,6 +2,7 @@ pub mod format; pub mod im; pub mod items; pub mod rm; +pub mod span; #[derive(Clone, Debug)] pub struct TerminalInfo { diff --git a/bin/ui/items.rs b/bin/ui/items.rs index 5c2ebc13..d03b157f 100644 --- a/bin/ui/items.rs +++ b/bin/ui/items.rs @@ -42,8 +42,9 @@ use tui::ui::utils::LineMerger; use tui::ui::{span, Column}; use tui::ui::{ToRow, ToTree}; -use crate::cob::{DiffStats, HunkState, HunkStats, IndexedHunkItem}; +use crate::cob::{DiffStats, HunkStats, IndexedHunkItem}; use crate::git::{Blob, Repo}; +use crate::ui; use super::super::git; use super::format; @@ -1185,10 +1186,6 @@ impl<'a> ToRow<3> for HunkItem<'a> { }, state, ) => { - let state = match state { - HunkState::Accepted => span::positive("✓"), - HunkState::Rejected => span::secondary("?"), - }; let stats = hunk.as_ref().map(HunkStats::from).unwrap_or_default(); let stats_cell = [ build_stats_spans(&DiffStats::Hunk(stats)), @@ -1197,7 +1194,9 @@ impl<'a> ToRow<3> for HunkItem<'a> { .concat(); [ - state.into(), + ui::span::hunk_state(state) + .into_right_aligned_line() + .into(), HunkItem::pretty_path(path, false).into(), Line::from(stats_cell).right_aligned().into(), ] @@ -1214,10 +1213,6 @@ impl<'a> ToRow<3> for HunkItem<'a> { }, state, ) => { - let state = match state { - HunkState::Accepted => span::positive("✓"), - HunkState::Rejected => span::secondary("?"), - }; let stats = hunk.as_ref().map(HunkStats::from).unwrap_or_default(); let stats_cell = [ build_stats_spans(&DiffStats::Hunk(stats)), @@ -1226,7 +1221,9 @@ impl<'a> ToRow<3> for HunkItem<'a> { .concat(); [ - state.into(), + ui::span::hunk_state(state) + .into_right_aligned_line() + .into(), HunkItem::pretty_path(path, false).into(), Line::from(stats_cell).right_aligned().into(), ] @@ -1242,10 +1239,6 @@ impl<'a> ToRow<3> for HunkItem<'a> { }, state, ) => { - let state = match state { - HunkState::Accepted => span::positive("✓"), - HunkState::Rejected => span::secondary("?"), - }; let stats = hunk.as_ref().map(HunkStats::from).unwrap_or_default(); let stats_cell = [ build_stats_spans(&DiffStats::Hunk(stats)), @@ -1254,16 +1247,14 @@ impl<'a> ToRow<3> for HunkItem<'a> { .concat(); [ - state.into(), + ui::span::hunk_state(state) + .into_right_aligned_line() + .into(), HunkItem::pretty_path(path, true).into(), Line::from(stats_cell).right_aligned().into(), ] } (_, Item::Copied { copied }, state) => { - let state = match state { - HunkState::Accepted => span::positive("✓"), - HunkState::Rejected => span::secondary("?"), - }; let stats = copied.diff.stats().copied().unwrap_or_default(); let stats_cell = [ build_stats_spans(&DiffStats::File(stats)), @@ -1272,16 +1263,14 @@ impl<'a> ToRow<3> for HunkItem<'a> { .concat(); [ - state.into(), + ui::span::hunk_state(state) + .into_right_aligned_line() + .into(), HunkItem::pretty_path(&copied.new_path, false).into(), Line::from(stats_cell).right_aligned().into(), ] } (_, Item::Moved { moved }, state) => { - let state = match state { - HunkState::Accepted => span::positive("✓"), - HunkState::Rejected => span::secondary("?"), - }; let stats = moved.diff.stats().copied().unwrap_or_default(); let stats_cell = [ build_stats_spans(&DiffStats::File(stats)), @@ -1290,7 +1279,9 @@ impl<'a> ToRow<3> for HunkItem<'a> { .concat(); [ - state.into(), + ui::span::hunk_state(state) + .into_right_aligned_line() + .into(), HunkItem::pretty_path(&moved.new_path, false).into(), Line::from(stats_cell).right_aligned().into(), ] @@ -1305,21 +1296,16 @@ impl<'a> ToRow<3> for HunkItem<'a> { _eof: _, }, state, - ) => { - let state = match state { - HunkState::Accepted => span::positive("✓"), - HunkState::Rejected => span::secondary("?"), - }; - - [ - state.into(), - HunkItem::pretty_path(path, false).into(), - span::default("EOF ") - .light_blue() - .into_right_aligned_line() - .into(), - ] - } + ) => [ + ui::span::hunk_state(state) + .into_right_aligned_line() + .into(), + HunkItem::pretty_path(path, false).into(), + span::default("EOF ") + .light_blue() + .into_right_aligned_line() + .into(), + ], ( _, Item::ModeChanged { @@ -1329,21 +1315,16 @@ impl<'a> ToRow<3> for HunkItem<'a> { new: _, }, state, - ) => { - let state = match state { - HunkState::Accepted => span::positive("✓"), - HunkState::Rejected => span::secondary("?"), - }; - - [ - state.into(), - HunkItem::pretty_path(path, false).into(), - span::default("FM ") - .light_blue() - .into_right_aligned_line() - .into(), - ] - } + ) => [ + ui::span::hunk_state(state) + .into_right_aligned_line() + .into(), + HunkItem::pretty_path(path, false).into(), + span::default("FM ") + .light_blue() + .into_right_aligned_line() + .into(), + ], } } } @@ -1368,9 +1349,7 @@ impl<'a> HunkItem<'a> { span::default(file.to_string_lossy().as_ref()) }, span::default(" "), - span::default(&path.join(&String::from("/")).to_string()) - .dark_gray() - .dim(), + span::default(&path.join(&String::from("/")).to_string()).dark_gray(), ] .to_vec(), ); diff --git a/bin/ui/span.rs b/bin/ui/span.rs new file mode 100644 index 00000000..af957060 --- /dev/null +++ b/bin/ui/span.rs @@ -0,0 +1,15 @@ +use ratatui::text::Span; + +use crate::cob::HunkState; + +use radicle_tui as tui; + +use tui::ui::span; + +pub fn hunk_state(state: &HunkState) -> Span<'static> { + match state { + HunkState::Accepted => span::positive("✓"), + // HunkState::Rejected => span::secondary("?"), + HunkState::Rejected => span::negative("✗"), + } +}