diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2018-05-18 06:28:24 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2018-05-18 06:28:24 -0700 |
commit | c77dabaf277f663b9530038e8e897f5a3e53a8b0 (patch) | |
tree | d0658789afb654bb81f39e89d837b2dbc886095c /linenoise | |
parent | b13a869dddb06218151f00a0abec077fff9cdd4a (diff) | |
download | txr-c77dabaf277f663b9530038e8e897f5a3e53a8b0.tar.gz txr-c77dabaf277f663b9530038e8e897f5a3e53a8b0.tar.bz2 txr-c77dabaf277f663b9530038e8e897f5a3e53a8b0.zip |
listener: Cygnal fix.
The standard input and output streams are in text mode on
Cygnal, which interferes with the listener, because it draws
input from streams. Let's hack it by Cygwin-specific code
in linenoise.
* linenoise/linenoise.c (struct lino_state): New members
orig_imode and orig_omode, on Cygwin/Cygnal only.
(enable_raw_mode): As part of enabling raw mode, use the
Cygwin setmode function to put both descriptors in binary
mode, saving their previous mode.
(disable_raw_mode): Revert the previous mode of both
descriptors, in reverse order in case they are the same
descriptor.
Diffstat (limited to 'linenoise')
-rw-r--r-- | linenoise/linenoise.c | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/linenoise/linenoise.c b/linenoise/linenoise.c index 1cdb1997..468c0a0b 100644 --- a/linenoise/linenoise.c +++ b/linenoise/linenoise.c @@ -63,6 +63,8 @@ #endif #ifdef __CYGWIN__ #include <sys/utsname.h> +#include <sys/fcntl.h> +#include <io.h> #endif #include "linenoise.h" @@ -96,6 +98,9 @@ struct lino_state { lino_enter_cb_t *enter_callback; void *ce_ctx; /* User context for enter callback */ struct termios orig_termios; /* In order to restore at exit.*/ +#ifdef __CYGWIN__ + int orig_imode, orig_omode; +#endif int rawmode; /* For atexit() function to check if restore is needed*/ int mlmode; /* Multi line mode. Default is single line. */ int history_max_len; @@ -218,6 +223,9 @@ static void atexit_handler(void); static int enable_raw_mode(lino_t *ls) { struct termios raw; int ifd = lino_os.fileno_fn(ls->tty_ifs); +#ifdef __CYGWIN__ + int ofd = lino_os.fileno_fn(ls->tty_ofs); +#endif if (!isatty(ifd)) goto fatal; @@ -248,6 +256,11 @@ static int enable_raw_mode(lino_t *ls) { if (tcsetattr(ifd, TCSANOW, &raw) < 0) goto fatal; +#ifdef __CYGWIN__ + ls->orig_imode = setmode(ifd, O_BINARY); + ls->orig_omode = setmode(ofd, O_BINARY); +#endif + ls->rawmode = 1; return 0; @@ -258,10 +271,19 @@ fatal: static void disable_raw_mode(lino_t *ls) { int ifd = lino_os.fileno_fn(ls->tty_ifs); +#ifdef __CYGWIN__ + int ofd = lino_os.fileno_fn(ls->tty_ofs); +#endif /* Don't even check the return value as it's too late. */ - if (ls->rawmode && tcsetattr(ifd, TCSANOW, &ls->orig_termios) != -1) + if (ls->rawmode && tcsetattr(ifd, TCSANOW, &ls->orig_termios) != -1) { +#ifdef __CYGWIN__ + /* reverse order in case ofd == ifd */ + setmode(ofd, ls->orig_omode); + setmode(ifd, ls->orig_imode); +#endif ls->rawmode = 0; + } } /* Use the ESC [6n escape sequence to query the horizontal cursor position |