Enable focus reporting only just before reading from stdin

Some terminals send the focus-in sequences ("^[I") whenever focus reporting is
enabled.  We enable focus reporting whenever we are finished running a command.
If we run two commands without reading in between, the focus sequences
will show up on the terminal.

Fix this by enabling focus-reporting as late as possible.

This fixes the problem with `^[I` showing up when running "cat" in
gnome-terminal https://github.com/fish-shell/fish-shell/issues/10411.

This begs the question if we should do the same for CSI u and bracketed paste.
It's difficult to answer that; let's hope we find motivating test cases.
If we enable CSI u too late, we might misinterpret key presses, so for now
we still enable those as early as possible.

Also, since we now read immediately after enabling focus events, we can get
rid of the hack where we defer enabling them until after the first prompt.
When I start a fresh terminal, the ^[I no longer shows up.
This commit is contained in:
Johannes Altmanninger
2024-04-06 07:42:05 +02:00
parent 7ffe023735
commit f285e85b0c
9 changed files with 34 additions and 31 deletions

View File

@@ -39,7 +39,6 @@ def get_prompt_re(counter):
(?:\x1b[>4;1m) # XTerm's modifyOtherKeys
(?:\x1b[>5u) # CSI u with kitty progressive enhancement
(?:\x1b=) # set application keypad mode, so the keypad keys send unique codes
(?:\x1b[\?1004h)? # enable focus notify
(?:\[.\]\ )? # optional vi mode prompt
"""
+ (r"prompt\ %d>" % counter) # prompt with counter