Wilfred / difftastic

a structural diff that understands syntax 🟥🟩
https://difftastic.wilfred.me.uk/
MIT License
20.59k stars 333 forks source link

difftastic do not show color in fzf preview #716

Open dsypasit opened 4 months ago

dsypasit commented 4 months ago

I tried to use difft to show the difference inside fzf. In the previous script, it showed colors but not in difft. However, when I used 'git show', it displayed correctly. What's wrong with it?

previous script

git log --oneline --format="%C(auto)%h %s%d" | fzf --ansi --preview "git show --color=always {1}" --bind 'enter:become(echo {1})'

image

using difftastic

git log --oneline --format="%C(auto)%h %s%d" | fzf --ansi --preview "GIT_EXTERNA_DIFF=difft git show --color=always {1} --ext-diff " --bind 'enter:become(echo {1})'

image

difftastic version

dotfile on  main [!⇡]
❯ difft --version
Difftastic 0.58.0 (0c9277108 2024-05-10, built with rustc 1.78.0)
bvergnaud commented 3 months ago

Hello 👋🏻

That's because difftastic, like many CLI tools, disables colored output by default when the output is redirected somewhere other than a terminal.

I've been configuring something similar for myself over the past couple of days so I can tell you it works for sure with this bit of git configuration:

[diff]
    external = difft --color=always

I'd assume you can do the same thing through the environment variable GIT_EXTERNAL_DIFF=difft --color=always but I haven't tested it.

Hope it helps. ;)