Skip to content

Commit a54fbf7

Browse files
author
Stephan Dilly
committed
visualize pending load of a diff (#160)
1 parent ed730c2 commit a54fbf7

File tree

5 files changed

+27
-12
lines changed

5 files changed

+27
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77
## [Unreleased]
88

99
### Added
10+
- pending load of a diff is visualized better ([#160](https://github.com/extrawurst/gitui/issues/160))
1011
- 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))
1112
- commits can be tagged in revlog [[@cruessler](https://github.com/cruessler)] ([#103](https://github.com/extrawurst/gitui/issues/103))
1213

src/components/diff.rs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crossterm::event::Event;
1212
use std::{borrow::Cow, cell::Cell, cmp, path::Path};
1313
use tui::{
1414
backend::Backend,
15-
layout::{Alignment, Rect},
15+
layout::Rect,
1616
symbols,
1717
widgets::{Block, Borders, Paragraph, Text},
1818
Frame,
@@ -30,6 +30,7 @@ struct Current {
3030
///
3131
pub struct DiffComponent {
3232
diff: Option<FileDiff>,
33+
pending: bool,
3334
selection: usize,
3435
selected_hunk: Option<usize>,
3536
current_size: Cell<(u16, u16)>,
@@ -47,6 +48,7 @@ impl DiffComponent {
4748
focused: false,
4849
queue,
4950
current: Current::default(),
51+
pending: false,
5052
selected_hunk: None,
5153
diff: None,
5254
current_size: Cell::new((0, 0)),
@@ -67,12 +69,13 @@ impl DiffComponent {
6769
(self.current.path.clone(), self.current.is_stage)
6870
}
6971
///
70-
pub fn clear(&mut self) -> Result<()> {
72+
pub fn clear(&mut self, pending: bool) -> Result<()> {
7173
self.current = Current::default();
7274
self.diff = None;
7375
self.scroll_top.set(0);
7476
self.selection = 0;
7577
self.selected_hunk = None;
78+
self.pending = pending;
7679

7780
Ok(())
7881
}
@@ -83,6 +86,8 @@ impl DiffComponent {
8386
is_stage: bool,
8487
diff: FileDiff,
8588
) -> Result<()> {
89+
self.pending = false;
90+
8691
let hash = hash(&diff);
8792

8893
if self.current.hash != hash {
@@ -432,19 +437,24 @@ impl DrawableComponent for DiffComponent {
432437

433438
let title =
434439
format!("{}{}", strings::TITLE_DIFF, self.current.path);
440+
441+
let txt = if self.pending {
442+
vec![Text::Styled(
443+
Cow::from(strings::LOADING_TEXT),
444+
self.theme.text(false, false),
445+
)]
446+
} else {
447+
self.get_text(r.width, self.current_size.get().1)?
448+
};
449+
435450
f.render_widget(
436-
Paragraph::new(
437-
self.get_text(r.width, self.current_size.get().1)?
438-
.iter(),
439-
)
440-
.block(
451+
Paragraph::new(txt.iter()).block(
441452
Block::default()
442453
.title(title.as_str())
443454
.borders(Borders::ALL)
444455
.border_style(self.theme.block(self.focused))
445456
.title_style(self.theme.title(self.focused)),
446-
)
447-
.alignment(Alignment::Left),
457+
),
448458
r,
449459
);
450460

src/components/inspect_commit.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,12 @@ impl InspectCommitComponent {
222222
}
223223

224224
self.git_diff.request(diff_params)?;
225+
self.diff.clear(true)?;
226+
return Ok(());
225227
}
226228
}
227229

228-
self.diff.clear()?;
230+
self.diff.clear(false)?;
229231
}
230232

231233
Ok(())

src/strings.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ pub static HELP_TITLE: &str = "Help: all commands";
3838
pub static STASHING_FILES_TITLE: &str = "Files to Stash";
3939
pub static STASHING_OPTIONS_TITLE: &str = "Options";
4040

41+
pub static LOADING_TEXT: &str = "Loading ...";
42+
4143
pub mod commit {
4244
pub static DETAILS_AUTHOR: &str = "Author: ";
4345
pub static DETAILS_COMMITTER: &str = "Committer: ";

src/tabs/status.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,11 @@ impl Status {
271271
{
272272
self.diff.update(path, is_stage, diff)?;
273273
} else {
274-
self.diff.clear()?;
274+
self.diff.clear(true)?;
275275
}
276276
}
277277
} else {
278-
self.diff.clear()?;
278+
self.diff.clear(false)?;
279279
}
280280

281281
Ok(())

0 commit comments

Comments
 (0)