diff options
author | 0xACE <0xaced@gmail.com> | 2019-07-16 04:30:16 +0200 |
---|---|---|
committer | 0xACE <0xaced@gmail.com> | 2019-07-16 04:30:16 +0200 |
commit | ba12fa8b3d215aeb1038cc5d34de2f1b2d9e3e4b (patch) | |
tree | 9574e37ffaa84d63388168dbe71bf11b2759d2d3 /src | |
parent | fee2c339cc635b826cc83e79a4ecd7aec24e4244 (diff) | |
download | nnn-ba12fa8b3d215aeb1038cc5d34de2f1b2d9e3e4b.tar.gz |
Use KEY_RESIZE when prompting user input
The problem was that a window wouldn't resize while prompting the user
for input. These changes allows the input methods in nnn to resize
properly if KEY_RESIZE is defined.
A more portable solution would be hooking the WINCH signal and update
the xlines value from there along with some resized flag.
In some cases the full window isn't redrawn until the user has finished
the input. This is because in some functions I wasn't sure the current
"path" was available.
Diffstat (limited to 'src')
-rw-r--r-- | src/nnn.c | 44 |
1 files changed, 40 insertions, 4 deletions
@@ -548,6 +548,15 @@ static char *xitoa(uint val) return &ascbuf[++i]; } +#ifdef KEY_RESIZE +/* Clear the old prompt */ +static inline void clearoldprompt() +{ + move(xlines - 1, 0); + clrtoeol(); +} +#endif + /* Messages show up at the bottom */ static inline void printmsg(const char *msg) { @@ -586,7 +595,20 @@ static int get_input(const char *prompt) if (prompt) printprompt(prompt); cleartimeout(); +#ifdef KEY_RESIZE + do { + r = getch(); + if ( r == KEY_RESIZE) { + if (prompt) { + clearoldprompt(); + xlines = LINES; + printprompt(prompt); + } + } + } while ( r == KEY_RESIZE); +#else r = getch(); +#endif settimeout(); return r; } @@ -1667,6 +1689,13 @@ static int filterentries(char *path) while ((r = get_wch(ch)) != ERR) { switch (*ch) { +#ifdef KEY_RESIZE + case KEY_RESIZE: + clearoldprompt(); + redraw(path); + printprompt(ln); + continue; +#endif case KEY_DC: // fallthrough case KEY_BACKSPACE: // fallthrough case '\b': // fallthrough @@ -1787,7 +1816,7 @@ end: static char *xreadline(char *prefill, char *prompt) { size_t len, pos; - int x, y, r; + int x, r; const int WCHAR_T_WIDTH = sizeof(wchar_t); wint_t ch[2] = {0}; wchar_t * const buf = malloc(sizeof(wchar_t) * CMD_LEN_MAX); @@ -1809,13 +1838,13 @@ static char *xreadline(char *prefill, char *prompt) len = pos = 0; } - getyx(stdscr, y, x); + x = getcurx(stdscr); curs_set(TRUE); while (1) { buf[len] = ' '; - mvaddnwstr(y, x, buf, len + 1); - move(y, x + wcswidth(buf, pos)); + mvaddnwstr(xlines - 1, x, buf, len + 1); + move(xlines - 1, x + wcswidth(buf, pos)); r = get_wch(ch); if (r != ERR) { @@ -1868,6 +1897,13 @@ static char *xreadline(char *prefill, char *prompt) } } else { switch (*ch) { +#ifdef KEY_RESIZE + case KEY_RESIZE: + clearoldprompt(); + xlines = LINES; + printprompt(prompt); + break; +#endif case KEY_LEFT: if (pos > 0) --pos; |