Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show relative line numbering when jumping #1808

Merged
merged 1 commit into from
Feb 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading