1 /* rltty.c -- functions to prepare and restore the terminal for readline's
4 /* Copyright (C) 1992-2017 Free Software Foundation, Inc.
6 This file is part of the GNU Readline Library (Readline), a library
7 for reading lines of text with interactive input and history editing.
9 Readline is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 Readline is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with Readline. If not, see <http://www.gnu.org/licenses/>.
23 #define READLINE_LIBRARY
25 #if defined (HAVE_CONFIG_H)
29 #include <sys/types.h>
34 #if defined (HAVE_UNISTD_H)
36 #endif /* HAVE_UNISTD_H */
41 #if defined (HAVE_SYS_IOCTL_H)
42 # include <sys/ioctl.h> /* include for declaration of ioctl */
46 #include "rlprivate.h"
52 rl_vintfunc_t *rl_prep_term_function = rl_prep_terminal;
53 rl_voidfunc_t *rl_deprep_term_function = rl_deprep_terminal;
55 static void set_winsize PARAMS((int));
57 /* **************************************************************** */
59 /* Saving and Restoring the TTY */
61 /* **************************************************************** */
63 /* Non-zero means that the terminal is in a prepped state. There are several
64 flags that are OR'd in to denote whether or not we have sent various
65 init strings to the terminal. */
66 #define TPX_PREPPED 0x01
67 #define TPX_BRACKPASTE 0x02
68 #define TPX_METAKEY 0x04
70 static int terminal_prepped;
72 static _RL_TTY_CHARS _rl_tty_chars, _rl_last_tty_chars;
74 /* If non-zero, means that this process has called tcflow(fd, TCOOFF)
75 and output is suspended. */
76 #if defined (__ksr1__)
80 /* Dummy call to force a backgrounded readline to stop before it tries
81 to get the tty settings. */
86 #if defined (TIOCGWINSZ)
89 if (ioctl (tty, TIOCGWINSZ, &w) == 0)
90 (void) ioctl (tty, TIOCSWINSZ, &w);
91 #endif /* TIOCGWINSZ */
94 #if defined (NO_TTY_DRIVER)
96 #elif defined (NEW_TTY_DRIVER)
98 /* Values for the `flags' field of a struct bsdtty. This tells which
99 elements of the struct bsdtty have been fetched from the system and
101 #define SGTTY_SET 0x01
102 #define LFLAG_SET 0x02
103 #define TCHARS_SET 0x04
104 #define LTCHARS_SET 0x08
107 struct sgttyb sgttyb; /* Basic BSD tty driver information. */
108 int lflag; /* Local mode flags, like LPASS8. */
109 #if defined (TIOCGETC)
110 struct tchars tchars; /* Terminal special characters, including ^S and ^Q. */
112 #if defined (TIOCGLTC)
113 struct ltchars ltchars; /* 4.2 BSD editing characters */
115 int flags; /* Bitmap saying which parts of the struct are valid. */
118 #define TIOTYPE struct bsdtty
122 static void save_tty_chars PARAMS((TIOTYPE *));
123 static int _get_tty_settings PARAMS((int, TIOTYPE *));
124 static int get_tty_settings PARAMS((int, TIOTYPE *));
125 static int _set_tty_settings PARAMS((int, TIOTYPE *));
126 static int set_tty_settings PARAMS((int, TIOTYPE *));
128 static void prepare_terminal_settings PARAMS((int, TIOTYPE, TIOTYPE *));
130 static void set_special_char PARAMS((Keymap, TIOTYPE *, int, rl_command_func_t *));
133 save_tty_chars (TIOTYPE *tiop)
135 _rl_last_tty_chars = _rl_tty_chars;
137 if (tiop->flags & SGTTY_SET)
139 _rl_tty_chars.t_erase = tiop->sgttyb.sg_erase;
140 _rl_tty_chars.t_kill = tiop->sgttyb.sg_kill;
143 if (tiop->flags & TCHARS_SET)
145 _rl_intr_char = _rl_tty_chars.t_intr = tiop->tchars.t_intrc;
146 _rl_quit_char = _rl_tty_chars.t_quit = tiop->tchars.t_quitc;
148 _rl_tty_chars.t_start = tiop->tchars.t_startc;
149 _rl_tty_chars.t_stop = tiop->tchars.t_stopc;
150 _rl_tty_chars.t_eof = tiop->tchars.t_eofc;
151 _rl_tty_chars.t_eol = '\n';
152 _rl_tty_chars.t_eol2 = tiop->tchars.t_brkc;
155 if (tiop->flags & LTCHARS_SET)
157 _rl_susp_char = _rl_tty_chars.t_susp = tiop->ltchars.t_suspc;
159 _rl_tty_chars.t_dsusp = tiop->ltchars.t_dsuspc;
160 _rl_tty_chars.t_reprint = tiop->ltchars.t_rprntc;
161 _rl_tty_chars.t_flush = tiop->ltchars.t_flushc;
162 _rl_tty_chars.t_werase = tiop->ltchars.t_werasc;
163 _rl_tty_chars.t_lnext = tiop->ltchars.t_lnextc;
166 _rl_tty_chars.t_status = -1;
170 get_tty_settings (int tty, TIOTYPE *tiop)
174 tiop->flags = tiop->lflag = 0;
177 if (ioctl (tty, TIOCGETP, &(tiop->sgttyb)) < 0)
179 tiop->flags |= SGTTY_SET;
181 #if defined (TIOCLGET)
182 if (ioctl (tty, TIOCLGET, &(tiop->lflag)) == 0)
183 tiop->flags |= LFLAG_SET;
186 #if defined (TIOCGETC)
187 if (ioctl (tty, TIOCGETC, &(tiop->tchars)) == 0)
188 tiop->flags |= TCHARS_SET;
191 #if defined (TIOCGLTC)
192 if (ioctl (tty, TIOCGLTC, &(tiop->ltchars)) == 0)
193 tiop->flags |= LTCHARS_SET;
200 set_tty_settings (int tty, TIOTYPE *tiop)
202 if (tiop->flags & SGTTY_SET)
204 ioctl (tty, TIOCSETN, &(tiop->sgttyb));
205 tiop->flags &= ~SGTTY_SET;
209 #if defined (TIOCLSET)
210 if (tiop->flags & LFLAG_SET)
212 ioctl (tty, TIOCLSET, &(tiop->lflag));
213 tiop->flags &= ~LFLAG_SET;
217 #if defined (TIOCSETC)
218 if (tiop->flags & TCHARS_SET)
220 ioctl (tty, TIOCSETC, &(tiop->tchars));
221 tiop->flags &= ~TCHARS_SET;
225 #if defined (TIOCSLTC)
226 if (tiop->flags & LTCHARS_SET)
228 ioctl (tty, TIOCSLTC, &(tiop->ltchars));
229 tiop->flags &= ~LTCHARS_SET;
237 prepare_terminal_settings (int meta_flag, TIOTYPE oldtio, TIOTYPE *tiop)
239 _rl_echoing_p = (oldtio.sgttyb.sg_flags & ECHO);
240 _rl_echoctl = (oldtio.sgttyb.sg_flags & ECHOCTL);
242 /* Copy the original settings to the structure we're going to use for
244 tiop->sgttyb = oldtio.sgttyb;
245 tiop->lflag = oldtio.lflag;
246 #if defined (TIOCGETC)
247 tiop->tchars = oldtio.tchars;
249 #if defined (TIOCGLTC)
250 tiop->ltchars = oldtio.ltchars;
252 tiop->flags = oldtio.flags;
254 /* First, the basic settings to put us into character-at-a-time, no-echo
256 tiop->sgttyb.sg_flags &= ~(ECHO | CRMOD);
257 tiop->sgttyb.sg_flags |= CBREAK;
259 /* If this terminal doesn't care how the 8th bit is used, then we can
260 use it for the meta-key. If only one of even or odd parity is
261 specified, then the terminal is using parity, and we cannot. */
263 # define ANYP (EVENP | ODDP)
265 if (((oldtio.sgttyb.sg_flags & ANYP) == ANYP) ||
266 ((oldtio.sgttyb.sg_flags & ANYP) == 0))
268 tiop->sgttyb.sg_flags |= ANYP;
270 /* Hack on local mode flags if we can. */
271 #if defined (TIOCLGET)
272 # if defined (LPASS8)
273 tiop->lflag |= LPASS8;
275 #endif /* TIOCLGET */
278 #if defined (TIOCGETC)
279 # if defined (USE_XON_XOFF)
280 /* Get rid of terminal output start and stop characters. */
281 tiop->tchars.t_stopc = -1; /* C-s */
282 tiop->tchars.t_startc = -1; /* C-q */
284 /* If there is an XON character, bind it to restart the output. */
285 if (oldtio.tchars.t_startc != -1)
286 rl_bind_key (oldtio.tchars.t_startc, rl_restart_output);
287 # endif /* USE_XON_XOFF */
289 /* If there is an EOF char, bind _rl_eof_char to it. */
290 if (oldtio.tchars.t_eofc != -1)
291 _rl_eof_char = oldtio.tchars.t_eofc;
293 # if defined (NO_KILL_INTR)
294 /* Get rid of terminal-generated SIGQUIT and SIGINT. */
295 tiop->tchars.t_quitc = -1; /* C-\ */
296 tiop->tchars.t_intrc = -1; /* C-c */
297 # endif /* NO_KILL_INTR */
298 #endif /* TIOCGETC */
300 #if defined (TIOCGLTC)
301 /* Make the interrupt keys go away. Just enough to make people happy. */
302 tiop->ltchars.t_dsuspc = -1; /* C-y */
303 tiop->ltchars.t_lnextc = -1; /* C-v */
304 #endif /* TIOCGLTC */
307 #else /* !defined (NEW_TTY_DRIVER) */
317 #if defined (TERMIOS_TTY_DRIVER)
318 # define TIOTYPE struct termios
319 # define DRAIN_OUTPUT(fd) tcdrain (fd)
320 # define GETATTR(tty, tiop) (tcgetattr (tty, tiop))
322 # define SETATTR(tty, tiop) (tcsetattr (tty, TCSANOW, tiop))
324 # define SETATTR(tty, tiop) (tcsetattr (tty, TCSADRAIN, tiop))
325 # endif /* !M_UNIX */
327 # define TIOTYPE struct termio
328 # define DRAIN_OUTPUT(fd)
329 # define GETATTR(tty, tiop) (ioctl (tty, TCGETA, tiop))
330 # define SETATTR(tty, tiop) (ioctl (tty, TCSETAW, tiop))
331 #endif /* !TERMIOS_TTY_DRIVER */
335 static void save_tty_chars PARAMS((TIOTYPE *));
336 static int _get_tty_settings PARAMS((int, TIOTYPE *));
337 static int get_tty_settings PARAMS((int, TIOTYPE *));
338 static int _set_tty_settings PARAMS((int, TIOTYPE *));
339 static int set_tty_settings PARAMS((int, TIOTYPE *));
341 static void prepare_terminal_settings PARAMS((int, TIOTYPE, TIOTYPE *));
343 static void set_special_char PARAMS((Keymap, TIOTYPE *, int, rl_command_func_t *));
344 static void _rl_bind_tty_special_chars PARAMS((Keymap, TIOTYPE));
347 # define OUTPUT_BEING_FLUSHED(tp) (tp->c_lflag & FLUSHO)
349 # define OUTPUT_BEING_FLUSHED(tp) 0
353 save_tty_chars (TIOTYPE *tiop)
355 _rl_last_tty_chars = _rl_tty_chars;
357 _rl_tty_chars.t_eof = tiop->c_cc[VEOF];
358 _rl_tty_chars.t_eol = tiop->c_cc[VEOL];
360 _rl_tty_chars.t_eol2 = tiop->c_cc[VEOL2];
362 _rl_tty_chars.t_erase = tiop->c_cc[VERASE];
364 _rl_tty_chars.t_werase = tiop->c_cc[VWERASE];
366 _rl_tty_chars.t_kill = tiop->c_cc[VKILL];
368 _rl_tty_chars.t_reprint = tiop->c_cc[VREPRINT];
370 _rl_intr_char = _rl_tty_chars.t_intr = tiop->c_cc[VINTR];
371 _rl_quit_char = _rl_tty_chars.t_quit = tiop->c_cc[VQUIT];
373 _rl_susp_char = _rl_tty_chars.t_susp = tiop->c_cc[VSUSP];
376 _rl_tty_chars.t_dsusp = tiop->c_cc[VDSUSP];
379 _rl_tty_chars.t_start = tiop->c_cc[VSTART];
382 _rl_tty_chars.t_stop = tiop->c_cc[VSTOP];
385 _rl_tty_chars.t_lnext = tiop->c_cc[VLNEXT];
388 _rl_tty_chars.t_flush = tiop->c_cc[VDISCARD];
391 _rl_tty_chars.t_status = tiop->c_cc[VSTATUS];
395 #if defined (_AIX) || defined (_AIX41)
396 /* Currently this is only used on AIX */
398 rltty_warning (char *msg)
400 _rl_errmsg ("warning: %s", msg);
406 setopost (TIOTYPE *tp)
408 if ((tp->c_oflag & OPOST) == 0)
410 _rl_errmsg ("warning: turning on OPOST for terminal\r");
411 tp->c_oflag |= OPOST|ONLCR;
417 _get_tty_settings (int tty, TIOTYPE *tiop)
423 ioctl_ret = GETATTR (tty, tiop);
431 if (OUTPUT_BEING_FLUSHED (tiop))
434 _rl_errmsg ("warning: turning off output flushing");
435 tiop->c_lflag &= ~FLUSHO;
448 get_tty_settings (int tty, TIOTYPE *tiop)
453 if (_get_tty_settings (tty, tiop) < 0)
464 _set_tty_settings (int tty, TIOTYPE *tiop)
466 while (SETATTR (tty, tiop) < 0)
476 set_tty_settings (int tty, TIOTYPE *tiop)
478 if (_set_tty_settings (tty, tiop) < 0)
483 #if defined (TERMIOS_TTY_DRIVER)
484 # if defined (__ksr1__)
491 tcflow (tty, TCOON); /* Simulate a ^Q. */
494 ioctl (tty, TCXONC, 1); /* Simulate a ^Q. */
495 #endif /* !TERMIOS_TTY_DRIVER */
503 prepare_terminal_settings (int meta_flag, TIOTYPE oldtio, TIOTYPE *tiop)
508 _rl_echoing_p = (oldtio.c_lflag & ECHO);
509 #if defined (ECHOCTL)
510 _rl_echoctl = (oldtio.c_lflag & ECHOCTL);
513 tiop->c_lflag &= ~(ICANON | ECHO);
515 if ((unsigned char) oldtio.c_cc[VEOF] != (unsigned char) _POSIX_VDISABLE)
516 _rl_eof_char = oldtio.c_cc[VEOF];
518 #if defined (USE_XON_XOFF)
520 tiop->c_iflag &= ~(IXON | IXANY);
522 /* `strict' Posix systems do not define IXANY. */
523 tiop->c_iflag &= ~IXON;
525 #endif /* USE_XON_XOFF */
527 /* Only turn this off if we are using all 8 bits. */
528 if (((tiop->c_cflag & CSIZE) == CS8) || meta_flag)
529 tiop->c_iflag &= ~(ISTRIP | INPCK);
531 /* Make sure we differentiate between CR and NL on input. */
532 tiop->c_iflag &= ~(ICRNL | INLCR);
534 #if !defined (HANDLE_SIGNALS)
535 tiop->c_lflag &= ~ISIG;
537 tiop->c_lflag |= ISIG;
540 tiop->c_cc[VMIN] = 1;
541 tiop->c_cc[VTIME] = 0;
544 if (OUTPUT_BEING_FLUSHED (tiop))
546 tiop->c_lflag &= ~FLUSHO;
547 oldtio.c_lflag &= ~FLUSHO;
551 /* Turn off characters that we need on Posix systems with job control,
552 just to be sure. This includes ^Y and ^V. This should not really
554 #if defined (TERMIOS_TTY_DRIVER) && defined (_POSIX_VDISABLE)
557 tiop->c_cc[VLNEXT] = _POSIX_VDISABLE;
561 tiop->c_cc[VDSUSP] = _POSIX_VDISABLE;
564 /* Conditionally disable some other tty special characters if there is a
565 key binding for them in the current keymap. Readline ordinarily doesn't
566 bind these characters, but an application or user might. */
567 #if defined (VI_MODE)
568 kmap = (rl_editing_mode == vi_mode) ? vi_insertion_keymap : _rl_keymap;
572 #if defined (VDISCARD)
573 sc = tiop->c_cc[VDISCARD];
574 if (sc != _POSIX_VDISABLE && kmap[(unsigned char)sc].type == ISFUNC)
575 tiop->c_cc[VDISCARD] = _POSIX_VDISABLE;
576 #endif /* VDISCARD */
578 #endif /* TERMIOS_TTY_DRIVER && _POSIX_VDISABLE */
580 #endif /* !NEW_TTY_DRIVER */
582 /* Put the terminal in CBREAK mode so that we can detect key presses. */
583 #if defined (NO_TTY_DRIVER)
585 rl_prep_terminal (int meta_flag)
591 rl_deprep_terminal (void)
595 #else /* ! NO_TTY_DRIVER */
597 rl_prep_terminal (int meta_flag)
602 if (terminal_prepped)
605 /* Try to keep this function from being INTerrupted. */
608 tty = rl_instream ? fileno (rl_instream) : fileno (stdin);
610 if (get_tty_settings (tty, &tio) < 0)
612 #if defined (ENOTSUP)
613 /* MacOS X and Linux, at least, lie about the value of errno if
615 if (errno == ENOTTY || errno == EINVAL || errno == ENOTSUP)
617 if (errno == ENOTTY || errno == EINVAL)
619 _rl_echoing_p = 1; /* XXX */
621 _rl_release_sigint ();
627 if (_rl_bind_stty_chars)
629 #if defined (VI_MODE)
630 /* If editing in vi mode, make sure we restore the bindings in the
631 insertion keymap no matter what keymap we ended up in. */
632 if (rl_editing_mode == vi_mode)
633 rl_tty_unset_default_bindings (vi_insertion_keymap);
636 rl_tty_unset_default_bindings (_rl_keymap);
638 save_tty_chars (&otio);
639 RL_SETSTATE(RL_STATE_TTYCSAVED);
640 if (_rl_bind_stty_chars)
642 #if defined (VI_MODE)
643 /* If editing in vi mode, make sure we set the bindings in the
644 insertion keymap no matter what keymap we ended up in. */
645 if (rl_editing_mode == vi_mode)
646 _rl_bind_tty_special_chars (vi_insertion_keymap, tio);
649 _rl_bind_tty_special_chars (_rl_keymap, tio);
652 prepare_terminal_settings (meta_flag, otio, &tio);
654 if (set_tty_settings (tty, &tio) < 0)
656 _rl_release_sigint ();
660 if (_rl_enable_keypad)
661 _rl_control_keypad (1);
665 if (_rl_enable_bracketed_paste)
667 fprintf (rl_outstream, BRACK_PASTE_INIT);
668 nprep |= TPX_BRACKPASTE;
671 fflush (rl_outstream);
672 terminal_prepped = nprep;
673 RL_SETSTATE(RL_STATE_TERMPREPPED);
675 _rl_release_sigint ();
678 /* Restore the terminal's normal settings and modes. */
680 rl_deprep_terminal (void)
684 if (terminal_prepped == 0)
687 /* Try to keep this function from being interrupted. */
690 tty = rl_instream ? fileno (rl_instream) : fileno (stdin);
692 if (terminal_prepped & TPX_BRACKPASTE)
694 fprintf (rl_outstream, BRACK_PASTE_FINI);
696 fprintf (rl_outstream, "\n");
699 if (_rl_enable_keypad)
700 _rl_control_keypad (0);
702 fflush (rl_outstream);
704 if (set_tty_settings (tty, &otio) < 0)
706 _rl_release_sigint ();
710 terminal_prepped = 0;
711 RL_UNSETSTATE(RL_STATE_TERMPREPPED);
713 _rl_release_sigint ();
715 #endif /* !NO_TTY_DRIVER */
717 /* Set readline's idea of whether or not it is echoing output to the terminal,
718 returning the old value. */
720 rl_tty_set_echoing (int u)
729 /* **************************************************************** */
731 /* Bogus Flow Control */
733 /* **************************************************************** */
736 rl_restart_output (int count, int key)
738 #if defined (__MINGW32__)
740 #else /* !__MING32__ */
742 int fildes = fileno (rl_outstream);
743 #if defined (TIOCSTART)
745 ioctl (&fildes, TIOCSTART, 0);
747 ioctl (fildes, TIOCSTART, 0);
750 #else /* !TIOCSTART */
751 # if defined (TERMIOS_TTY_DRIVER)
752 # if defined (__ksr1__)
756 tcflow (fildes, TCOON);
759 tcflow (fildes, TCOON); /* Simulate a ^Q. */
761 # else /* !TERMIOS_TTY_DRIVER */
762 # if defined (TCXONC)
763 ioctl (fildes, TCXONC, TCOON);
765 # endif /* !TERMIOS_TTY_DRIVER */
766 #endif /* !TIOCSTART */
769 #endif /* !__MINGW32__ */
773 rl_stop_output (int count, int key)
775 #if defined (__MINGW32__)
779 int fildes = fileno (rl_instream);
781 #if defined (TIOCSTOP)
782 # if defined (apollo)
783 ioctl (&fildes, TIOCSTOP, 0);
785 ioctl (fildes, TIOCSTOP, 0);
787 #else /* !TIOCSTOP */
788 # if defined (TERMIOS_TTY_DRIVER)
789 # if defined (__ksr1__)
792 tcflow (fildes, TCOOFF);
794 # if defined (TCXONC)
795 ioctl (fildes, TCXONC, TCOON);
797 # endif /* !TERMIOS_TTY_DRIVER */
798 #endif /* !TIOCSTOP */
801 #endif /* !__MINGW32__ */
804 /* **************************************************************** */
806 /* Default Key Bindings */
808 /* **************************************************************** */
810 #if !defined (NO_TTY_DRIVER)
811 #define SET_SPECIAL(sc, func) set_special_char(kmap, &ttybuff, sc, func)
814 #if defined (NO_TTY_DRIVER)
816 #define SET_SPECIAL(sc, func)
817 #define RESET_SPECIAL(c)
819 #elif defined (NEW_TTY_DRIVER)
821 set_special_char (Keymap kmap, TIOTYPE *tiop, int sc, rl_command_func_t *func)
823 if (sc != -1 && kmap[(unsigned char)sc].type == ISFUNC)
824 kmap[(unsigned char)sc].function = func;
827 #define RESET_SPECIAL(c) \
828 if (c != -1 && kmap[(unsigned char)c].type == ISFUNC) \
829 kmap[(unsigned char)c].function = rl_insert;
832 _rl_bind_tty_special_chars (Keymap kmap, TIOTYPE ttybuff)
834 if (ttybuff.flags & SGTTY_SET)
836 SET_SPECIAL (ttybuff.sgttyb.sg_erase, rl_rubout);
837 SET_SPECIAL (ttybuff.sgttyb.sg_kill, rl_unix_line_discard);
840 # if defined (TIOCGLTC)
841 if (ttybuff.flags & LTCHARS_SET)
843 SET_SPECIAL (ttybuff.ltchars.t_werasc, rl_unix_word_rubout);
844 SET_SPECIAL (ttybuff.ltchars.t_lnextc, rl_quoted_insert);
846 # endif /* TIOCGLTC */
849 #else /* !NEW_TTY_DRIVER */
851 set_special_char (Keymap kmap, TIOTYPE *tiop, int sc, rl_command_func_t *func)
856 if (uc != (unsigned char)_POSIX_VDISABLE && kmap[uc].type == ISFUNC)
857 kmap[uc].function = func;
861 #define RESET_SPECIAL(uc) \
862 if (uc != (unsigned char)_POSIX_VDISABLE && kmap[uc].type == ISFUNC) \
863 kmap[uc].function = rl_insert;
866 _rl_bind_tty_special_chars (Keymap kmap, TIOTYPE ttybuff)
868 SET_SPECIAL (VERASE, rl_rubout);
869 SET_SPECIAL (VKILL, rl_unix_line_discard);
871 # if defined (VLNEXT) && defined (TERMIOS_TTY_DRIVER)
872 SET_SPECIAL (VLNEXT, rl_quoted_insert);
873 # endif /* VLNEXT && TERMIOS_TTY_DRIVER */
875 # if defined (VWERASE) && defined (TERMIOS_TTY_DRIVER)
876 # if defined (VI_MODE)
877 if (rl_editing_mode == vi_mode)
878 SET_SPECIAL (VWERASE, rl_vi_unix_word_rubout);
881 SET_SPECIAL (VWERASE, rl_unix_word_rubout);
882 # endif /* VWERASE && TERMIOS_TTY_DRIVER */
885 #endif /* !NEW_TTY_DRIVER */
887 /* Set the system's default editing characters to their readline equivalents
888 in KMAP. Should be static, now that we have rl_tty_set_default_bindings. */
890 rltty_set_default_bindings (Keymap kmap)
892 #if !defined (NO_TTY_DRIVER)
896 tty = fileno (rl_instream);
898 if (get_tty_settings (tty, &ttybuff) == 0)
899 _rl_bind_tty_special_chars (kmap, ttybuff);
903 /* New public way to set the system default editing chars to their readline
906 rl_tty_set_default_bindings (Keymap kmap)
908 rltty_set_default_bindings (kmap);
911 /* Rebind all of the tty special chars that readline worries about back
912 to self-insert. Call this before saving the current terminal special
913 chars with save_tty_chars(). This only works on POSIX termios or termio
916 rl_tty_unset_default_bindings (Keymap kmap)
918 /* Don't bother before we've saved the tty special chars at least once. */
919 if (RL_ISSTATE(RL_STATE_TTYCSAVED) == 0)
922 RESET_SPECIAL (_rl_tty_chars.t_erase);
923 RESET_SPECIAL (_rl_tty_chars.t_kill);
925 # if defined (VLNEXT) && defined (TERMIOS_TTY_DRIVER)
926 RESET_SPECIAL (_rl_tty_chars.t_lnext);
927 # endif /* VLNEXT && TERMIOS_TTY_DRIVER */
929 # if defined (VWERASE) && defined (TERMIOS_TTY_DRIVER)
930 RESET_SPECIAL (_rl_tty_chars.t_werase);
931 # endif /* VWERASE && TERMIOS_TTY_DRIVER */
934 #if defined (HANDLE_SIGNALS)
936 #if defined (NEW_TTY_DRIVER) || defined (NO_TTY_DRIVER)
938 _rl_disable_tty_signals (void)
944 _rl_restore_tty_signals (void)
950 static TIOTYPE sigstty, nosigstty;
951 static int tty_sigs_disabled = 0;
954 _rl_disable_tty_signals (void)
956 if (tty_sigs_disabled)
959 if (_get_tty_settings (fileno (rl_instream), &sigstty) < 0)
964 nosigstty.c_lflag &= ~ISIG;
965 nosigstty.c_iflag &= ~IXON;
967 if (_set_tty_settings (fileno (rl_instream), &nosigstty) < 0)
968 return (_set_tty_settings (fileno (rl_instream), &sigstty));
970 tty_sigs_disabled = 1;
975 _rl_restore_tty_signals (void)
979 if (tty_sigs_disabled == 0)
982 r = _set_tty_settings (fileno (rl_instream), &sigstty);
985 tty_sigs_disabled = 0;
989 #endif /* !NEW_TTY_DRIVER */
991 #endif /* HANDLE_SIGNALS */