aboutsummaryrefslogtreecommitdiff
path: root/ui-curses.c
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2015-04-03 18:39:22 +0200
committerMarc André Tanner <mat@brain-dump.org>2015-04-03 23:55:22 +0200
commitca222a7cc0d5a55312d96000a617e11d7a9996a1 (patch)
treee5aee5e31ac06ff8bc81d587687ae874602577d2 /ui-curses.c
parent9915b9fd0b8e59bda9e334eb9485c473b06055c9 (diff)
downloadvis-ca222a7cc0d5a55312d96000a617e11d7a9996a1.tar.gz
vis-ca222a7cc0d5a55312d96000a617e11d7a9996a1.tar.xz
Add option to display relative line numbers
:set rnu Based on a patch by Sebastian Götte.
Diffstat (limited to 'ui-curses.c')
-rw-r--r--ui-curses.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/ui-curses.c b/ui-curses.c
index 4b351e5..3cab014 100644
--- a/ui-curses.c
+++ b/ui-curses.c
@@ -197,10 +197,19 @@ static void ui_window_draw_sidebar(UiCursesWin *win, const Line *line) {
} else {
int i = 0;
size_t prev_lineno = 0;
+ size_t cursor_lineno = window_cursor_getpos(win->view).line;
werase(win->winside);
for (const Line *l = line; l; l = l->next, i++) {
- if (l->lineno != prev_lineno)
- mvwprintw(win->winside, i, 0, "%*u", sidebar_width-1, l->lineno);
+ if (l->lineno != prev_lineno) {
+ if (win->options & UI_OPTION_LINE_NUMBERS_ABSOLUTE) {
+ mvwprintw(win->winside, i, 0, "%*u", sidebar_width-1, l->lineno);
+ } else if (win->options & UI_OPTION_LINE_NUMBERS_RELATIVE) {
+ size_t rel = l->lineno > cursor_lineno ?
+ l->lineno - cursor_lineno :
+ cursor_lineno - l->lineno;
+ mvwprintw(win->winside, i, 0, "%*u", sidebar_width-1, rel);
+ }
+ }
prev_lineno = l->lineno;
}
mvwvline(win->winside, 0, sidebar_width-1, ACS_VLINE, win->height-1);
@@ -338,6 +347,8 @@ static void ui_window_cursor_to(UiWin *w, int x, int y) {
UiCursesWin *win = (UiCursesWin*)w;
wmove(win->win, y, x);
ui_window_draw_status(w);
+ if (win->options & UI_OPTION_LINE_NUMBERS_RELATIVE)
+ ui_window_draw_sidebar(win, window_lines_get(win->view));
}
static void ui_window_draw_text(UiWin *w, const Line *line) {
@@ -386,6 +397,7 @@ static void ui_window_options(UiWin *w, enum UiOption options) {
}
break;
case UI_OPTION_LINE_NUMBERS_ABSOLUTE:
+ case UI_OPTION_LINE_NUMBERS_RELATIVE:
if (!win->winside)
win->winside = newwin(1, 1, 1, 1);
break;