/* rltty.c -- functions to prepare and restore the terminal for readline's
use. */
-/* Copyright (C) 1992-2005 Free Software Foundation, Inc.
+/* Copyright (C) 1992-2017 Free Software Foundation, Inc.
This file is part of the GNU Readline Library (Readline), a library
for reading lines of text with interactive input and history editing.
static void set_special_char PARAMS((Keymap, TIOTYPE *, int, rl_command_func_t *));
static void
-save_tty_chars (tiop)
- TIOTYPE *tiop;
+save_tty_chars (TIOTYPE *tiop)
{
_rl_last_tty_chars = _rl_tty_chars;
}
static int
-get_tty_settings (tty, tiop)
- int tty;
- TIOTYPE *tiop;
+get_tty_settings (int tty, TIOTYPE *tiop)
{
set_winsize (tty);
}
static int
-set_tty_settings (tty, tiop)
- int tty;
- TIOTYPE *tiop;
+set_tty_settings (int tty, TIOTYPE *tiop)
{
if (tiop->flags & SGTTY_SET)
{
}
static void
-prepare_terminal_settings (meta_flag, oldtio, tiop)
- int meta_flag;
- TIOTYPE oldtio, *tiop;
+prepare_terminal_settings (int meta_flag, TIOTYPE oldtio, TIOTYPE *tiop)
{
_rl_echoing_p = (oldtio.sgttyb.sg_flags & ECHO);
_rl_echoctl = (oldtio.sgttyb.sg_flags & ECHOCTL);
#endif
static void
-save_tty_chars (tiop)
- TIOTYPE *tiop;
+save_tty_chars (TIOTYPE *tiop)
{
_rl_last_tty_chars = _rl_tty_chars;
#if defined (_AIX) || defined (_AIX41)
/* Currently this is only used on AIX */
static void
-rltty_warning (msg)
- char *msg;
+rltty_warning (char *msg)
{
_rl_errmsg ("warning: %s", msg);
}
#if defined (_AIX)
void
-setopost(tp)
-TIOTYPE *tp;
+setopost (TIOTYPE *tp)
{
if ((tp->c_oflag & OPOST) == 0)
{
#endif
static int
-_get_tty_settings (tty, tiop)
- int tty;
- TIOTYPE *tiop;
+_get_tty_settings (int tty, TIOTYPE *tiop)
{
int ioctl_ret;
}
static int
-get_tty_settings (tty, tiop)
- int tty;
- TIOTYPE *tiop;
+get_tty_settings (int tty, TIOTYPE *tiop)
{
set_winsize (tty);
}
static int
-_set_tty_settings (tty, tiop)
- int tty;
- TIOTYPE *tiop;
+_set_tty_settings (int tty, TIOTYPE *tiop)
{
while (SETATTR (tty, tiop) < 0)
{
}
static int
-set_tty_settings (tty, tiop)
- int tty;
- TIOTYPE *tiop;
+set_tty_settings (int tty, TIOTYPE *tiop)
{
if (_set_tty_settings (tty, tiop) < 0)
return -1;
}
static void
-prepare_terminal_settings (meta_flag, oldtio, tiop)
- int meta_flag;
- TIOTYPE oldtio, *tiop;
+prepare_terminal_settings (int meta_flag, TIOTYPE oldtio, TIOTYPE *tiop)
{
+ int sc;
+ Keymap kmap;
+
_rl_echoing_p = (oldtio.c_lflag & ECHO);
#if defined (ECHOCTL)
_rl_echoctl = (oldtio.c_lflag & ECHOCTL);
tiop->c_cc[VDSUSP] = _POSIX_VDISABLE;
#endif
+ /* Conditionally disable some other tty special characters if there is a
+ key binding for them in the current keymap. Readline ordinarily doesn't
+ bind these characters, but an application or user might. */
+#if defined (VI_MODE)
+ kmap = (rl_editing_mode == vi_mode) ? vi_insertion_keymap : _rl_keymap;
+#else
+ kmap = _rl_keymap;
+#endif
+#if defined (VDISCARD)
+ sc = tiop->c_cc[VDISCARD];
+ if (sc != _POSIX_VDISABLE && kmap[(unsigned char)sc].type == ISFUNC)
+ tiop->c_cc[VDISCARD] = _POSIX_VDISABLE;
+#endif /* VDISCARD */
+
#endif /* TERMIOS_TTY_DRIVER && _POSIX_VDISABLE */
}
#endif /* !NEW_TTY_DRIVER */
/* Put the terminal in CBREAK mode so that we can detect key presses. */
#if defined (NO_TTY_DRIVER)
void
-rl_prep_terminal (meta_flag)
- int meta_flag;
+rl_prep_terminal (int meta_flag)
{
_rl_echoing_p = 1;
}
void
-rl_deprep_terminal ()
+rl_deprep_terminal (void)
{
}
#else /* ! NO_TTY_DRIVER */
void
-rl_prep_terminal (meta_flag)
- int meta_flag;
+rl_prep_terminal (int meta_flag)
{
int tty, nprep;
TIOTYPE tio;
/* Restore the terminal's normal settings and modes. */
void
-rl_deprep_terminal ()
+rl_deprep_terminal (void)
{
int tty;
tty = rl_instream ? fileno (rl_instream) : fileno (stdin);
if (terminal_prepped & TPX_BRACKPASTE)
- fprintf (rl_outstream, BRACK_PASTE_FINI);
+ {
+ fprintf (rl_outstream, BRACK_PASTE_FINI);
+ if (_rl_eof_found)
+ fprintf (rl_outstream, "\n");
+ }
if (_rl_enable_keypad)
_rl_control_keypad (0);
_rl_release_sigint ();
}
#endif /* !NO_TTY_DRIVER */
+
+/* Set readline's idea of whether or not it is echoing output to the terminal,
+ returning the old value. */
+int
+rl_tty_set_echoing (int u)
+{
+ int o;
+
+ o = _rl_echoing_p;
+ _rl_echoing_p = u;
+ return o;
+}
\f
/* **************************************************************** */
/* */
/* **************************************************************** */
int
-rl_restart_output (count, key)
- int count, key;
+rl_restart_output (int count, int key)
{
#if defined (__MINGW32__)
return 0;
}
int
-rl_stop_output (count, key)
- int count, key;
+rl_stop_output (int count, int key)
{
#if defined (__MINGW32__)
return 0;
#elif defined (NEW_TTY_DRIVER)
static void
-set_special_char (kmap, tiop, sc, func)
- Keymap kmap;
- TIOTYPE *tiop;
- int sc;
- rl_command_func_t *func;
+set_special_char (Keymap kmap, TIOTYPE *tiop, int sc, rl_command_func_t *func)
{
if (sc != -1 && kmap[(unsigned char)sc].type == ISFUNC)
kmap[(unsigned char)sc].function = func;
kmap[(unsigned char)c].function = rl_insert;
static void
-_rl_bind_tty_special_chars (kmap, ttybuff)
- Keymap kmap;
- TIOTYPE ttybuff;
+_rl_bind_tty_special_chars (Keymap kmap, TIOTYPE ttybuff)
{
if (ttybuff.flags & SGTTY_SET)
{
#else /* !NEW_TTY_DRIVER */
static void
-set_special_char (kmap, tiop, sc, func)
- Keymap kmap;
- TIOTYPE *tiop;
- int sc;
- rl_command_func_t *func;
+set_special_char (Keymap kmap, TIOTYPE *tiop, int sc, rl_command_func_t *func)
{
unsigned char uc;
kmap[uc].function = rl_insert;
static void
-_rl_bind_tty_special_chars (kmap, ttybuff)
- Keymap kmap;
- TIOTYPE ttybuff;
+_rl_bind_tty_special_chars (Keymap kmap, TIOTYPE ttybuff)
{
SET_SPECIAL (VERASE, rl_rubout);
SET_SPECIAL (VKILL, rl_unix_line_discard);
# endif /* VLNEXT && TERMIOS_TTY_DRIVER */
# if defined (VWERASE) && defined (TERMIOS_TTY_DRIVER)
+# if defined (VI_MODE)
+ if (rl_editing_mode == vi_mode)
+ SET_SPECIAL (VWERASE, rl_vi_unix_word_rubout);
+ else
+# endif
SET_SPECIAL (VWERASE, rl_unix_word_rubout);
# endif /* VWERASE && TERMIOS_TTY_DRIVER */
}
/* Set the system's default editing characters to their readline equivalents
in KMAP. Should be static, now that we have rl_tty_set_default_bindings. */
void
-rltty_set_default_bindings (kmap)
- Keymap kmap;
+rltty_set_default_bindings (Keymap kmap)
{
#if !defined (NO_TTY_DRIVER)
TIOTYPE ttybuff;
/* New public way to set the system default editing chars to their readline
equivalents. */
void
-rl_tty_set_default_bindings (kmap)
- Keymap kmap;
+rl_tty_set_default_bindings (Keymap kmap)
{
rltty_set_default_bindings (kmap);
}
chars with save_tty_chars(). This only works on POSIX termios or termio
systems. */
void
-rl_tty_unset_default_bindings (kmap)
- Keymap kmap;
+rl_tty_unset_default_bindings (Keymap kmap)
{
/* Don't bother before we've saved the tty special chars at least once. */
if (RL_ISSTATE(RL_STATE_TTYCSAVED) == 0)
#if defined (NEW_TTY_DRIVER) || defined (NO_TTY_DRIVER)
int
-_rl_disable_tty_signals ()
+_rl_disable_tty_signals (void)
{
return 0;
}
int
-_rl_restore_tty_signals ()
+_rl_restore_tty_signals (void)
{
return 0;
}
static int tty_sigs_disabled = 0;
int
-_rl_disable_tty_signals ()
+_rl_disable_tty_signals (void)
{
if (tty_sigs_disabled)
return 0;
}
int
-_rl_restore_tty_signals ()
+_rl_restore_tty_signals (void)
{
int r;