summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/libedit/tty.c25
-rw-r--r--lib/libedit/tty.h9
2 files changed, 25 insertions, 9 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 */
+ }
}
diff --git a/lib/libedit/tty.h b/lib/libedit/tty.h
index 49a7541942a..1e004e06404 100644
--- a/lib/libedit/tty.h
+++ b/lib/libedit/tty.h
@@ -1,5 +1,5 @@
-/* $OpenBSD: tty.h,v 1.10 2016/03/20 22:57:59 schwarze Exp $ */
-/* $NetBSD: tty.h,v 1.12 2009/12/30 22:37:40 christos Exp $ */
+/* $OpenBSD: tty.h,v 1.11 2016/04/09 18:42:49 schwarze Exp $ */
+/* $NetBSD: tty.h,v 1.19 2016/02/27 18:13:21 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -469,12 +469,13 @@ protected void tty_bind_char(EditLine *, int);
typedef struct {
ttyperm_t t_t;
ttychar_t t_c;
- struct termios t_ex, t_ed, t_ts;
+ struct termios t_or, t_ex, t_ed, t_ts;
int t_tabs;
int t_eight;
speed_t t_speed;
- int t_mode;
+ unsigned char t_mode;
unsigned char t_vdisable;
+ unsigned char t_initialized;
} el_tty_t;