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 linenumber when in SEL_JUMP #1804

Closed
wants to merge 1 commit into from
Closed
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
11 changes: 6 additions & 5 deletions patches/gitstatus/mainline.diff
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@ index 83ecdb90..4397944a 100644
/* TYPE DEFINITIONS */
typedef unsigned int uint_t;
typedef unsigned char uchar_t;
@@ -294,6 +313,7 @@ typedef struct entry {
uid_t uid; /* 4 bytes */
gid_t gid; /* 4 bytes */
@@ -307,6 +326,7 @@ typedef struct entry {
gid_t gid; /* 4 bytes */
#endif
+ char git_status[2][5];
int ncount;
+ char git_status[2][5];
} *pEntry;

/* Selection marker */

@@ -349,6 +369,7 @@ typedef struct {
uint_t cliopener : 1; /* All-CLI app opener */
uint_t waitedit : 1; /* For ops that can't be detached, used EDITOR */
Expand Down
78 changes: 51 additions & 27 deletions src/nnn.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ typedef struct entry {
uid_t uid; /* 4 bytes */
gid_t gid; /* 4 bytes */
#endif
int ncount;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This increases memory usage per file. Why do we need to store this and not calculate on the fly?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simpler approach in #1808 which doesn't require storing counts.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already merged.

} *pEntry;

/* Selection marker */
Expand Down Expand Up @@ -519,6 +520,9 @@ alignas(max_align_t) static char g_pipepath[TMP_LEN_MAX];
/* Non-persistent runtime states */
static runstate g_state;

/* Used for SEL_JUMP */
static bool show_linenumber;

/* Options to identify file MIME */
#if defined(__APPLE__)
#define FILE_MIME_OPTS "-bIL"
Expand Down Expand Up @@ -4251,6 +4255,14 @@ static void printent(const struct entry *ent, uint_t namecols, bool sel)
attroff(attrs);
}

if (show_linenumber) {
if (ent->ncount == cur+1 && sel) {
printw("%4d", ent->ncount);
} else{
printw("%+4d", ent->ncount);
}
}

attrs = 0;

uchar_t color_pair = get_color_pair_name_ind(ent, &ind, &attrs);
Expand Down Expand Up @@ -6124,32 +6136,6 @@ static void handle_screen_move(enum action sel)
move_cursor(curscroll, 1);
curscroll -= onscreen >> 1;
break;
case SEL_JUMP:
{
char *input = xreadline(NULL, "jump (+n/-n/n): ");

if (!input || !*input)
break;
if (input[0] == '-') {
cur -= atoi(input + 1);
if (cur < 0)
cur = 0;
} else if (input[0] == '+') {
cur += atoi(input + 1);
if (cur >= ndents)
cur = ndents - 1;
} else {
int index = atoi(input);

if ((index < 1) || (index > ndents))
break;
cur = index - 1;
}
onscreen = xlines - 4;
move_cursor(cur, 1);
curscroll -= onscreen >> 1;
break;
}
case SEL_HOME:
move_cursor(0, 1);
break;
Expand Down Expand Up @@ -6698,6 +6684,14 @@ static void redraw(char *path)
if (len)
findmarkentry(len, &pdents[i]);

// relative numbering
pdents[i].ncount = i-cur;
if (i-cur == 0)
pdents[i].ncount = cur + 1;

// absolute numbering
//pdents[i].ncount = i;

printent(&pdents[i], ncols, i == cur);
}

Expand Down Expand Up @@ -7251,13 +7245,43 @@ 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:
{
show_linenumber=true;
redraw(path);
show_linenumber=false;
char *input = xreadline(NULL, "jump (+n/-n/n): ");

if (!input || !*input) {
redraw(path);
break;
}
if (input[0] == '-') {
cur -= atoi(input + 1);
if (cur < 0)
cur = 0;
} else if (input[0] == '+') {
cur += atoi(input + 1);
if (cur >= ndents)
cur = ndents - 1;
} else {
int index = atoi(input);

if ((index < 1) || (index > ndents))
break;
cur = index - 1;
}
int onscreen = xlines - 4;
move_cursor(cur, 1);
curscroll -= onscreen >> 1;
break;
}
case SEL_CDHOME: // fallthrough
case SEL_CDBEGIN: // fallthrough
case SEL_CDLAST: // fallthrough
Expand Down
Loading