Skip to content

Commit

Permalink
display precentage through file on the right
Browse files Browse the repository at this point in the history
This only applies to normal mode, and is a straightforward extension of
ff0dc68's modifications.
  • Loading branch information
oldaccountdeadname committed Jan 23, 2022
1 parent ff0dc68 commit d7fbd47
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
25 changes: 17 additions & 8 deletions src/presenters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@ fn current_buffer_status_line_data(workspace: &mut Workspace) -> StatusLineData
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;
Expand All @@ -30,7 +23,7 @@ fn current_buffer_status_line_data(workspace: &mut Workspace) -> StatusLineData
style = Style::Bold;
}

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

StatusLineData {
Expand All @@ -40,6 +33,21 @@ fn current_buffer_status_line_data(workspace: &mut Workspace) -> StatusLineData
}
}

fn percentage_cursor_indicator_line_data(workspace: &mut Workspace) -> StatusLineData {
let content = workspace.current_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());

StatusLineData {
content,
style: Style::Default,
colors: Colors::Default,
}
}

fn git_status_line_data(repo: &Option<Repository>, path: &Option<PathBuf>) -> StatusLineData {
// Build a display value for the current buffer's git status.
let mut content = String::new();
Expand All @@ -61,6 +69,7 @@ fn git_status_line_data(repo: &Option<Repository>, path: &Option<PathBuf>) -> St
colors: Colors::Focused,
}
}

fn presentable_status(status: &Status) -> &str {
if status.contains(git2::Status::WT_NEW) {
if status.contains(git2::Status::INDEX_NEW) {
Expand Down
7 changes: 6 additions & 1 deletion src/presenters/modes/normal.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
use crate::errors::*;
use scribe::Workspace;
use scribe::buffer::Position;
use crate::presenters::{current_buffer_status_line_data, git_status_line_data};
use crate::presenters::{
current_buffer_status_line_data,
git_status_line_data,
percentage_cursor_indicator_line_data
};
use git2::Repository;
use crate::view::{Colors, StatusLineData, Style, View};

Expand Down Expand Up @@ -33,6 +37,7 @@ pub fn display(workspace: &mut Workspace, view: &mut View, repo: &Option<Reposit
],
&[
git_status_line_data(&repo, &buf.path),
percentage_cursor_indicator_line_data(workspace),
],
);

Expand Down

0 comments on commit d7fbd47

Please sign in to comment.