Radish alpha
r
Radicle terminal user interface
Radicle
Git (anonymous pull)
Log in to clone via SSH
bin: Cleans up hunk-to-text conversion
Erik Kundt committed 1 year ago
commit 70f89884b5e6eb5b7a045a2b054f834e52d9f2a0
parent d983b7ccd6d58324922a9757404077014e6a7044
2 files changed +17 -24
modified bin/commands/patch/review.rs
@@ -8,17 +8,15 @@ use std::sync::Mutex;

use anyhow::Result;

-
use radicle::patch::Review;
use ratatui::layout::Position;
+
use ratatui::layout::{Constraint, Layout};
use ratatui::style::Stylize;
use ratatui::text::Text;
-
use termion::event::Key;
-

-
use ratatui::layout::{Constraint, Layout};
use ratatui::{Frame, Viewport};
+
use termion::event::Key;

use radicle::identity::RepoId;
-
use radicle::storage::git::Repository;
+
use radicle::patch::Review;
use radicle::storage::ReadStorage;
use radicle::Profile;

@@ -139,8 +137,6 @@ pub struct ReviewItemState {

#[derive(Clone)]
pub struct App<'a> {
-
    repository: Arc<Mutex<Repository>>,
-
    review: Arc<Mutex<Review>>,
    queue: Arc<Mutex<(Vec<HunkItem<'a>>, TableState)>>,
    items: HashMap<usize, ReviewItemState>,
    page: AppPage,
@@ -165,7 +161,7 @@ impl<'a> App<'a> {
    pub fn new(
        profile: Profile,
        rid: RepoId,
-
        review: Review,
+
        _review: Review,
        queue: ReviewQueue,
    ) -> Result<Self, anyhow::Error> {
        let repository = profile.storage.repository(rid)?;
@@ -186,13 +182,11 @@ impl<'a> App<'a> {
        }

        Ok(Self {
-
            repository: Arc::new(Mutex::new(repository)),
            page: AppPage::Main,
            windows: GroupState::new(2, Some(0)),
            help: HelpState {
                text: TextViewState::new(help_text(), Position::default()),
            },
-
            review: Arc::new(Mutex::new(review)),
            queue: Arc::new(Mutex::new((queue, TableState::new(Some(0))))),
            items,
        })
@@ -220,7 +214,6 @@ impl<'a> App<'a> {
    }

    fn show_review_item(&self, ui: &mut Ui<Message>, frame: &mut Frame) {
-
        let repo = self.repository.lock().unwrap();
        let queue = self.queue.lock().unwrap();

        let selected = queue.1.selected();
@@ -229,7 +222,7 @@ impl<'a> App<'a> {
        if let Some(item) = item {
            let header = item.header();
            let hunk = item
-
                .hunk_text(&repo)
+
                .hunk_text()
                .unwrap_or(Text::raw("Nothing to show.").dark_gray());

            let mut cursor = selected
@@ -243,7 +236,7 @@ impl<'a> App<'a> {
                |ui| {
                    ui.columns(frame, header, Some(Borders::Top));

-
                    if let Some(hunk) = item.hunk_text(&repo) {
+
                    if let Some(hunk) = item.hunk_text() {
                        let diff =
                            ui.text_view(frame, hunk, &mut cursor, Some(Borders::BottomSides));
                        if diff.changed {
modified bin/ui/items.rs
@@ -1443,7 +1443,7 @@ impl<'a> HunkItem<'a> {
        }
    }

-
    pub fn hunk_text(&'a self, repo: &Repository) -> Option<Text<'a>> {
+
    pub fn hunk_text(&'a self) -> Option<Text<'a>> {
        match &self.inner {
            (
                _,
@@ -1455,7 +1455,7 @@ impl<'a> HunkItem<'a> {
                },
            ) => hunk
                .as_ref()
-
                .map(|hunk| Text::from(hunk.to_text(&self.highlighted, repo.raw()))),
+
                .map(|hunk| Text::from(hunk.to_text(&self.highlighted))),
            (
                _,
                crate::cob::HunkItem::FileModified {
@@ -1467,7 +1467,7 @@ impl<'a> HunkItem<'a> {
                },
            ) => hunk
                .as_ref()
-
                .map(|hunk| Text::from(hunk.to_text(&self.highlighted, repo.raw()))),
+
                .map(|hunk| Text::from(hunk.to_text(&self.highlighted))),
            (
                _,
                crate::cob::HunkItem::FileDeleted {
@@ -1478,7 +1478,7 @@ impl<'a> HunkItem<'a> {
                },
            ) => hunk
                .as_ref()
-
                .map(|hunk| Text::from(hunk.to_text(&self.highlighted, repo.raw()))),
+
                .map(|hunk| Text::from(hunk.to_text(&self.highlighted))),
            _ => None,
        }
    }
@@ -1582,14 +1582,14 @@ pub trait ToText<'a> {
    type Context;

    /// Render to pretty diff output.
-
    fn to_text<R: Repo>(&'a self, context: &Self::Context, repo: &R) -> Self::Output;
+
    fn to_text(&'a self, context: &Self::Context) -> Self::Output;
}

impl<'a> ToText<'a> for HunkHeader {
    type Output = Line<'a>;
    type Context = ();

-
    fn to_text<R: Repo>(&self, _context: &Self::Context, _repo: &R) -> Self::Output {
+
    fn to_text(&self, _context: &Self::Context) -> Self::Output {
        Line::from(
            [
                span::default(&format!(
@@ -1609,7 +1609,7 @@ impl<'a> ToText<'a> for Modification {
    type Output = Line<'a>;
    type Context = Blobs<Vec<Line<'a>>>;

-
    fn to_text<R: Repo>(&'a self, blobs: &Blobs<Vec<Line<'a>>>, _repo: &R) -> Self::Output {
+
    fn to_text(&'a self, blobs: &Blobs<Vec<Line<'a>>>) -> Self::Output {
        let line = match self {
            Modification::Deletion(diff::Deletion { line, line_no }) => {
                if let Some(lines) = &blobs.old.as_ref() {
@@ -1645,7 +1645,7 @@ impl<'a> ToText<'a> for Hunk<Modification> {
    type Output = Vec<Line<'a>>;
    type Context = Blobs<Vec<Line<'a>>>;

-
    fn to_text<R: Repo>(&'a self, blobs: &Self::Context, repo: &R) -> Self::Output {
+
    fn to_text(&'a self, blobs: &Self::Context) -> Self::Output {
        let mut lines: Vec<Line<'a>> = vec![];

        let default_dark = Color::Rgb(20, 20, 20);
@@ -1689,7 +1689,7 @@ impl<'a> ToText<'a> for Hunk<Modification> {
                                span::positive(" + ").bg(positive_dark).dim(),
                            ]
                            .to_vec(),
-
                            line.to_text(blobs, repo)
+
                            line.to_text(blobs)
                                .spans
                                .into_iter()
                                .map(|span| span.bg(positive_dark))
@@ -1712,7 +1712,7 @@ impl<'a> ToText<'a> for Hunk<Modification> {
                                span::negative(" - ").bg(negative_dark).dim(),
                            ]
                            .to_vec(),
-
                            line.to_text(blobs, repo)
+
                            line.to_text(blobs)
                                .spans
                                .into_iter()
                                .map(|span| span.bg(negative_dark))
@@ -1741,7 +1741,7 @@ impl<'a> ToText<'a> for Hunk<Modification> {
                                span::default(&format!("{:<3}", "")),
                            ]
                            .to_vec(),
-
                            line.to_text(blobs, repo).spans,
+
                            line.to_text(blobs).spans,
                        ]
                        .concat(),
                    ));