Disable focus reporting on non-tmux again for now

We sometimes leak ^[[I and ^[[O focus reporting events when run from VSCode's
"Run python file" button in the top right corner. To reproduce I installed
the ms-python extension set the VSCode default shell to fish and repeatedly
ran a script that does "time.sleep(1)". I believe VSCode synthesizes keys
and triggers a race condition.

We can probably fix this but I'm not sure when I'll get to it (given how
relatively unimportant this feature is).

So let's go back to the old behavior of only enabling focus reporting in tmux.

I believe that tmux is affected by the same VSCode issue (also on 3.7.1 I
think) but I haven't been able to get tmux to emit focus reporting sequences
yet.  Still, keep it to not regress cursor shape (#4788).  So far this is
the only motivation for focus reporting and I believe it is only relevant
for terminals that can split windows (though there are a bunch that do).

Closes #10448
This commit is contained in:
Johannes Altmanninger 2024-04-18 10:21:28 +02:00
parent ed8f62e723
commit bdd478bbd0
5 changed files with 14 additions and 7 deletions

View File

@ -150,9 +150,7 @@ Improved terminal support
- Fish now sets the terminal window title (via OSC 0) unconditionally instead of only for some terminals (:issue:`10037`). - Fish now sets the terminal window title (via OSC 0) unconditionally instead of only for some terminals (:issue:`10037`).
- Fish now marks the prompt and command-output regions (via OSC 133) to enable terminal shell integration (:issue:`10352`). - Fish now marks the prompt and command-output regions (via OSC 133) to enable terminal shell integration (:issue:`10352`).
Shell integration shortcuts can scroll to the next/previous prompt or show the last command output in a pager. Shell integration shortcuts can scroll to the next/previous prompt or show the last command output in a pager.
- Focus reporting is enabled unconditionally, not just inside tmux. - Focus reporting in tmux is no longer disabled on the first prompt.
To use it, define functions that handle events ``fish_focus_in`` and ``fish_focus_out``.
- Focus reporting is no longer disabled on the first prompt.
Other improvements Other improvements
------------------ ------------------

View File

@ -7,6 +7,7 @@ use crate::common::{
use crate::env::{EnvStack, Environment}; use crate::env::{EnvStack, Environment};
use crate::fd_readable_set::FdReadableSet; use crate::fd_readable_set::FdReadableSet;
use crate::flog::FLOG; use crate::flog::FLOG;
use crate::global_safety::RelaxedAtomicBool;
use crate::input::KeyNameStyle; use crate::input::KeyNameStyle;
use crate::key::{ use crate::key::{
self, alt, canonicalize_control_char, canonicalize_keyed_control_char, function_key, shift, self, alt, canonicalize_control_char, canonicalize_keyed_control_char, function_key, shift,
@ -515,7 +516,12 @@ fn terminal_protocols_disable_impl() {
let _ = write_to_fd(sequences.as_bytes(), STDOUT_FILENO); let _ = write_to_fd(sequences.as_bytes(), STDOUT_FILENO);
} }
pub(crate) static IS_TMUX: RelaxedAtomicBool = RelaxedAtomicBool::new(false);
pub(crate) fn focus_events_enable_ifn() { pub(crate) fn focus_events_enable_ifn() {
if !IS_TMUX.load() {
return;
}
let mut term_protocols = TERMINAL_PROTOCOLS.get().borrow_mut(); let mut term_protocols = TERMINAL_PROTOCOLS.get().borrow_mut();
let Some(term_protocols) = term_protocols.as_mut() else { let Some(term_protocols) = term_protocols.as_mut() else {
panic!() panic!()

View File

@ -71,6 +71,7 @@ use crate::history::{
}; };
use crate::input::init_input; use crate::input::init_input;
use crate::input::Inputter; use crate::input::Inputter;
use crate::input_common::IS_TMUX;
use crate::input_common::{ use crate::input_common::{
focus_events_enable_ifn, terminal_protocols_enable_scoped, CharEvent, CharInputStyle, focus_events_enable_ifn, terminal_protocols_enable_scoped, CharEvent, CharInputStyle,
ReadlineCmd, ReadlineCmd,
@ -3660,6 +3661,8 @@ fn reader_interactive_init(parser: &Parser) {
parser parser
.vars() .vars()
.set_one(L!("_"), EnvMode::GLOBAL, L!("fish").to_owned()); .set_one(L!("_"), EnvMode::GLOBAL, L!("fish").to_owned());
IS_TMUX.store(parser.vars().get_unless_empty(L!("TMUX")).is_some());
} }
/// Destroy data for interactive use. /// Destroy data for interactive use.

View File

@ -13,7 +13,7 @@ send, sendline, sleep, expect_prompt, expect_re, expect_str = (
def expect_read_prompt(): def expect_read_prompt():
expect_re(r"\r\n?read> \x1b\[\?1004h$") expect_re(r"\r\n?read> (\x1b\[\?1004h)?$")
def expect_marker(text): def expect_marker(text):
@ -56,12 +56,12 @@ print_var_contents("foo", "bar")
# read -c (see #8633) # read -c (see #8633)
sendline(r"read -c init_text somevar && echo $somevar") sendline(r"read -c init_text somevar && echo $somevar")
expect_re(r"\r\n?read> init_text\x1b\[\?1004h$") expect_re(r"\r\n?read> init_text(\x1b\[\?1004h)?$")
sendline("someval") sendline("someval")
expect_prompt("someval\r\n") expect_prompt("someval\r\n")
sendline(r"read --command='some other text' somevar && echo $somevar") sendline(r"read --command='some other text' somevar && echo $somevar")
expect_re(r"\r\n?read> some other text\x1b\[\?1004h$") expect_re(r"\r\n?read> some other text(\x1b\[\?1004h)?$")
sendline("another value") sendline("another value")
expect_prompt("another value\r\n") expect_prompt("another value\r\n")

View File

@ -47,7 +47,7 @@ expect_prompt()
sendline("function postexec --on-event fish_postexec; echo fish_postexec spotted; end") sendline("function postexec --on-event fish_postexec; echo fish_postexec spotted; end")
expect_prompt() expect_prompt()
sendline("read") sendline("read")
expect_re(r"\r\n?read> \x1b\[\?1004h$") expect_re(r"\r\n?read> (\x1b\[\?1004h)?$")
sleep(0.200) sleep(0.200)
os.kill(sp.spawn.pid, signal.SIGINT) os.kill(sp.spawn.pid, signal.SIGINT)
expect_str("fish_postexec spotted") expect_str("fish_postexec spotted")