From a54fbf7f63a2aa16dc37cb964dae6406b040143a Mon Sep 17 00:00:00 2001 From: Stephan Dilly Date: Sat, 18 Jul 2020 12:21:18 +0200 Subject: [PATCH] visualize pending load of a diff (#160) --- CHANGELOG.md | 1 + src/components/diff.rs | 28 +++++++++++++++++++--------- src/components/inspect_commit.rs | 4 +++- src/strings.rs | 2 ++ src/tabs/status.rs | 4 ++-- 5 files changed, 27 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f64daab5..b14a97d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added +- pending load of a diff is visualized better ([#160](https://github.com/extrawurst/gitui/issues/160)) - entry on [git-scm.com](https://git-scm.com/downloads/guis) in the list of GUI tools [[@Vidar314](https://github.com/Vidar314)] (see [PR](https://github.com/git/git-scm.com/pull/1485)) - commits can be tagged in revlog [[@cruessler](https://github.com/cruessler)] ([#103](https://github.com/extrawurst/gitui/issues/103)) diff --git a/src/components/diff.rs b/src/components/diff.rs index 110031b7..868806b3 100644 --- a/src/components/diff.rs +++ b/src/components/diff.rs @@ -12,7 +12,7 @@ use crossterm::event::Event; use std::{borrow::Cow, cell::Cell, cmp, path::Path}; use tui::{ backend::Backend, - layout::{Alignment, Rect}, + layout::Rect, symbols, widgets::{Block, Borders, Paragraph, Text}, Frame, @@ -30,6 +30,7 @@ struct Current { /// pub struct DiffComponent { diff: Option, + pending: bool, selection: usize, selected_hunk: Option, current_size: Cell<(u16, u16)>, @@ -47,6 +48,7 @@ impl DiffComponent { focused: false, queue, current: Current::default(), + pending: false, selected_hunk: None, diff: None, current_size: Cell::new((0, 0)), @@ -67,12 +69,13 @@ impl DiffComponent { (self.current.path.clone(), self.current.is_stage) } /// - pub fn clear(&mut self) -> Result<()> { + pub fn clear(&mut self, pending: bool) -> Result<()> { self.current = Current::default(); self.diff = None; self.scroll_top.set(0); self.selection = 0; self.selected_hunk = None; + self.pending = pending; Ok(()) } @@ -83,6 +86,8 @@ impl DiffComponent { is_stage: bool, diff: FileDiff, ) -> Result<()> { + self.pending = false; + let hash = hash(&diff); if self.current.hash != hash { @@ -432,19 +437,24 @@ impl DrawableComponent for DiffComponent { let title = format!("{}{}", strings::TITLE_DIFF, self.current.path); + + let txt = if self.pending { + vec![Text::Styled( + Cow::from(strings::LOADING_TEXT), + self.theme.text(false, false), + )] + } else { + self.get_text(r.width, self.current_size.get().1)? + }; + f.render_widget( - Paragraph::new( - self.get_text(r.width, self.current_size.get().1)? - .iter(), - ) - .block( + Paragraph::new(txt.iter()).block( Block::default() .title(title.as_str()) .borders(Borders::ALL) .border_style(self.theme.block(self.focused)) .title_style(self.theme.title(self.focused)), - ) - .alignment(Alignment::Left), + ), r, ); diff --git a/src/components/inspect_commit.rs b/src/components/inspect_commit.rs index a2201d74..f39d4c09 100644 --- a/src/components/inspect_commit.rs +++ b/src/components/inspect_commit.rs @@ -222,10 +222,12 @@ impl InspectCommitComponent { } self.git_diff.request(diff_params)?; + self.diff.clear(true)?; + return Ok(()); } } - self.diff.clear()?; + self.diff.clear(false)?; } Ok(()) diff --git a/src/strings.rs b/src/strings.rs index 218a5308..509dffb8 100644 --- a/src/strings.rs +++ b/src/strings.rs @@ -38,6 +38,8 @@ pub static HELP_TITLE: &str = "Help: all commands"; pub static STASHING_FILES_TITLE: &str = "Files to Stash"; pub static STASHING_OPTIONS_TITLE: &str = "Options"; +pub static LOADING_TEXT: &str = "Loading ..."; + pub mod commit { pub static DETAILS_AUTHOR: &str = "Author: "; pub static DETAILS_COMMITTER: &str = "Committer: "; diff --git a/src/tabs/status.rs b/src/tabs/status.rs index 5de60676..72ba5e39 100644 --- a/src/tabs/status.rs +++ b/src/tabs/status.rs @@ -271,11 +271,11 @@ impl Status { { self.diff.update(path, is_stage, diff)?; } else { - self.diff.clear()?; + self.diff.clear(true)?; } } } else { - self.diff.clear()?; + self.diff.clear(false)?; } Ok(())