Skip to content

Commit

Permalink
display the percentage through the file that the cursor is at
Browse files Browse the repository at this point in the history
A modeline may look like, for instance:

	NORMAL  [17%] src/presenters/mod.rs

as opposed to the previous:

	NORMAL  src/presenters/mod.rs

This is a small & slightly opinionated change.
  • Loading branch information
oldaccountdeadname committed Oct 23, 2021
1 parent 94f94cc commit add8bbc
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/presenters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,26 @@ fn path_as_title(path: &Path) -> String {
}

fn current_buffer_status_line_data(workspace: &mut Workspace) -> StatusLineData {
let modified = workspace.current_buffer().map(|b| b.modified()).unwrap_or(false);
let buffer = workspace.current_buffer();
let modified = buffer.as_ref().map(|b| b.modified()).unwrap_or(false);

let line_perc = buffer.map(|b| {
let line_total = b.line_count();
let line_at = b.cursor.position.line + 1;
let line_perc = (line_at * 100) / line_total;
format!("[{:2}%]", line_perc)
}).unwrap_or(String::new());

let (content, style) = workspace.current_buffer_path().map(|path| {
let mut title = path_as_title(path);
let mut style = Style::Default;

if modified {
title.push('*');
(title, Style::Bold)
} else {
(title, Style::Default)
style = Style::Bold;
}

(format!(" {}{}", line_perc, title), style)
}).unwrap_or((String::new(), Style::Default));

StatusLineData {
Expand Down

0 comments on commit add8bbc

Please sign in to comment.