junegunn / fzf

:cherry_blossom: A command-line fuzzy finder
https://junegunn.github.io/fzf/
MIT License
64.3k stars 2.38k forks source link

Alt-c overwrites prompt that is in next line #3765

Open Drllap opened 5 months ago

Drllap commented 5 months ago

Checklist

Output of fzf --version

0.48.1 (9ffe951f)

OS

Shell

Problem / Steps to reproduce

I'm using starship and have a theme where the prompt continues on the next line. If I use Alt+C to cd the curser ends up before the prompt: alt-c-fzf When I go out of vi-insert-mode the prompt overwrites what was written

Edit: This is what I have in my .bashrc

eval "$(fzf --bash)"
eval "$(starship init bash)"

The starship config can be found here

Drllap commented 5 months ago

Note that if I execute after leaving the vi-insert-mode the "correct" thing is executed (the prompt arrow doesn't affect it) so this is only a minor visual glitch

Drllap commented 5 months ago

Also, why do I get `__fzf_cd__` when I use Alt+c? I don't get `__fzf_history__` when I use Ctrl+r or nvim ** <tab>. Is it intentional?

tmpm697 commented 5 months ago

this is probably how u play with fzf, i got this issue before, but it does not appear now.

Drllap commented 5 months ago

@tmpm697 I'm not entirely sure what you mean by "how you play with fzf"

I'm just using the default keybindings. The only thing I have in my .bashrc

eval "$(fzf --bash)"
eval "$(starship init bash)"
junegunn commented 5 months ago

Also, why do I get `__fzf_cd__` when I use Alt+c? I don't get `__fzf_history__` when I use Ctrl+r or nvim ** <tab>. Is it intentional?

That's because ALT-C uses a different mechanism than the others. No -x option.

https://github.com/junegunn/fzf/blob/7bac1a761c9040542d9bd73d860fe0b9e2fb7ac5/shell/key-bindings.bash#L126-L144

The reason we decided to use this method (only for ALT-C) can be found here: https://github.com/junegunn/fzf/pull/2674 (and an older one: https://github.com/junegunn/fzf/issues/546#issuecomment-213891483)

I have no experience with starship, so I'm currently unaware of how you can work around the issue.

Drllap commented 4 months ago

Ok, I narrowed it down a bit. This is pretty much what starship does when I have deleted most of the things that aren't relevant to my issue:

function set_PS1 {
  PS1="something cool
\[\]\[\] "
}

precmd_functions+=(set_PS1)

Edit: Ok github doesn't render all of the "characters" in the file so here is the file: test-bashrc.txt

Drllap commented 4 months ago

Did a little bit more digging. So, I have WezTerm installed, and it supports prompt scrolling: See here.

To accomplish this it injects OSC 133 before and after my prompt, so effectively it does:

PS1='\[\e]133;P;k=i\a\]'$PS1'\[\e]133;B\a\]'

This seems to be what triggers my issue. So if put

PS1="\[\e]133;P;k=i\a\]-> \[\e]133;B\a\]"

in my .bashrc, I get the cursor starts at the beginning of prompt when I exit ALT-C