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

word-diff for the plaintext fallback parser #497

Open
int opened this issue Mar 14, 2023 · 4 comments
Open

word-diff for the plaintext fallback parser #497

int opened this issue Mar 14, 2023 · 4 comments

Comments

@int
Copy link

int commented Mar 14, 2023

Not a bug. Just a feature request (label: enhancement).

(1) A description of the issue. A screenshot is often helpful too.

Currently, difftastic treats plain text (the fallback) as a simple line-oriented diff.
Would be nice if we can enable some kind of word-diff for it.

In real life, various config files are treated as plain text (fallback). And if we only
change a small part of a line (e.g. theme="onedark" -> theme="twodark"),
word-diff would make the output more pleasant than the plain line-diff.

Below are some screenshots of an "artificial" use case showing remove/change/insert.

difft a.txt b.txt:
difft

difft --display inline a.txt b.txt:
difft inline

git diff --no-index --color-words=. a.txt b.txt:
git diff word-diff

Since we are advertising difft as more than word-diff at our front page,
can we make it behave similarly for the fallback plain text?

(2) A copy of what you're diffing.

------a.txt-----
hi, this is a sample text.
you can edit it as freely as you can.
cheers

------b.txt-----
hi, this is a sample txt.
you can change it as freely as you can.
cheers!

(3) The version of difftastic you're using (see difft --version) and
your operating system.

Difftastic 0.45.0
WSL 2 on Windows 10

@Wilfred
Copy link
Owner

Wilfred commented Mar 14, 2023

There is word-level diffing, but I'm guessing the bright and bold style isn't supported in your terminal.

Screenshot from 2023-03-14 08-16-08

That said, this is kinda subtle, especially for the changed !. Difftastic will underline changed words when diffing comments in code, but it can be overwhelming when most of the words on a line have changed.

@joyously
Copy link

Do those colors have meaning?
(It looks to me as if the red means deleted and the green means added, but maybe that's a notion I got from somewhere else. To a color blind person or a terminal that doesn't do bold, it looks like the entire line changed.)

@int
Copy link
Author

int commented Mar 16, 2023

There is word-level diffing

Cool. So the functionality has already been there. :)

but I'm guessing the bright and bold style isn't supported in your terminal.

Yeah. Seems Windows Terminal doesn't enable it by default. Here for a fix.

That said, this is kinda subtle

Yes Indeed.
How about we don't highlight those unchanged parts at all?
Make it just like what we did for the "recognized" programming languages.

The --color-words (--word-diff-regex) is an extra feature -- it lets you define what a "word" is.
In the screenshot of git above, it treats each char as a word.

And probably an independent topic (but kinda related with word-diff):
Looks I was confused by the different modes of difft --display.
Now I realize that for difft:

  • side-by-side is usually side-by-side-show-both unless lhs_changes or rhs_changes is empty
  • side-by-side-show-both is the REAL side by side for me, and then
  • inline is just good old "unified" diff.

A color-words (or merged) mode would be nice (see the git screenshot above).
(Well, personally I call it "inline" - probably just me).

Keeping old names and semantics unchanged to avoid compatible issues,
I'd suggest these three names/modes:

  • both -- alias for the old side-by-side-show-both
  • unified -- alias for the old inline
  • merged -- the old side-by-side when lhs/rhs empty + the new color-words

I for one would make both or merged as default.
It's kinda surprising (at least for me) that side-by-side sometimes only show one side
and we have to specify another suffix show-both to really show both sides.

@int
Copy link
Author

int commented Mar 17, 2023

Related: for changes in comments of programming languages.

e.g. a repro: uncomment code.

  • difft
    difft

  • git diff --color-words=.
    git diff --color-words=.

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

No branches or pull requests

3 participants