tty driver ignore lnext (\cV) and werase (\cW)

Configure the tty driver to ignore the lnext (\cV) and werase (\cW) characters
so they can be bound to fish functions.

Correct the `fish_key_bindings` program to initialize the tty in the same
manner as the `fish` program.

Fixes #3064
This commit is contained in:
Kurtis Rader
2016-05-24 20:42:50 -07:00
parent d7a4838a54
commit d1208386d2
4 changed files with 42 additions and 55 deletions

View File

@@ -784,23 +784,19 @@ void reader_init() {
// Set the mode used for the terminal, initialized to the current mode.
memcpy(&shell_modes, &terminal_mode_on_startup, sizeof shell_modes);
shell_modes.c_iflag &= ~ICRNL; // turn off mapping CR (\cM) to NL (\cJ)
shell_modes.c_iflag &= ~INLCR; // turn off mapping NL (\cJ) to CR (\cM)
shell_modes.c_iflag &= ~ICRNL; // disable mapping CR (\cM) to NL (\cJ)
shell_modes.c_iflag &= ~INLCR; // disable mapping NL (\cJ) to CR (\cM)
shell_modes.c_iflag &= ~IXON; // disable flow control
shell_modes.c_iflag &= ~IXOFF; // disable flow control
shell_modes.c_lflag &= ~ICANON; // turn off canonical mode
shell_modes.c_lflag &= ~ECHO; // turn off echo mode
shell_modes.c_iflag &= ~IXON; // disable flow control
shell_modes.c_iflag &= ~IXOFF; // disable flow control
shell_modes.c_lflag &= ~IEXTEN; // turn off handling of discard and lnext characters
shell_modes.c_cc[VMIN] = 1;
shell_modes.c_cc[VTIME] = 0;
#if defined(_POSIX_VDISABLE)
// PCA disable VDSUSP (typically control-Y), which is a funny job control. function available only
// on OS X and BSD systems. This lets us use control-Y for yank instead.
#ifdef VDSUSP
shell_modes.c_cc[VDSUSP] = _POSIX_VDISABLE;
#endif
#endif
// We don't use term_steal because this can fail if fd 0 isn't associated with a tty and this
// function is run regardless of whether stdin is tied to a tty. This is harmless in that case.
// We do it unconditionally because disabling ICRNL mode (see above) needs to be done at the
@@ -1107,8 +1103,7 @@ wcstring completion_apply_to_command_line(const wcstring &val_str, complete_flag
// Perform the insertion and compute the new location.
wcstring result = command_line;
result.insert(insertion_point, replaced);
size_t new_cursor_pos =
insertion_point + replaced.size() + (back_into_trailing_quote ? 1 : 0);
size_t new_cursor_pos = insertion_point + replaced.size() + (back_into_trailing_quote ? 1 : 0);
if (add_space) {
if (quote != L'\0' && unescaped_quote(command_line, insertion_point) != quote) {
// This is a quoted parameter, first print a quote.