Skip to content

Commit 03cf23a

Browse files
author
Stephan Dilly
committed
visualize pending load on status file list (closes #160)
1 parent 9d4972b commit 03cf23a

File tree

2 files changed

+68
-44
lines changed

2 files changed

+68
-44
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +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))
10+
- pending load of a diff/status is visualized ([#160](https://github.com/extrawurst/gitui/issues/160))
1111
- 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))
1212
- commits can be tagged in revlog [[@cruessler](https://github.com/cruessler)] ([#103](https://github.com/extrawurst/gitui/issues/103))
1313

src/components/filetree.rs

Lines changed: 67 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::{
99
components::{CommandInfo, Component},
1010
keys,
1111
queue::{InternalEvent, NeedsUpdate, Queue},
12-
strings::{commands, order},
12+
strings::{self, commands, order},
1313
ui,
1414
ui::style::SharedTheme,
1515
};
@@ -23,6 +23,7 @@ use tui::{backend::Backend, layout::Rect, widgets::Text, Frame};
2323
pub struct FileTreeComponent {
2424
title: String,
2525
tree: StatusTree,
26+
pending: bool,
2627
current_hash: u64,
2728
focused: bool,
2829
show_selection: bool,
@@ -48,11 +49,13 @@ impl FileTreeComponent {
4849
queue,
4950
theme,
5051
scroll_top: Cell::new(0),
52+
pending: true,
5153
}
5254
}
5355

5456
///
5557
pub fn update(&mut self, list: &[StatusItem]) -> Result<()> {
58+
self.pending = false;
5659
let new_hash = hash(list);
5760
if self.current_hash != new_hash {
5861
self.tree.update(list)?;
@@ -217,25 +220,58 @@ impl DrawableComponent for FileTreeComponent {
217220
f: &mut Frame<B>,
218221
r: Rect,
219222
) -> Result<()> {
220-
let selection_offset =
221-
self.tree.tree.items().iter().enumerate().fold(
222-
0,
223-
|acc, (idx, e)| {
224-
let visible = e.info.visible;
225-
let index_above_select =
226-
idx < self.tree.selection.unwrap_or(0);
227-
228-
if !visible && index_above_select {
229-
acc + 1
230-
} else {
231-
acc
232-
}
233-
},
223+
if self.pending {
224+
let items = vec![Text::Styled(
225+
Cow::from(strings::LOADING_TEXT),
226+
self.theme.text(false, false),
227+
)];
228+
229+
ui::draw_list(
230+
f,
231+
r,
232+
self.title.as_str(),
233+
items.into_iter(),
234+
None,
235+
self.focused,
236+
&self.theme,
234237
);
235-
236-
let items =
237-
self.tree.tree.items().iter().enumerate().filter_map(
238-
|(idx, e)| {
238+
} else {
239+
let selection_offset =
240+
self.tree.tree.items().iter().enumerate().fold(
241+
0,
242+
|acc, (idx, e)| {
243+
let visible = e.info.visible;
244+
let index_above_select =
245+
idx < self.tree.selection.unwrap_or(0);
246+
247+
if !visible && index_above_select {
248+
acc + 1
249+
} else {
250+
acc
251+
}
252+
},
253+
);
254+
255+
let select = self
256+
.tree
257+
.selection
258+
.map(|idx| idx.saturating_sub(selection_offset))
259+
.unwrap_or_default();
260+
let tree_height = r.height.saturating_sub(2) as usize;
261+
262+
self.scroll_top.set(ui::calc_scroll_top(
263+
self.scroll_top.get(),
264+
tree_height,
265+
select,
266+
));
267+
268+
let items = self
269+
.tree
270+
.tree
271+
.items()
272+
.iter()
273+
.enumerate()
274+
.filter_map(|(idx, e)| {
239275
Self::item_to_text(
240276
e,
241277
r.width,
@@ -246,31 +282,19 @@ impl DrawableComponent for FileTreeComponent {
246282
.map_or(false, |e| e == idx),
247283
&self.theme,
248284
)
249-
},
285+
})
286+
.skip(self.scroll_top.get());
287+
288+
ui::draw_list(
289+
f,
290+
r,
291+
self.title.as_str(),
292+
items,
293+
Some(select),
294+
self.focused,
295+
&self.theme,
250296
);
251-
252-
let select = self
253-
.tree
254-
.selection
255-
.map(|idx| idx.saturating_sub(selection_offset))
256-
.unwrap_or_default();
257-
let tree_height = r.height.saturating_sub(2) as usize;
258-
259-
self.scroll_top.set(ui::calc_scroll_top(
260-
self.scroll_top.get(),
261-
tree_height,
262-
select,
263-
));
264-
265-
ui::draw_list(
266-
f,
267-
r,
268-
self.title.as_str(),
269-
items.skip(self.scroll_top.get()),
270-
Some(select),
271-
self.focused,
272-
&self.theme,
273-
);
297+
}
274298

275299
Ok(())
276300
}

0 commit comments

Comments
 (0)