Use getch() directly to get Leader key suffix

Note: this change BREAKS because get_bm_loc() expects a char *key.
This commit is contained in:
Arun Prakash Jana 2018-11-12 23:05:57 +05:30
parent 07e643b10f
commit 48e64c2a79
No known key found for this signature in database
GPG key ID: A75979F35C080412

148
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
case '-': //fallthrough
case '&':
presel = (char)fd;
goto nochange;
case '>':
case '.':
case '<':
case ',':
r = cfg.curctx;
if (fd == '>' || fd == '.')
do
(r == MAX_CTX - 1) ? (r = 0) : ++r;
while (!g_ctx[r].c_cfg.ctxactive);
else
do
(r == 0) ? (r = MAX_CTX - 1) : --r;
while (!g_ctx[r].c_cfg.ctxactive); //fallthrough
fd = '1' + r; //fallthrough
case '1': //fallthrough
case '2': //fallthrough
case '3': //fallthrough
case '4':
r = fd - '1'; /* Save the next context id */
if (cfg.curctx == r)
continue;
/* Interpret ~, - and & keys */ g_crc = 0;
if (tmp[1] == '\0') {
switch (tmp[0]) {
case 'q':
case '~': //fallthrough
case '-': //fallthrough
case '&':
presel = tmp[0];
goto nochange;
case '>':
case '.':
case '<':
case ',':
r = cfg.curctx;
if (tmp[0] == '>' || tmp[0] == '.')
do
(r == MAX_CTX - 1) ? (r = 0) : ++r;
while (!g_ctx[r].c_cfg.ctxactive);
else
do
(r == 0) ? (r = MAX_CTX - 1) : --r;
while (!g_ctx[r].c_cfg.ctxactive); //fallthrough
tmp[0] = '1' + r; //fallthrough
case '1': //fallthrough
case '2': //fallthrough
case '3': //fallthrough
case '4':
r = tmp[0] - '1'; /* Save the next context id */
if (cfg.curctx == r)
continue;
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;
/* Save current context */ if (g_ctx[r].c_cfg.ctxactive) /* Switch to saved context */
xstrlcpy(g_ctx[cfg.curctx].c_name, dents[cur].name, NAME_MAX + 1); cfg = g_ctx[r].c_cfg;
g_ctx[cfg.curctx].c_cfg = cfg; else { /* Setup a new context from current context */
g_ctx[r].c_cfg.ctxactive = 1;
if (g_ctx[r].c_cfg.ctxactive) /* Switch to saved context */ xstrlcpy(g_ctx[r].c_path, path, PATH_MAX);
cfg = g_ctx[r].c_cfg; xstrlcpy(g_ctx[r].c_init, path, PATH_MAX);
else { /* Setup a new context from current context */ g_ctx[r].c_last[0] = '\0';
g_ctx[r].c_cfg.ctxactive = 1; xstrlcpy(g_ctx[r].c_name, dents[cur].name, NAME_MAX + 1);
xstrlcpy(g_ctx[r].c_path, path, PATH_MAX); g_ctx[r].c_cfg = cfg;
xstrlcpy(g_ctx[r].c_init, path, PATH_MAX); xstrlcpy(g_ctx[r].c_fltr, hfltr, DOT_FILTER_LEN);
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;
} }
/* 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);
} }