Skip to content

Commit

Permalink
show relative line numbering when jumping
Browse files Browse the repository at this point in the history
Co-authored-by: Darukutsu <darupeter@pm.me>
Closes: #1804
Closes: #1708
  • Loading branch information
N-R-K and Darukutsu committed Feb 3, 2024
1 parent e76d7bb commit 0738f39
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 17 deletions.
19 changes: 12 additions & 7 deletions patches/namefirst/mainline.diff
Original file line number Diff line number Diff line change
Expand Up @@ -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;
-
Expand All @@ -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
Expand Down Expand Up @@ -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();
}

Expand Down
8 changes: 4 additions & 4 deletions patches/restorepreview/mainline.diff
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
26 changes: 20 additions & 6 deletions src/nnn.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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;

Expand All @@ -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);
Expand Down Expand Up @@ -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 */
Expand All @@ -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)
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -7251,13 +7258,20 @@ static bool browse(char *ipath, const char *session, int pkey)
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
Expand Down

0 comments on commit 0738f39

Please sign in to comment.