fish-shell/tests/pexpects
Johannes Altmanninger b89619330b Disable terminal protocols before cancellable operations
The [disambiguate flag](https://sw.kovidgoyal.net/kitty/keyboard-protocol/#disambiguate) means that:

> In particular, ctrl+c will no longer generate the SIGINT signal,
> but instead be delivered as a CSI u escape code.

so cancellation only works while we turn off disambiguation.

Today we turn it off while running external commands that want to
claim the TTY.  Also we do it (only as a workaround for this issue)
while expanding wildcards or while running builtin wait.

However there are other cases where we don't have a workaround,
like in trivial infinite loops or when opening a fifo.

Before we run "while true; end", we put the terminal back in ICANON
mode. This means it's line-buffered, so we won't be able to detect
if the user pressed ctrl-c.

Commit 8164855b7 (Disable terminal protocols throughout evaluation,
2024-04-02) had the right solution: simply disable terminal protocols
whenever we do computations that might take a long time.
eval_node() covers most of that; there are a few others.

As pointed out in #10494, the logic was fairly unsophisticated then:
it toggled terminal protocols many times.  The fix in 29f2da8d1
(Toggle terminal protocols lazily, 2024-05-16) went to the extreme
other end of only toggling protocols when absolutely necessary.

Back out part of that commit by toggling in eval_node() again,
fixing cancellation.  Fortunately, we can keep most of the benefits
of the lazy approach from 29f2da8d1: we toggle only 2 times instead
of 8 times for an empty prompt.

There are only two places left where we call signal_check_cancel()
without necessarily disabling the disambiguate flag
1. open_cloexec() we assume that the files we open outside eval_node()
   are never blocking fifos.
2. fire_delayed(). Judging by commit history, this check is not
   relevant for interactive sessions; we'll soon end up calling
   eval_node() anyway.

In future, we can leave bracketed paste, modifyOtherKeys and
application keypad mode turned on again, until we actually run an
external command.  We really only want to turn off the disambiguate
flag.

Since this is approach is overly complex, I plan to go with either
of these two alternatives in future:
- extend the kitty keyboard protocol to optionally support VINTR,
  VSTOP and friends.  Then we can drop most of these changes.
- poll stdin for ctrl-c. This promises a great simplification,
  because it implies that terminal ownership (term_steal/term_donate)
  will be perfectly synced with us enabling kitty keyboard protocol.
  This is because polling requires us to turn off ICANON.
  I started working on this change; I'm convinced it must work,
  but it's not finished yet. Note that this will also want to
  add stdin polling to builtin wait.

Closes #10864
2024-11-24 16:11:57 +01:00
..
abbrs.py Allow restricting abbreviations to specific commands (#10452) 2024-04-24 18:09:04 +02:00
bind.py reader: Remove a panic 2024-06-10 17:14:13 +02:00
bind_mode_events.py Make bind_mode_events.py pass on Mac again 2024-05-06 10:26:32 -07:00
cancel_event.py Control-C to simply clear commandline buffer again 2024-01-17 19:54:57 +01:00
commandline.py Add pexpect test for commandline --showing-suggestion 2024-07-07 22:34:36 -05:00
complete-group-order.py complete: Sort --keep-order completions smaller 2024-10-05 13:53:02 +02:00
complete.py Disable terminal protocols throughout evaluation 2024-04-02 21:25:47 +02:00
cursor_selection.py Restyle fishscript and python 2023-06-01 18:20:19 +02:00
disable_mouse.py pexpects: More timeouts 2024-04-23 21:59:40 +02:00
eval-stack-overflow.py Restyle fishscript and python 2023-06-01 18:20:19 +02:00
exit.py Reformat 2020-11-22 14:39:48 +01:00
exit_handlers.py Add a test that fish_exit handlers run on receipt of SIGHUP 2020-08-30 15:09:34 -07:00
exit_nohang.py tests: Increase a sleep 2023-11-15 17:58:42 +01:00
fg.py Bravely reenable fg.py in CI for Mac 2024-06-02 15:11:51 -07:00
fkr.py fish_key_reader: use char_to_symbol for verbose output 2024-08-13 16:03:47 +02:00
generic.py Work around more spurious test failures 2024-05-07 17:55:29 +02:00
histfile.py Fix the histfile.py test 2024-06-02 15:31:19 -07:00
history.py Work around wants_terminal not begin set inside eval 2024-05-18 20:55:06 +02:00
isatty.py Reformat 2020-11-22 14:39:48 +01:00
job_summary.py tests/pexpect: Fix \d escape 2024-04-02 22:41:54 +02:00
nullterm.py Be careful to not touch curses variables if cur_term is null 2022-04-16 13:26:56 -07:00
pipeline.py Improve error for redirections to invalid paths 2021-11-20 17:44:05 +01:00
postexec.py Reformat 2020-11-22 14:39:48 +01:00
private_mode.py Restyle fishscript and python 2023-06-01 18:20:19 +02:00
read.py Disable terminal protocols before cancellable operations 2024-11-24 16:11:57 +01:00
set_color.py set_color: Print the given colors with --print-colors 2022-07-01 21:28:35 +02:00
sigint.py Add missing expect_prompt to test_sigint.py 2024-01-07 00:54:22 +01:00
signals.py Disable terminal protocols before cancellable operations 2024-11-24 16:11:57 +01:00
status.py Disable terminal protocols throughout evaluation 2024-04-02 21:25:47 +02:00
stdin_nonblocking.py stdin_nonblocking.py test to not leave background processes 2022-02-12 11:48:55 -08:00
terminal.py Disable terminal protocols throughout evaluation 2024-04-02 21:25:47 +02:00
torn_escapes.py Help the torn_escapes test pass on Mac 2024-05-06 10:26:32 -07:00
tty_ownership.py Claim the tty unconditionally in reader_data_t::readline 2022-09-09 13:43:29 -07:00
undo.py Fix the undo pexpect 2024-06-02 14:17:36 -07:00
wait.py share/config.fish: Quit if job expansion hack errors 2023-06-10 15:36:36 +02:00
wildcard_tab.py Restyle fishscript and python 2023-06-01 18:20:19 +02:00