sfeed_curses

[fork] sfeed (atom feed) reader
Log | Files | Refs | README | LICENSE

commit b8c1cc0140e91f44de035ecc37f470edbaf9bc5c
parent dd851a166a6f62d8ebadbc801c68fbfe40d5d2dd
Author: hhvn <dev@hhvn.uk>
Date:   Fri, 18 Jun 2021 22:03:29 +0100

sfeed_curses.c: handle escape key in lineeditor()

Diffstat:
Msfeed_curses.c | 15+++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/sfeed_curses.c b/sfeed_curses.c @@ -934,7 +934,7 @@ lineeditor(void) { char *input = NULL; size_t cap = 0, nchars = 0; - int ch; + int ch, escape = 0; for (;;) { if (nchars + 1 >= cap) { @@ -943,7 +943,18 @@ lineeditor(void) } ch = readch(); - if (ch == EOF || ch == '\r' || ch == '\n') { + if (ch == '\033') { + escape = 1; + continue; + } else if (ch == '[' && escape) { + /* some sequence like this isn't an escape: + * ^[[A (up arrow) */ + escape = 0; + write(1, &ch, 1); + } else if (escape) { + input[0] = '\0'; + break; + } else if (ch == EOF || ch == '\r' || ch == '\n') { input[nchars] = '\0'; break; } else if (ch == '\b' || ch == 0x7f) {