daveewart / colordiff

Primary development for colordiff
http://www.colordiff.org/
GNU General Public License v2.0
177 stars 37 forks source link

colordiff -y: no colour output on MacOS #55

Open guyg-codes opened 2 years ago

guyg-codes commented 2 years ago

I'm able to get coloured output with a standard colordiff, but not when the -y arg (side-by-side output) is provided.

A previous issue on this topic appeared to be resolved by updating to the latest colordiff release, I believe I am already running on 1.0.20

Field Value
MacOS Monterey 12.3
CPU M1 - ARM-based
package manager brew
coreutils gnu - via brew
colordiff --version diff (GNU diffutils) 2.8.1
which colordiff /opt/homebrew/bin/colordiff
brew info colordiff colordiff: stable 1.0.20 (bottled)
...
/opt/homebrew/Cellar/colordiff/1.0.20 (10 files, 60.7KB) *

Issue Detail

The output of the following to commands is identical (i.e. no colouring at all)

colordiff -y file1 file2 diff -y file1 file2 | colordiff

Steps Taken

I have tried to run with a variety of additional args (--strip-trailing, --supress-common-lines) and tried diff'ing several files - all with the same result.

Any help would be much appreciated, colordiff is a huge improvement over the original diff, much appreciation for your work! Cheers, Guy

daveewart commented 2 years ago

I've just attempted to replicate this issue (Mac Mini M1, Monterey 12.3.1) and cannot do so. It works fine for me. Have also tried various files to test comparison.

Unclear why this isn't working for you: are you able to share an example pair of files for which you see it failing?

guyg-codes commented 2 years ago

Hi @daveewart, I played around some more and I thought I had found the culprit - the original file(s) I was trying to diff include an unusual unicode character (↳ - https://unicode-table.com/en/21B3/).

After more testing, it's unclear this char/line is the problem, I can't reproduce the issue copying the line or recreating the issue with the char in some test files.

Testing more generally with other files, colordiff -y does appear to be working with coloured output.

file1 file2

daveewart commented 2 years ago

Not quite sure where to take it from here. I'm also unclear what your attachments are about: first one is init.vim and the second one is a Google Drive link that is asking me to request access.

I'm tempted to close this Issue, unless you have a reproducible test case?

guyg-codes commented 2 years ago

Hi Dave, thanks for your patience - apparently generating a public link for a Gdrive file doesn't also set the sharing permissions to public, file2 should be accessible now.

daveewart commented 2 years ago

OK, interesting.

colordiff -y init.vim.tmp_adoc_folds init.vim

produces coloured output, but

colordiff -y init.vim init.vim.tmp_adoc_folds

does not. I think I understand why. It is likely to be because this is a very 'asymmetric' diff.

Explanation: colordiff does not understand diff operations, it is simply taking the (text) output of a diff and attempting to interpret it. For 'diff -y' it has to do a lot of work to try to detect where the middle separators are (the '<', '>' and '|'). It does this by looking for one of those characters with a space on either side. (See the code for the details). In your example, because one of the files is almost empty, there is nothing at all for most of the compared lines: when the short file is the second listed, the lines all end with ' <' with no following space, thus the script fails to identify the separator location.

I don't think there's much can be done with this, although I guess that diff-detection code could be extended.