diff options
Diffstat (limited to 'lib/libedit/tty.c')
-rw-r--r-- | lib/libedit/tty.c | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/lib/libedit/tty.c b/lib/libedit/tty.c index dd3fed61ea2..c68f8ecc530 100644 --- a/lib/libedit/tty.c +++ b/lib/libedit/tty.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tty.c,v 1.21 2016/03/20 23:48:27 schwarze Exp $ */ +/* $OpenBSD: tty.c,v 1.22 2016/04/09 18:42:49 schwarze Exp $ */ /* $NetBSD: tty.c,v 1.34 2011/01/27 23:11:40 christos Exp $ */ /*- @@ -495,6 +495,9 @@ tty_setup(EditLine *el) if (el->el_flags & EDIT_DISABLED) return 0; + if (el->el_tty.t_initialized) + return -1; + if (!isatty(el->el_outfd)) { #ifdef DEBUG_TTY (void) fprintf(el->el_errfile, @@ -502,14 +505,14 @@ tty_setup(EditLine *el) #endif /* DEBUG_TTY */ return -1; } - if (tty_getty(el, &el->el_tty.t_ed) == -1) { + if (tty_getty(el, &el->el_tty.t_or) == -1) { #ifdef DEBUG_TTY (void) fprintf(el->el_errfile, "tty_setup: tty_getty: %s\n", strerror(errno)); #endif /* DEBUG_TTY */ return -1; } - el->el_tty.t_ts = el->el_tty.t_ex = el->el_tty.t_ed; + el->el_tty.t_ts = el->el_tty.t_ex = el->el_tty.t_ed = el->el_tty.t_or; el->el_tty.t_speed = tty__getspeed(&el->el_tty.t_ex); el->el_tty.t_tabs = tty__gettabs(&el->el_tty.t_ex); @@ -555,6 +558,7 @@ tty_setup(EditLine *el) tty__setchar(&el->el_tty.t_ed, el->el_tty.t_c[ED_IO]); tty_bind_char(el, 1); + el->el_tty.t_initialized = 1; return 0; } @@ -564,6 +568,7 @@ tty_init(EditLine *el) el->el_tty.t_mode = EX_IO; el->el_tty.t_vdisable = _POSIX_VDISABLE; + el->el_tty.t_initialized = 0; (void) memcpy(el->el_tty.t_t, ttyperm, sizeof(ttyperm_t)); (void) memcpy(el->el_tty.t_c, ttychar, sizeof(ttychar_t)); return tty_setup(el); @@ -575,10 +580,20 @@ tty_init(EditLine *el) */ protected void /*ARGSUSED*/ -tty_end(EditLine *el __attribute__((__unused__))) +tty_end(EditLine *el) { + if (el->el_flags & EDIT_DISABLED) + return; + + if (!el->el_tty.t_initialized) + return; - /* XXX: Maybe reset to an initial state? */ + if (tty_setty(el, TCSAFLUSH, &el->el_tty.t_or) == -1) { +#ifdef DEBUG_TTY + (void) fprintf(el->el_errfile, + "%s: tty_setty: %s\n", __func__, strerror(errno)); +#endif /* DEBUG_TTY */ + } } |