bin(patch-review): Improve hunk list

This commit is contained in:
Erik Kundt
2024-11-29 12:07:50 +01:00
parent 97852c6e9d
commit 65002a725e
5 changed files with 69 additions and 69 deletions
+2 -2
View File
@@ -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() {
+13 -8
View File
@@ -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<Message>, 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),
+1
View File
@@ -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 {
+38 -59
View File
@@ -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(),
);
+15
View File
@@ -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("✗"),
}
}