on master help sign in
feat(statusline): add option to show total line numbers in file (#3960)
c144cc0Joshua Pauline
book/src/configuration.md+1
@@ -93,6 +93,7 @@ The following statusline elements can be configured:
93| `file-name` | The path/name of the opened file |
93| `file-name` | The path/name of the opened file |
94| `file-encoding` | The encoding of the opened file if it differs from UTF-8 |
94| `file-encoding` | The encoding of the opened file if it differs from UTF-8 |
95| `file-line-ending` | The file line endings (CRLF or LF) |
95| `file-line-ending` | The file line endings (CRLF or LF) |
96+| `total-line-numbers` | The total line numbers of the opened file |
96| `file-type` | The type of the opened file |
97| `file-type` | The type of the opened file |
97| `diagnostics` | The number of warnings and/or errors |
98| `diagnostics` | The number of warnings and/or errors |
98| `selections` | The number of active selections |
99| `selections` | The number of active selections |
helix-term/src/ui/statusline.rs+10
@@ -144,6 +144,7 @@ where
144 helix_view::editor::StatusLineElement::Selections => render_selections,
144 helix_view::editor::StatusLineElement::Selections => render_selections,
145 helix_view::editor::StatusLineElement::Position => render_position,
145 helix_view::editor::StatusLineElement::Position => render_position,
146 helix_view::editor::StatusLineElement::PositionPercentage => render_position_percentage,
146 helix_view::editor::StatusLineElement::PositionPercentage => render_position_percentage,
147+ helix_view::editor::StatusLineElement::TotalLineNumbers => render_total_line_numbers,
147 helix_view::editor::StatusLineElement::Separator => render_separator,
148 helix_view::editor::StatusLineElement::Separator => render_separator,
148 helix_view::editor::StatusLineElement::Spacer => render_spacer,
149 helix_view::editor::StatusLineElement::Spacer => render_spacer,
149 }
150 }
@@ -276,6 +277,15 @@ where
276 );
277 );
277}
278}
278
279
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+
279fn render_position_percentage<F>(context: &mut RenderContext, write: F)
289fn render_position_percentage<F>(context: &mut RenderContext, write: F)
280where
290where
281 F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
291 F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
helix-view/src/editor.rs+3
@@ -331,6 +331,9 @@ pub enum StatusLineElement {
331 /// The cursor position as a percent of the total file
331 /// The cursor position as a percent of the total file
332 PositionPercentage,
332 PositionPercentage,
333
333
334+ /// The total line numbers of the current file
335+ TotalLineNumbers,
336+
334 /// A single space
337 /// A single space
335 Spacer,
338 Spacer,
336}
339}