fzf icon indicating copy to clipboard operation
fzf copied to clipboard

[FR] osc10/11 support in preview window

Open phanen opened this issue 10 months ago • 1 comments

Checklist

  • [x] I have read through the manual page (man fzf)
  • [x] I have searched through the existing issues
  • [x] For bug reports, I have checked if the bug is reproducible in the latest version of fzf

Output of fzf --version

0.60.3 (0012183e)

OS

  • [x] Linux
  • [ ] macOS
  • [ ] Windows
  • [ ] Etc.

Shell

  • [x] bash
  • [x] zsh
  • [x] fish

Problem / Steps to reproduce

Change a light background in terminal then do this with delta:

: | fzf --preview 'git show|delta'

You will find delta will use dark theme. Image

That's because delta use osc10/11 to detect fg/bg color.

  • related: https://github.com/ibhagwan/fzf-lua/pull/1885.

Although I can set --light/--dark in a "smart script wrapper" (e.g. fzf-lua) that can tell if we are in dark/light mode. I think if would be better if fzf is able to response to escape sequence. Image

e.g. In nvim/vim we have autocmd: TermRequest from "child" and TermResponse from "host" (e.g. kitty).

Maybe fzf can have a similar concept as a "event".

phanen avatar Mar 19 '25 02:03 phanen

I'm not sure how we can do this.

OSC 10/11 querying requires

  1. directly writing to /dev/tty,
  2. making it spit out some escape sequence,
  3. and directly reading from it.

But at the same time, fzf is reading from /dev/tty for the user input. So as a result of this conflict, fzf gets this strange unwanted sequence, and the preview program doesn't get the response and hangs.

The only option would be to block fzf during the execution of the preview program. But we know that is not acceptable.

I think if would be better if fzf is able to response to escape sequence.

The problem here is that it's not fzf that should respond to the sequence, but it's the preview program. Once fzf intercepts the sequence, it's not possible to pass it to the running preview program.


Another thing to consider is that the preview window can be configured to have non-default foreground and background colors.

export FZF_DEFAULT_OPTS='--color fg:black,bg:white,preview-fg:white,preview-bg:black'

# Light or dark?
fzf --margin 3 --preview 'echo {}'

Maybe we can make fzf perform OSC 10/11 query at the beginning and determine the initial color palette (--color light), but once it starts reading from /dev/tty for user input, we can't do it anymore.

junegunn avatar Mar 19 '25 10:03 junegunn