For readline emulation, don't reset the tty to "sane" (cooked) mode if we

did not start this way. Also set and reset the tty on entry and exit from
readline() since this is what readline does.
This commit is contained in:
christos 2017-09-05 18:07:59 +00:00
parent 12d26bd60a
commit b2ad969a13
4 changed files with 32 additions and 15 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: el.c,v 1.94 2017/06/27 23:25:13 christos Exp $ */
/* $NetBSD: el.c,v 1.95 2017/09/05 18:07:59 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)el.c 8.2 (Berkeley) 1/3/94";
#else
__RCSID("$NetBSD: el.c,v 1.94 2017/06/27 23:25:13 christos Exp $");
__RCSID("$NetBSD: el.c,v 1.95 2017/09/05 18:07:59 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
@ -67,9 +67,9 @@ el_init(const char *prog, FILE *fin, FILE *fout, FILE *ferr)
fileno(ferr));
}
EditLine *
el_init_fd(const char *prog, FILE *fin, FILE *fout, FILE *ferr,
int fdin, int fdout, int fderr)
libedit_private EditLine *
el_init_internal(const char *prog, FILE *fin, FILE *fout, FILE *ferr,
int fdin, int fdout, int fderr, int flags)
{
EditLine *el = el_malloc(sizeof(*el));
@ -95,7 +95,7 @@ el_init_fd(const char *prog, FILE *fin, FILE *fout, FILE *ferr,
/*
* Initialize all the modules. Order is important!!!
*/
el->el_flags = 0;
el->el_flags = flags;
if (setlocale(LC_CTYPE, NULL) != NULL){
if (strcmp(nl_langinfo(CODESET), "UTF-8") == 0)
el->el_flags |= CHARSET_IS_UTF8;
@ -123,6 +123,12 @@ el_init_fd(const char *prog, FILE *fin, FILE *fout, FILE *ferr,
return el;
}
EditLine *
el_init_fd(const char *prog, FILE *fin, FILE *fout, FILE *ferr,
int fdin, int fdout, int fderr)
{
return el_init_internal(prog, fin, fout, ferr, fdin, fdout, fderr, 0);
}
/* el_end():
* Clean up.

View File

@ -1,4 +1,4 @@
/* $NetBSD: el.h,v 1.42 2017/06/27 23:25:13 christos Exp $ */
/* $NetBSD: el.h,v 1.43 2017/09/05 18:07:59 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@ -57,6 +57,7 @@
#define UNBUFFERED 0x08
#define CHARSET_IS_UTF8 0x10
#define NARROW_HISTORY 0x40
#define NO_RESET 0x80
typedef unsigned char el_action_t; /* Index to command array */
@ -141,6 +142,8 @@ struct editline {
};
libedit_private int el_editmode(EditLine *, int, const wchar_t **);
libedit_private EditLine *el_init_internal(const char *, FILE *, FILE *,
FILE *, int, int, int, int);
#ifdef DEBUG
#define EL_ABORT(a) do { \

View File

@ -1,4 +1,4 @@
/* $NetBSD: readline.c,v 1.142 2017/09/01 10:19:10 christos Exp $ */
/* $NetBSD: readline.c,v 1.143 2017/09/05 18:07:59 christos Exp $ */
/*-
* Copyright (c) 1997 The NetBSD Foundation, Inc.
@ -31,7 +31,7 @@
#include "config.h"
#if !defined(lint) && !defined(SCCSID)
__RCSID("$NetBSD: readline.c,v 1.142 2017/09/01 10:19:10 christos Exp $");
__RCSID("$NetBSD: readline.c,v 1.143 2017/09/05 18:07:59 christos Exp $");
#endif /* not lint && not SCCSID */
#include <sys/types.h>
@ -290,7 +290,9 @@ rl_initialize(void)
if (tcgetattr(fileno(rl_instream), &t) != -1 && (t.c_lflag & ECHO) == 0)
editmode = 0;
e = el_init(rl_readline_name, rl_instream, rl_outstream, stderr);
e = el_init_internal(rl_readline_name, rl_instream, rl_outstream,
stderr, fileno(rl_instream), fileno(rl_outstream), fileno(stderr),
NO_RESET);
if (!editmode)
el_set(e, EL_EDITMODE, 0);
@ -386,6 +388,8 @@ rl_initialize(void)
_resize_fun(e, &rl_line_buffer);
_rl_update_pos();
tty_end(e);
return 0;
}
@ -410,15 +414,17 @@ readline(const char *p)
rl_did_startup_hook = 1;
(*rl_startup_hook)(NULL, 0);
}
tty_init(e);
rl_done = 0;
(void)setjmp(topbuf);
buf = NULL;
/* update prompt accordingly to what has been passed */
if (rl_set_prompt(prompt) == -1)
return NULL;
goto out;
if (rl_pre_input_hook)
(*rl_pre_input_hook)(NULL, 0);
@ -443,7 +449,7 @@ readline(const char *p)
buf = strdup(ret);
if (buf == NULL)
return NULL;
goto out;
lastidx = count - 1;
if (buf[lastidx] == '\n')
buf[lastidx] = '\0';
@ -453,6 +459,8 @@ readline(const char *p)
history(h, &ev, H_GETSIZE);
history_length = ev.num;
out:
tty_end(e);
return buf;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: tty.c,v 1.65 2016/05/09 21:46:56 christos Exp $ */
/* $NetBSD: tty.c,v 1.66 2017/09/05 18:07:59 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)tty.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: tty.c,v 1.65 2016/05/09 21:46:56 christos Exp $");
__RCSID("$NetBSD: tty.c,v 1.66 2017/09/05 18:07:59 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
@ -497,7 +497,7 @@ tty_setty(EditLine *el, int action, const struct termios *t)
static int
tty_setup(EditLine *el)
{
int rst = 1;
int rst = (el->el_flags & NO_RESET) == 0;
if (el->el_flags & EDIT_DISABLED)
return 0;