Skip to content

Commit 852da93

Browse files
only show cursor percentage indicator when file is larger than height
This modifies the display function in normal mode without changing the logic to gather the percentage, and should make the statusline a bit cleaner on small files.
1 parent d6302d9 commit 852da93

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/presenters/modes/normal.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@ use git2::Repository;
1010
use crate::view::{Colors, StatusLineData, Style, View};
1111

1212
pub fn display(workspace: &mut Workspace, view: &mut View, repo: &Option<Repository>) -> Result<()> {
13+
let height = view.height();
1314
let mut presenter = view.build_presenter()?;
1415
let buffer_status = current_buffer_status_line_data(workspace);
1516

1617
if let Some(buf) = workspace.current_buffer() {
18+
let line_count = buf.line_count();
19+
1720
// Draw the visible set of tokens to the terminal.
1821
let data = buf.data();
1922
presenter.print_buffer(buf, &data, None, None)?;
@@ -25,6 +28,15 @@ pub fn display(workspace: &mut Workspace, view: &mut View, repo: &Option<Reposit
2528
Colors::Inverted
2629
};
2730

31+
let mut right_widgets = vec![
32+
git_status_line_data(&repo, &buf.path),
33+
percentage_cursor_indicator_line_data(workspace),
34+
];
35+
36+
if line_count <= height {
37+
right_widgets.pop();
38+
}
39+
2840
// Build the status line mode and buffer title display.
2941
presenter.print_status_line(
3042
&[
@@ -35,10 +47,7 @@ pub fn display(workspace: &mut Workspace, view: &mut View, repo: &Option<Reposit
3547
},
3648
buffer_status,
3749
],
38-
&[
39-
git_status_line_data(&repo, &buf.path),
40-
percentage_cursor_indicator_line_data(workspace),
41-
],
50+
&right_widgets,
4251
);
4352

4453
presenter.present();

src/view/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ impl View {
7070
Presenter::new(self)
7171
}
7272

73+
pub fn height(&self) -> usize {
74+
self.terminal.height()
75+
}
76+
7377
///
7478
/// Scrollable region delegation methods.
7579
///

0 commit comments

Comments
 (0)