Skip to content

Commit 4860304

Browse files
0xfourzerofourpathwave
authored andcommitted
feat(statusline): add option to show total line numbers in file (helix-editor#3960)
* feat(statusline): add option to show total line numbers in file * feat(line numbers): add config to doc book
1 parent dccc161 commit 4860304

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

book/src/configuration.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
279289
fn render_position_percentage<F>(context: &mut RenderContext, write: F)
280290
where
281291
F: Fn(&mut RenderContext, String, Option<Style>) + Copy,

helix-view/src/editor.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

0 commit comments

Comments
 (0)