From 0738f39cf040287eab03b52474c974907ea53f97 Mon Sep 17 00:00:00 2001 From: NRK Date: Sat, 3 Feb 2024 09:45:46 +0000 Subject: [PATCH] show relative line numbering when jumping Co-authored-by: Darukutsu Closes: https://github.com/jarun/nnn/pull/1804 Closes: https://github.com/jarun/nnn/discussions/1708 --- patches/namefirst/mainline.diff | 19 ++++++++++++------- patches/restorepreview/mainline.diff | 8 ++++---- src/nnn.c | 26 ++++++++++++++++++++------ 3 files changed, 36 insertions(+), 17 deletions(-) diff --git a/patches/namefirst/mainline.diff b/patches/namefirst/mainline.diff index 797081f8..cb3f3ff8 100644 --- a/patches/namefirst/mainline.diff +++ b/patches/namefirst/mainline.diff @@ -71,9 +71,9 @@ index f8a2c58..9802a1f 100644 } static off_t get_size(off_t size, off_t *pval, int comp) -@@ -4134,33 +4141,7 @@ static uchar_t get_color_pair_name_ind(const struct entry *ent, char *pind, int - static void printent(const struct entry *ent, uint_t namecols, bool sel) +@@ -4228,38 +4235,13 @@ static void printent(int pdents_index, uint_t namecols, bool sel) { + const struct entry *ent = &pdents[pdents_index]; char ind = '\0'; - int attrs; - @@ -99,14 +99,19 @@ index f8a2c58..9802a1f 100644 - if (attrs) - attroff(attrs); - } -- ++ int attrs = 0, namelen; + + if (g_state.showlines) { + ptrdiff_t rel_num = pdents_index - cur; + printw(rel_num == 0 ? "%4td" : "%+4td", rel_num); + } + - attrs = 0; - -+ int attrs = 0, namelen; uchar_t color_pair = get_color_pair_name_ind(ent, &ind, &attrs); addch((ent->flags & FILE_SELECTED) ? '+' | A_REVERSE | A_BOLD : ' '); -@@ -4185,15 +4166,40 @@ static void printent(const struct entry *ent, uint_t namecols, bool sel) +@@ -4284,15 +4266,40 @@ static void printent(int pdents_index, uint_t namecols, bool sel) ++namecols; #ifndef NOLC @@ -149,8 +154,8 @@ index f8a2c58..9802a1f 100644 + attroff(attrs); } - static void savecurctx(char *path, char *curname, int nextctx) -@@ -6356,26 +6362,19 @@ static void statusbar(char *path) + /** +@@ -6527,26 +6534,19 @@ static void statusbar(char *path) tocursor(); } diff --git a/patches/restorepreview/mainline.diff b/patches/restorepreview/mainline.diff index cd2f49df..a1d6b791 100644 --- a/patches/restorepreview/mainline.diff +++ b/patches/restorepreview/mainline.diff @@ -10,13 +10,13 @@ diff --git a/src/nnn.c b/src/nnn.c index 0388b23c..66d3316a 100644 --- a/src/nnn.c +++ b/src/nnn.c -@@ -390,7 +390,8 @@ typedef struct { - uint_t uidgid : 1; /* Show owner and group info */ +@@ -391,7 +391,8 @@ typedef struct { uint_t usebsdtar : 1; /* Use bsdtar as default archive utility */ uint_t xprompt : 1; /* Use native prompt instead of readline prompt */ -- uint_t reserved : 4; /* Adjust when adding/removing a field */ + uint_t showlines : 1; /* Show line numbers */ +- uint_t reserved : 3; /* Adjust when adding/removing a field */ + uint_t previewer : 1; /* Run state of previewer */ -+ uint_t reserved : 3; /* Adjust when adding/removing a field */ ++ uint_t reserved : 2; /* Adjust when adding/removing a field */ } runstate; /* Contexts or workspaces */ diff --git a/src/nnn.c b/src/nnn.c index 77829dc6..d0938b99 100644 --- a/src/nnn.c +++ b/src/nnn.c @@ -390,7 +390,8 @@ typedef struct { uint_t uidgid : 1; /* Show owner and group info */ uint_t usebsdtar : 1; /* Use bsdtar as default archive utility */ uint_t xprompt : 1; /* Use native prompt instead of readline prompt */ - uint_t reserved : 4; /* Adjust when adding/removing a field */ + uint_t showlines : 1; /* Show line numbers */ + uint_t reserved : 3; /* Adjust when adding/removing a field */ } runstate; /* Contexts or workspaces */ @@ -4223,8 +4224,9 @@ static uchar_t get_color_pair_name_ind(const struct entry *ent, char *pind, int return C_UND; } -static void printent(const struct entry *ent, uint_t namecols, bool sel) +static void printent(int pdents_index, uint_t namecols, bool sel) { + const struct entry *ent = &pdents[pdents_index]; char ind = '\0'; int attrs; @@ -4251,6 +4253,11 @@ static void printent(const struct entry *ent, uint_t namecols, bool sel) attroff(attrs); } + if (g_state.showlines) { + ptrdiff_t rel_num = pdents_index - cur; + printw(rel_num == 0 ? "%4td" : "%+4td", rel_num); + } + attrs = 0; uchar_t color_pair = get_color_pair_name_ind(ent, &ind, &attrs); @@ -6559,7 +6566,7 @@ static void draw_line(int ncols) move(2 + last - curscroll, 0); macos_icons_hack(); - printent(&pdents[last], ncols, FALSE); + printent(last, ncols, FALSE); if (g_state.oldcolor && (pdents[cur].flags & DIR_OR_DIRLNK)) { if (!dir) {/* First file is not a directory */ @@ -6573,7 +6580,7 @@ static void draw_line(int ncols) move(2 + cur - curscroll, 0); macos_icons_hack(); - printent(&pdents[cur], ncols, TRUE); + printent(cur, ncols, TRUE); /* Must reset e.g. no files in dir */ if (dir) @@ -6698,7 +6705,7 @@ static void redraw(char *path) if (len) findmarkentry(len, &pdents[i]); - printent(&pdents[i], ncols, i == cur); + printent(i, ncols, i == cur); } /* Must reset e.g. no files in dir */ @@ -7251,13 +7258,20 @@ nochange: case SEL_HOME: // fallthrough case SEL_END: // fallthrough case SEL_FIRST: // fallthrough - case SEL_JUMP: // fallthrough case SEL_YOUNG: if (ndents) { g_state.move = 1; handle_screen_move(sel); } break; + case SEL_JUMP: + if (ndents) { + g_state.showlines = 1; + redraw(path); + handle_screen_move(sel); + g_state.showlines = 0; + } + break; case SEL_CDHOME: // fallthrough case SEL_CDBEGIN: // fallthrough case SEL_CDLAST: // fallthrough