visualize pending load of a diff (#160)

This commit is contained in:
Stephan Dilly 2020-07-18 12:21:18 +02:00
parent ed730c2fa1
commit a54fbf7f63
5 changed files with 27 additions and 12 deletions

View file

@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
### Added ### 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)) - 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)) - commits can be tagged in revlog [[@cruessler](https://github.com/cruessler)] ([#103](https://github.com/extrawurst/gitui/issues/103))

View file

@ -12,7 +12,7 @@ use crossterm::event::Event;
use std::{borrow::Cow, cell::Cell, cmp, path::Path}; use std::{borrow::Cow, cell::Cell, cmp, path::Path};
use tui::{ use tui::{
backend::Backend, backend::Backend,
layout::{Alignment, Rect}, layout::Rect,
symbols, symbols,
widgets::{Block, Borders, Paragraph, Text}, widgets::{Block, Borders, Paragraph, Text},
Frame, Frame,
@ -30,6 +30,7 @@ struct Current {
/// ///
pub struct DiffComponent { pub struct DiffComponent {
diff: Option<FileDiff>, diff: Option<FileDiff>,
pending: bool,
selection: usize, selection: usize,
selected_hunk: Option<usize>, selected_hunk: Option<usize>,
current_size: Cell<(u16, u16)>, current_size: Cell<(u16, u16)>,
@ -47,6 +48,7 @@ impl DiffComponent {
focused: false, focused: false,
queue, queue,
current: Current::default(), current: Current::default(),
pending: false,
selected_hunk: None, selected_hunk: None,
diff: None, diff: None,
current_size: Cell::new((0, 0)), current_size: Cell::new((0, 0)),
@ -67,12 +69,13 @@ impl DiffComponent {
(self.current.path.clone(), self.current.is_stage) (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.current = Current::default();
self.diff = None; self.diff = None;
self.scroll_top.set(0); self.scroll_top.set(0);
self.selection = 0; self.selection = 0;
self.selected_hunk = None; self.selected_hunk = None;
self.pending = pending;
Ok(()) Ok(())
} }
@ -83,6 +86,8 @@ impl DiffComponent {
is_stage: bool, is_stage: bool,
diff: FileDiff, diff: FileDiff,
) -> Result<()> { ) -> Result<()> {
self.pending = false;
let hash = hash(&diff); let hash = hash(&diff);
if self.current.hash != hash { if self.current.hash != hash {
@ -432,19 +437,24 @@ impl DrawableComponent for DiffComponent {
let title = let title =
format!("{}{}", strings::TITLE_DIFF, self.current.path); 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( f.render_widget(
Paragraph::new( Paragraph::new(txt.iter()).block(
self.get_text(r.width, self.current_size.get().1)?
.iter(),
)
.block(
Block::default() Block::default()
.title(title.as_str()) .title(title.as_str())
.borders(Borders::ALL) .borders(Borders::ALL)
.border_style(self.theme.block(self.focused)) .border_style(self.theme.block(self.focused))
.title_style(self.theme.title(self.focused)), .title_style(self.theme.title(self.focused)),
) ),
.alignment(Alignment::Left),
r, r,
); );

View file

@ -222,10 +222,12 @@ impl InspectCommitComponent {
} }
self.git_diff.request(diff_params)?; self.git_diff.request(diff_params)?;
self.diff.clear(true)?;
return Ok(());
} }
} }
self.diff.clear()?; self.diff.clear(false)?;
} }
Ok(()) Ok(())

View file

@ -38,6 +38,8 @@ pub static HELP_TITLE: &str = "Help: all commands";
pub static STASHING_FILES_TITLE: &str = "Files to Stash"; pub static STASHING_FILES_TITLE: &str = "Files to Stash";
pub static STASHING_OPTIONS_TITLE: &str = "Options"; pub static STASHING_OPTIONS_TITLE: &str = "Options";
pub static LOADING_TEXT: &str = "Loading ...";
pub mod commit { pub mod commit {
pub static DETAILS_AUTHOR: &str = "Author: "; pub static DETAILS_AUTHOR: &str = "Author: ";
pub static DETAILS_COMMITTER: &str = "Committer: "; pub static DETAILS_COMMITTER: &str = "Committer: ";

View file

@ -271,11 +271,11 @@ impl Status {
{ {
self.diff.update(path, is_stage, diff)?; self.diff.update(path, is_stage, diff)?;
} else { } else {
self.diff.clear()?; self.diff.clear(true)?;
} }
} }
} else { } else {
self.diff.clear()?; self.diff.clear(false)?;
} }
Ok(()) Ok(())