Work around wants_terminal not begin set inside eval

On this binding we fail to disable CSI u

    bind c-t '
        begin
            set -lx FZF_DEFAULT_OPTS --height 40% --bind=ctrl-z:ignore
            eval fzf | while read -l r; echo read $r; end
        end
    '

because for "fzf", ParseExecutionContext::setup_group() returns early with the
parent process group (which should be fish's own) , hence "wants_terminal"
is false. This seems questionable, I don't think the eval should make a
difference here.

For now, don't touch it; use the more accurate way of detecting whether
a process may read keyboard input. In many of such cases "wants_terminal"
is false, like

    echo (echo 1\n2\n3 | fzf)

Fixes #10504
This commit is contained in:
Johannes Altmanninger 2024-05-18 19:54:13 +02:00
parent ef614ba2d9
commit d40d2b786f
5 changed files with 16 additions and 12 deletions

View file

@ -147,10 +147,11 @@ pub fn fg(parser: &Parser, streams: &mut IoStreams, argv: &mut [&wstr]) -> Optio
{
let job_group = job.group();
job_group.set_is_foreground(true);
let tmodes = job_group.tmodes.borrow();
if job_group.wants_terminal() {
if job.entitled_to_terminal() {
terminal_protocols_disable_ifn();
if tmodes.is_some() {
}
let tmodes = job_group.tmodes.borrow();
if job_group.wants_terminal() && tmodes.is_some() {
let termios = tmodes.as_ref().unwrap();
let res = unsafe { libc::tcsetattr(STDIN_FILENO, TCSADRAIN, termios) };
if res < 0 {
@ -158,7 +159,6 @@ pub fn fg(parser: &Parser, streams: &mut IoStreams, argv: &mut [&wstr]) -> Optio
}
}
}
}
let mut transfer = TtyTransfer::new();
transfer.to_job_group(job.group.as_ref().unwrap());
let resumed = job.resume();

View file

@ -72,7 +72,7 @@ pub fn exec_job(parser: &Parser, job: &Job, block_io: IoChain) -> bool {
return true;
}
if job.group().wants_terminal() {
if job.entitled_to_terminal() {
terminal_protocols_disable_ifn();
}

View file

@ -886,6 +886,10 @@ impl Job {
self.group().wants_job_control()
}
pub fn entitled_to_terminal(&self) -> bool {
self.group().is_foreground() && self.processes().iter().any(|p| !p.is_internal())
}
/// Return whether this job is initially going to run in the background, because & was
/// specified.
pub fn is_initially_background(&self) -> bool {

View file

@ -192,7 +192,7 @@ expect_prompt("nonephemeral! line")
sendline("true")
expect_prompt()
sendline("echo a; history search '*ephemeral!*' | cat; echo b")
expect_prompt("a\r\necho nonephemeral! line\r\nb\r\n")
expect_prompt(r"a\r\n.*echo nonephemeral! line\r\nb\r\n")
# If fish_should_add_to_history exists, it will completely take over,
# so even lines with spaces are stored
@ -201,4 +201,4 @@ expect_prompt("spaced")
sendline("true")
expect_prompt()
sendline("echo a; history search '*spaced*' | cat; echo b")
expect_prompt("a\r\n echo spaced\r\nb\r\n")
expect_prompt("a\r\n.* echo spaced\r\nb\r\n")

View file

@ -13,7 +13,7 @@ send, sendline, sleep, expect_prompt, expect_re, expect_str = (
def expect_read_prompt():
expect_re(r"\r\n?read> $")
expect_re(r"\r\n?read> .*$")
def expect_marker(text):