mirror of
https://github.com/jarun/nnn.git
synced 2024-11-28 13:51:31 +00:00
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:
parent
07e643b10f
commit
48e64c2a79
50
src/nnn.c
50
src/nnn.c
|
@ -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,12 +437,12 @@ 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)
|
||||||
{
|
{
|
||||||
|
if (prompt)
|
||||||
printprompt(prompt);
|
printprompt(prompt);
|
||||||
cleartimeout();
|
cleartimeout();
|
||||||
int r = getch();
|
int r = getch();
|
||||||
|
@ -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,25 +2722,20 @@ 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
|
||||||
|
|
||||||
/* Interpret ~, - and & keys */
|
|
||||||
if (tmp[1] == '\0') {
|
|
||||||
switch (tmp[0]) {
|
|
||||||
case 'q':
|
|
||||||
case '~': //fallthrough
|
case '~': //fallthrough
|
||||||
case '-': //fallthrough
|
case '-': //fallthrough
|
||||||
case '&':
|
case '&':
|
||||||
presel = tmp[0];
|
presel = (char)fd;
|
||||||
goto nochange;
|
goto nochange;
|
||||||
case '>':
|
case '>':
|
||||||
case '.':
|
case '.':
|
||||||
case '<':
|
case '<':
|
||||||
case ',':
|
case ',':
|
||||||
r = cfg.curctx;
|
r = cfg.curctx;
|
||||||
if (tmp[0] == '>' || tmp[0] == '.')
|
if (fd == '>' || fd == '.')
|
||||||
do
|
do
|
||||||
(r == MAX_CTX - 1) ? (r = 0) : ++r;
|
(r == MAX_CTX - 1) ? (r = 0) : ++r;
|
||||||
while (!g_ctx[r].c_cfg.ctxactive);
|
while (!g_ctx[r].c_cfg.ctxactive);
|
||||||
|
@ -2754,12 +2743,12 @@ nochange:
|
||||||
do
|
do
|
||||||
(r == 0) ? (r = MAX_CTX - 1) : --r;
|
(r == 0) ? (r = MAX_CTX - 1) : --r;
|
||||||
while (!g_ctx[r].c_cfg.ctxactive); //fallthrough
|
while (!g_ctx[r].c_cfg.ctxactive); //fallthrough
|
||||||
tmp[0] = '1' + r; //fallthrough
|
fd = '1' + r; //fallthrough
|
||||||
case '1': //fallthrough
|
case '1': //fallthrough
|
||||||
case '2': //fallthrough
|
case '2': //fallthrough
|
||||||
case '3': //fallthrough
|
case '3': //fallthrough
|
||||||
case '4':
|
case '4':
|
||||||
r = tmp[0] - '1'; /* Save the next context id */
|
r = fd - '1'; /* Save the next context id */
|
||||||
if (cfg.curctx == r)
|
if (cfg.curctx == r)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -2792,10 +2781,9 @@ nochange:
|
||||||
setdirwatch();
|
setdirwatch();
|
||||||
goto begin;
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue