aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Pauline2022-10-03 14:54:00 +0000
committerGitHub2022-10-03 14:54:00 +0000
commitc144cc0b04c18d6749016773073a23b5e42d5804 (patch)
tree834abbfd1b6f3276a900d2650f82be4dea7ba5b2
parent519857d6323d272106e0b48f9a9a23ce066f53f9 (diff)
feat(statusline): add option to show total line numbers in file (#3960)
* feat(statusline): add option to show total line numbers in file * feat(line numbers): add config to doc book
-rw-r--r--book/src/configuration.md1
-rw-r--r--helix-term/src/ui/statusline.rs10
-rw-r--r--helix-view/src/editor.rs3
3 files changed, 14 insertions, 0 deletions
diff --git a/book/src/configuration.md b/book/src/configuration.md
index d44855c7..039d181c 100644
--- a/book/src/configuration.md
+++ b/book/src/configuration.md
@@ -93,6 +93,7 @@ The following statusline elements can be configured:
| `file-name` | The path/name of the opened file |
| `file-encoding` | The encoding of the opened file if it differs from UTF-8 |
| `file-line-ending` | The file line endings (CRLF or LF) |
+| `total-line-numbers` | The total line numbers of the opened file |
| `file-type` | The type of the opened file |
| `diagnostics` | The number of warnings and/or errors |
| `selections` | The number of active selections |
diff --git a/helix-term/src/ui/statusline.rs b/helix-term/src/ui/statusline.rs
index 9bbb268f..b0e8ec5d 100644
--- a/helix-term/src/ui/statusline.rs
+++ b/helix-term/src/ui/statusline.rs
@@ -144,6 +144,7 @@ where
helix_view::editor::StatusLineElement::Selections => render_selections,
helix_view::editor::StatusLineElement::Position => render_position,
helix_view::editor::StatusLineElement::PositionPercentage => render_position_percentage,
+ helix_view::editor::StatusLineElement::TotalLineNumbers => render_total_line_numbers,
helix_view::editor::StatusLineElement::Separator => render_separator,
helix_view::editor::StatusLineElement::Spacer => render_spacer,
}
@@ -276,6 +277,15 @@ where
);
}
+fn render_total_line_numbers<F>(context: &mut RenderContext, write: F)
+where
+ F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
+{
+ let total_line_numbers = context.doc.text().len_lines();
+
+ write(context, format!(" {} ", total_line_numbers), None);
+}
+
fn render_position_percentage<F>(context: &mut RenderContext, write: F)
where
F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs
index 70c49872..f3b0e26f 100644
--- a/helix-view/src/editor.rs
+++ b/helix-view/src/editor.rs
@@ -331,6 +331,9 @@ pub enum StatusLineElement {
/// The cursor position as a percent of the total file
PositionPercentage,
+ /// The total line numbers of the current file
+ TotalLineNumbers,
+
/// A single space
Spacer,
}