Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Colors broken in fzf preview on Windows (mintty) #4199

Open
5 of 10 tasks
kleymionov opened this issue Jan 23, 2025 · 8 comments
Open
5 of 10 tasks

Colors broken in fzf preview on Windows (mintty) #4199

kleymionov opened this issue Jan 23, 2025 · 8 comments
Labels

Comments

@kleymionov
Copy link

Checklist

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

Output of fzf --version

0.56.3 (tarball)

OS

  • Linux
  • macOS
  • Windows
  • Etc.

Shell

  • bash
  • zsh
  • fish

Problem / Steps to reproduce

Syntax and line highlighting produced by bat are incorrectly displayed by fzf preview on mintty:
#> echo | fzf --preview="bat --theme=1337 --highlight-line=2 --color=always test.sh | tee out.txt"
Image
#> cat out.txt
Image

The issue is also reproducible on Alacritty and ConEmu.
Colors are kept intact only on Windows Terminal, but it is unusably slow and laggy.

@junegunn
Copy link
Owner

Does bat --theme=1337 --highlight-line=2 --color=always test.sh itself produce the right colors?

@t40mas
Copy link

t40mas commented Jan 23, 2025

I don't know if the behavior is related to my problem, but it seems that fzf is not passing the current appearance to bat or it's not available anymore. Even if I run fzf with --color=dark.

Image

fzf --preview="bat --theme-dark='Catppuccin Mocha' --color=always {}"

Image

If I specify the theme directly, everything works as expected:
fzf --preview="bat --theme='Catppuccin Mocha' --color=always {}";

Image

Many thanks for your work!!!

@kleymionov
Copy link
Author

Does bat --theme=1337 --highlight-line=2 --color=always test.sh itself produce the right colors?

Yes, output is similar to shown by cat out.txt.

@kleymionov
Copy link
Author

I don't know if the behavior is related to my problem

Yes, this is the same problem: fzf somehow transforms color codes received from bat.

@junegunn
Copy link
Owner

It is probably because of winpty. Can you try setting export MSYS=enable_pcon?

func needWinpty(opts *Options) bool {
if os.Getenv("TERM_PROGRAM") != "mintty" {
return false
}
if isMintty345() {
/*
See: https://github.com/junegunn/fzf/issues/3809
"MSYS=enable_pcon" allows fzf to run properly on mintty 3.4.5 or later.
*/
if strings.Contains(os.Getenv("MSYS"), "enable_pcon") {
return false
}
// Setting the environment variable here unfortunately doesn't help,
// so we need to start a child process with "MSYS=enable_pcon"
// os.Setenv("MSYS", "enable_pcon")
return true
}
if opts.NoWinpty {
return false
}
if _, err := exec.LookPath("winpty"); err != nil {
return false
}
return true
}

Related:

@kleymionov
Copy link
Author

Can you try setting export MSYS=enable_pcon?

Same result. It's not only mintty related, but also reproducible with Alacritty and ConEmu.

@junegunn
Copy link
Owner

I don't know if the behavior is related to my problem

Yes, this is the same problem: fzf somehow transforms color codes received from bat.

I don't think it's the same problem. He said "If I specify the theme directly, everything works as expected".

@t40mas It looks like 'bat' somehow fails to detect the terminal theme (dark or light) when run inside the preview window of fzf. --dark option of fzf only changes the colors of fzf, and it does not do anything beyond that.

@kleymionov
Copy link
Author

everything works as expected

It seems that together with bat's theme-dark problem, it just happened that 'Catppuccin Mocha' theme colors are not that much warped by fzf pass-through. But there are still slight differences in colors, and --highlight-line, if specified for bat, is not highlighted in preview window with this theme.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants