Browse Source

Use getch() directly to get Leader key suffix

Note: this change BREAKS because get_bm_loc() expects a char *key.
master
Arun Prakash Jana 6 years ago
parent
commit
48e64c2a79
No known key found for this signature in database GPG Key ID: A75979F35C080412
1 changed files with 68 additions and 80 deletions
  1. +68
    -80
      src/nnn.c

+ 68
- 80
src/nnn.c View File

@@ -354,7 +354,7 @@ static char * const utils[] = {
#define STR_NFTWFAIL_ID 0 #define STR_NFTWFAIL_ID 0
#define STR_NOHOME_ID 1 #define STR_NOHOME_ID 1
#define STR_INPUT_ID 2 #define STR_INPUT_ID 2
#define STR_INVBM_ID 3 #define STR_INVBM_KEY 3
#define STR_COPY_ID 4 #define STR_COPY_ID 4
#define STR_DATE_ID 5 #define STR_DATE_ID 5


@@ -437,13 +437,13 @@ static void printerr(int linenum)
static void printprompt(const char *str) static void printprompt(const char *str)
{ {
clearprompt(); clearprompt();
if (str) printw(str);
printw(str);
} }


static int get_input(const char *prompt) static int get_input(const char *prompt)
{ {
printprompt(prompt); if (prompt)
printprompt(prompt);
cleartimeout(); cleartimeout();
int r = getch(); int r = getch();
settimeout(); settimeout();
@@ -1221,7 +1221,7 @@ end:
} }


/* Show a prompt with input string and return the changes */ /* Show a prompt with input string and return the changes */
static char *xreadline(char *fname, char *prompt, bool single) static char *xreadline(char *fname, char *prompt)
{ {
size_t len, pos; size_t len, pos;
int x, y, r; int x, y, r;
@@ -1229,12 +1229,6 @@ static char *xreadline(char *fname, char *prompt, bool single)
static wchar_t * const buf = (wchar_t *)g_buf; static wchar_t * const buf = (wchar_t *)g_buf;


cleartimeout(); cleartimeout();
if (single) {
buf[0] = getch();
len = 1;
goto END;
}

printprompt(prompt); printprompt(prompt);


if (fname) { if (fname) {
@@ -2728,74 +2722,68 @@ nochange:
setdirwatch(); setdirwatch();
goto begin; goto begin;
case SEL_LEADER: case SEL_LEADER:
tmp = xreadline(NULL, "key: ", TRUE); fd = get_input(NULL);
if (tmp == NULL || tmp[0] == '\0') switch (fd) {
break; case 'q': //fallthrough

case '~': //fallthrough
/* Interpret ~, - and & keys */ case '-': //fallthrough
if (tmp[1] == '\0') { case '&':
switch (tmp[0]) { presel = (char)fd;
case 'q': goto nochange;
case '~': //fallthrough case '>':
case '-': //fallthrough case '.':
case '&': case '<':
presel = tmp[0]; case ',':
goto nochange; r = cfg.curctx;
case '>': if (fd == '>' || fd == '.')
case '.': do
case '<': (r == MAX_CTX - 1) ? (r = 0) : ++r;
case ',': while (!g_ctx[r].c_cfg.ctxactive);
r = cfg.curctx; else
if (tmp[0] == '>' || tmp[0] == '.') do
do (r == 0) ? (r = MAX_CTX - 1) : --r;
(r == MAX_CTX - 1) ? (r = 0) : ++r; while (!g_ctx[r].c_cfg.ctxactive); //fallthrough
while (!g_ctx[r].c_cfg.ctxactive); fd = '1' + r; //fallthrough
else case '1': //fallthrough
do case '2': //fallthrough
(r == 0) ? (r = MAX_CTX - 1) : --r; case '3': //fallthrough
while (!g_ctx[r].c_cfg.ctxactive); //fallthrough case '4':
tmp[0] = '1' + r; //fallthrough r = fd - '1'; /* Save the next context id */
case '1': //fallthrough if (cfg.curctx == r)
case '2': //fallthrough continue;
case '3': //fallthrough
case '4':
r = tmp[0] - '1'; /* Save the next context id */
if (cfg.curctx == r)
continue;


g_crc = 0; g_crc = 0;

/* Save current context */
xstrlcpy(g_ctx[cfg.curctx].c_name, dents[cur].name, NAME_MAX + 1);
g_ctx[cfg.curctx].c_cfg = cfg;

if (g_ctx[r].c_cfg.ctxactive) /* Switch to saved context */
cfg = g_ctx[r].c_cfg;
else { /* Setup a new context from current context */
g_ctx[r].c_cfg.ctxactive = 1;
xstrlcpy(g_ctx[r].c_path, path, PATH_MAX);
xstrlcpy(g_ctx[r].c_init, path, PATH_MAX);
g_ctx[r].c_last[0] = '\0';
xstrlcpy(g_ctx[r].c_name, dents[cur].name, NAME_MAX + 1);
g_ctx[r].c_cfg = cfg;
xstrlcpy(g_ctx[r].c_fltr, hfltr, DOT_FILTER_LEN);
}


/* Reset the pointers */ /* Save current context */
path = g_ctx[r].c_path; xstrlcpy(g_ctx[cfg.curctx].c_name, dents[cur].name, NAME_MAX + 1);
ipath = g_ctx[r].c_init; g_ctx[cfg.curctx].c_cfg = cfg;
lastdir = g_ctx[r].c_last;
lastname = g_ctx[r].c_name;
hfltr = g_ctx[r].c_fltr;


cfg.curctx = r; if (g_ctx[r].c_cfg.ctxactive) /* Switch to saved context */
setdirwatch(); cfg = g_ctx[r].c_cfg;
goto begin; else { /* Setup a new context from current context */
g_ctx[r].c_cfg.ctxactive = 1;
xstrlcpy(g_ctx[r].c_path, path, PATH_MAX);
xstrlcpy(g_ctx[r].c_init, path, PATH_MAX);
g_ctx[r].c_last[0] = '\0';
xstrlcpy(g_ctx[r].c_name, dents[cur].name, NAME_MAX + 1);
g_ctx[r].c_cfg = cfg;
xstrlcpy(g_ctx[r].c_fltr, hfltr, DOT_FILTER_LEN);
} }

/* Reset the pointers */
path = g_ctx[r].c_path;
ipath = g_ctx[r].c_init;
lastdir = g_ctx[r].c_last;
lastname = g_ctx[r].c_name;
hfltr = g_ctx[r].c_fltr;

cfg.curctx = r;
setdirwatch();
goto begin;
} }


if (get_bm_loc(tmp, newpath) == NULL) { if (get_bm_loc((char)fd, newpath) == NULL) {
printmsg(messages[STR_INVBM_ID]); printmsg(messages[STR_INVBM_KEY]);
goto nochange; goto nochange;
} }


@@ -3114,13 +3102,13 @@ nochange:
case SEL_LAUNCH: // fallthrough case SEL_LAUNCH: // fallthrough
case SEL_NEW: case SEL_NEW:
if (sel == SEL_OPEN) if (sel == SEL_OPEN)
tmp = xreadline(NULL, "open with: ", FALSE); tmp = xreadline(NULL, "open with: ");
else if (sel == SEL_LAUNCH) else if (sel == SEL_LAUNCH)
tmp = xreadline(NULL, "launch: ", FALSE); tmp = xreadline(NULL, "launch: ");
else if (sel == SEL_ARCHIVE) else if (sel == SEL_ARCHIVE)
tmp = xreadline(dents[cur].name, "name: ", FALSE); tmp = xreadline(dents[cur].name, "name: ");
else else
tmp = xreadline(NULL, "name: ", FALSE); tmp = xreadline(NULL, "name: ");


if (tmp == NULL || tmp[0] == '\0') if (tmp == NULL || tmp[0] == '\0')
break; break;
@@ -3226,7 +3214,7 @@ nochange:
if (!ndents) if (!ndents)
break; break;


tmp = xreadline(dents[cur].name, "", FALSE); tmp = xreadline(dents[cur].name, "");
if (tmp == NULL || tmp[0] == '\0') if (tmp == NULL || tmp[0] == '\0')
break; break;


@@ -3295,7 +3283,7 @@ nochange:
if (getenv("NNN_MULTISCRIPT")) { if (getenv("NNN_MULTISCRIPT")) {
size_t _len = xstrlcpy(newpath, tmp, PATH_MAX); size_t _len = xstrlcpy(newpath, tmp, PATH_MAX);


tmp = xreadline(NULL, "script suffix: ", FALSE); tmp = xreadline(NULL, "script suffix: ");
if (tmp && tmp[0]) if (tmp && tmp[0])
xstrlcpy(newpath + _len - 1, tmp, PATH_MAX - _len); xstrlcpy(newpath + _len - 1, tmp, PATH_MAX - _len);


@@ -3474,7 +3462,7 @@ int main(int argc, char *argv[])


if (ipath) { /* Open a bookmark directly */ if (ipath) { /* Open a bookmark directly */
if (get_bm_loc(ipath, cwd) == NULL) { if (get_bm_loc(ipath, cwd) == NULL) {
fprintf(stderr, "%s\n", messages[STR_INVBM_ID]); fprintf(stderr, "%s\n", messages[STR_INVBM_KEY]);
exit(1); exit(1);
} }




||||||
x
 
000:0
Loading…
Cancel
Save