Skip to content

Commit

Permalink
feat: add relative line numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
metiftikci committed Oct 25, 2023
1 parent 9366650 commit a0a5760
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/screen/print_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ impl Screen {

for y in 0..buffer.area.height {
let row_index = buffer.scroll.y + y as usize;
let relative_line_number = if row_index == buffer.cursor.y {
row_index + 1
} else if row_index < buffer.cursor.y {
buffer.cursor.y - row_index
} else {
row_index - buffer.cursor.y
};
match buffer.get_line_visible_text(row_index) {
Ok(text) => {
// TODO: Move this and print in separate functions
Expand All @@ -96,7 +103,7 @@ impl Screen {
buffer.area.x,
&format!(
" {:>1$} ",
row_index + 1,
relative_line_number,
buffer.info_area.width as usize - 2
),
Style::new(T.info_column_fg, T.info_column_bg),
Expand Down

0 comments on commit a0a5760

Please sign in to comment.