on master help sign in
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

commitc144cc0b04c18d6749016773073a23b5e42d5804 authorJoshua Pauline <36560907+joshpauline@users.noreply.github.com> dateTue 4 Oct 2022, 01:54 (4 years ago) parent519857d
3 files changed+14
book/src/configuration.md+1 helix-term/src/ui/statusline.rs+10 helix-view/src/editor.rs+3
book/src/configuration.md+1
@@ -93,6 +93,7 @@ The following statusline elements can be configured:
9393| `file-name` | The path/name of the opened file |
9494| `file-encoding` | The encoding of the opened file if it differs from UTF-8 |
9595| `file-line-ending` | The file line endings (CRLF or LF) |
96+| `total-line-numbers` | The total line numbers of the opened file |
9697| `file-type` | The type of the opened file |
9798| `diagnostics` | The number of warnings and/or errors |
9899| `selections` | The number of active selections |
helix-term/src/ui/statusline.rs+10
@@ -144,6 +144,7 @@ where
144144 helix_view::editor::StatusLineElement::Selections => render_selections,
145145 helix_view::editor::StatusLineElement::Position => render_position,
146146 helix_view::editor::StatusLineElement::PositionPercentage => render_position_percentage,
147+ helix_view::editor::StatusLineElement::TotalLineNumbers => render_total_line_numbers,
147148 helix_view::editor::StatusLineElement::Separator => render_separator,
148149 helix_view::editor::StatusLineElement::Spacer => render_spacer,
149150 }
@@ -276,6 +277,15 @@ where
276277 );
277278}
278279
280+fn render_total_line_numbers<F>(context: &mut RenderContext, write: F)
281+where
282+ F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
283+{
284+ let total_line_numbers = context.doc.text().len_lines();
285+
286+ write(context, format!(" {} ", total_line_numbers), None);
287+}
288+
279289fn render_position_percentage<F>(context: &mut RenderContext, write: F)
280290where
281291 F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
helix-view/src/editor.rs+3
@@ -331,6 +331,9 @@ pub enum StatusLineElement {
331331 /// The cursor position as a percent of the total file
332332 PositionPercentage,
333333
334+ /// The total line numbers of the current file
335+ TotalLineNumbers,
336+
334337 /// A single space
335338 Spacer,
336339}