fzf icon indicating copy to clipboard operation
fzf copied to clipboard

feat: --color=auto

Open WhyNotHugo opened this issue 4 months ago • 9 comments

This is a feature request for a new options to --color, auto.

This new option shall query the terminal via OSC11 to determine the background colour. If the background is dark, then theme = dupeTheme(tui.Dark256). If the background is light, then theme = dupeTheme(tui.Light256).

The intent here is to allow fzf to the correct theme depending on whether the terminal is currently set to dark mode or light mode.


I tried to implement this myself, but I'm not familiar enough with the codebase. The main entry point for the change is in src/options.go:parseTheme, but beyond that, I'm not sure how to use control sequences. If you have guidance on this, I can try and work up a patch.

WhyNotHugo avatar Aug 13 '25 10:08 WhyNotHugo

Integer values in a --color option correspond to your terminal emulators corresponding color definition. By configuring fzf to use your terminals color definitions, you ensure that when your terminal colors change, so does fzf.

For example, here's a video showing me toggling my system light/dark mode, which toggles my terminals colors, which then gets reflected in fzf:

https://github.com/user-attachments/assets/7899a800-f57b-480b-8355-72ecc6f8b349

I make no claims that these are good colors or pretty colors. Just that you can achieve what you are asking if you configure things correctly.

Here are my fzf --color options from the video:

--color=fg:-1
--color=fg+:-1
--color=bg:-1
--color=bg+:20
--color=pointer:-1
--color=header:1
--color=border:4
--color=hl:16
--color=hl+:17
--color=info:21
--color=prompt:2
--color=marker:21
--color=spinner:21
--color=scrollbar:dim

Relevant manual section: https://github.com/junegunn/fzf/blob/9a53d84b9cce3a0be12fb98e313726ecc806f034/man/man1/fzf.1#L303-L333

andelink avatar Aug 23 '25 00:08 andelink

Thanks @andelink for sharing a nice theme that works well in both dark and light modes.

If you switch between dark and light modes, you'll get better results if you only use the base 16 colors that are defined by each theme. --color=16 provides a good starting point.


Auto-detecting the background color brightness can be done, but it's not trivial to implement it in a portable way (Windows), and if I'm not mistaken, it's not supported by all terminal emulators, so I'm going to take some time to see if we really need it. For now, I would recommend using --color=16.

junegunn avatar Aug 23 '25 01:08 junegunn

FZF_DEFAULT_OPTS='--colors=16' works for text, but borders don't have any colour in dark mode.

WhyNotHugo avatar Aug 23 '25 08:08 WhyNotHugo

FZF_DEFAULT_OPTS='--colors=16' works for text, but borders don't have any colour in dark mode.

The currently selected line is also not highlighted on dark mode.

WhyNotHugo avatar Aug 23 '25 08:08 WhyNotHugo

it's not supported by all terminal emulators

This is likely, some emulators don't have any features from the last decade.

Is it reasonable to simply fall back to default (or 16) if detecting the mode is unsupported by the emulator?

WhyNotHugo avatar Aug 23 '25 08:08 WhyNotHugo

I don't have any of the problems with --color=16, I suspect it's because of your terminal color scheme (possibly the black text being unreadable), and you might want to try again with a different one.

If I run this script on my terminal:

https://gist.github.com/sdeaton2/8450564

I get this result:

Image

junegunn avatar Aug 24 '25 06:08 junegunn

Also, I believe --color=16 is the better default for those who care a lot about the colors, because it uses the colors defined by the user's theme. In contrast, --color=dark and --color=light use the colors picked by me based on my preferences a decade ago, which may not blend well with the user's theme.

junegunn avatar Aug 24 '25 06:08 junegunn

possibly the black text being unreadable

I think we can consider changing the color of the border from black to dim, so it works better even with themes that have this limitation.

junegunn avatar Aug 24 '25 06:08 junegunn

See #4501

junegunn avatar Aug 24 '25 06:08 junegunn