From c5a841f507b18045adabdaac16211fa191868a38 Mon Sep 17 00:00:00 2001 From: Arun Prakash Jana Date: Sat, 27 Oct 2018 08:35:05 +0530 Subject: [PATCH] Exit prompt on Escape press --- README.md | 1 + nnn.1 | 4 +++- nnn.c | 18 +++++++++++++----- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 7247363..ea6b6b5 100644 --- a/README.md +++ b/README.md @@ -249,6 +249,7 @@ optional args: y Show copy buffer ^T Toggle path quote ^L Redraw, clear prompt + Esc Exit prompt L Lock terminal o Open DE filemanager ^/ Open DE search app diff --git a/nnn.1 b/nnn.1 index e2aa335..7685c4c 100644 --- a/nnn.1 +++ b/nnn.1 @@ -116,7 +116,9 @@ Show copy buffer .It Ic ^T Toggle path quote .It Ic ^L -Force a redraw, clear rename or filter prompt +Force a redraw, clear prompt +.It Ic Esc +Exit prompt .It Ic L Lock terminal (Linux only) .It Ic \&? diff --git a/nnn.c b/nnn.c index e2d8ae7..125998b 100644 --- a/nnn.c +++ b/nnn.c @@ -1092,7 +1092,6 @@ static int filterentries(char *path) cur = 0; cleartimeout(); - echo(); curs_set(TRUE); printprompt(ln); @@ -1117,6 +1116,12 @@ static int filterentries(char *path) continue; } + if (*ch == 27) { /* Exit filter mode on Escape */ + cur = oldcur; + *ch = CONTROL('L'); + goto end; + } + if (r == OK) { /* Handle all control chars in main loop */ if (keyname(*ch)[0] == '^') { @@ -1186,7 +1191,6 @@ static int filterentries(char *path) } } end: - noecho(); curs_set(FALSE); settimeout(); @@ -1197,7 +1201,6 @@ end: /* Show a prompt with input string and return the changes */ static char *xreadline(char *fname, char *prompt) { - int old_curs = curs_set(1); size_t len, pos; int x, y, r; wint_t ch[2] = {0}; @@ -1217,6 +1220,7 @@ static char *xreadline(char *fname, char *prompt) } getyx(stdscr, y, x); + curs_set(TRUE); cleartimeout(); while (1) { @@ -1257,6 +1261,9 @@ static char *xreadline(char *fname, char *prompt) len -= pos; pos = 0; continue; + case 27: /* Exit prompt on Escape */ + len = 0; + goto END; } /* Filter out all other control chars */ @@ -1300,10 +1307,10 @@ static char *xreadline(char *fname, char *prompt) END: buf[len] = '\0'; - if (old_curs != ERR) - curs_set(old_curs); + curs_set(FALSE); settimeout(); + DPRINTF_S(buf); wcstombs(g_buf, buf, NAME_MAX); clearprompt(); @@ -1974,6 +1981,7 @@ static int show_help(char *path) "ey Show copy buffer\n" "d^T Toggle path quote\n" "d^L Redraw, clear prompt\n" + "cEsc Exit prompt\n" "eL Lock terminal\n" "eo Open DE filemanager\n" "d^/ Open DE search app\n"