Skip to content

Commit

Permalink
only show cursor percentage indicator when file is larger than height
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
oldaccountdeadname committed Jan 23, 2022
1 parent d6302d9 commit 852da93
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/presenters/modes/normal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ use git2::Repository;
use crate::view::{Colors, StatusLineData, Style, View};

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

if let Some(buf) = workspace.current_buffer() {
let line_count = buf.line_count();

// Draw the visible set of tokens to the terminal.
let data = buf.data();
presenter.print_buffer(buf, &data, None, None)?;
Expand All @@ -25,6 +28,15 @@ pub fn display(workspace: &mut Workspace, view: &mut View, repo: &Option<Reposit
Colors::Inverted
};

let mut right_widgets = vec![
git_status_line_data(&repo, &buf.path),
percentage_cursor_indicator_line_data(workspace),
];

if line_count <= height {
right_widgets.pop();
}

// Build the status line mode and buffer title display.
presenter.print_status_line(
&[
Expand All @@ -35,10 +47,7 @@ pub fn display(workspace: &mut Workspace, view: &mut View, repo: &Option<Reposit
},
buffer_status,
],
&[
git_status_line_data(&repo, &buf.path),
percentage_cursor_indicator_line_data(workspace),
],
&right_widgets,
);

presenter.present();
Expand Down
4 changes: 4 additions & 0 deletions src/view/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ impl View {
Presenter::new(self)
}

pub fn height(&self) -> usize {
self.terminal.height()
}

///
/// Scrollable region delegation methods.
///
Expand Down

0 comments on commit 852da93

Please sign in to comment.