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

Added word-diff=plain colorizing support #966

Closed
wants to merge 3 commits into from

Conversation

dvalter
Copy link
Contributor

@dvalter dvalter commented Nov 11, 2019

Added ADD and DEL colors for {+added+} and [-removed-] blocks of git word-diff=plain

Since git does not escape delimiters in word-diff, this code may produce an incorrect color output on some code that actually contains these sequences including the first commit of this PR.

It's possible to bypass this by using git color escape sequences to determine additions and deletions, but it's likely to conflict with the rest of diff parser.

(Probably) fixes #221

Added ADD and DEL colors for {+added+} and [-removed-] blocks of git word-diff=plain

Since git does not escape the delimiters and splits them by line, this code would sometimes end up with an incorrect highlighting.

The solution scans DEFAULT lines of the diff chunk and and adds colored cells. Since git (unlike wdiff) does not use multi-line word-diff, it works.
Test is based on diff-context-test
@eMPee584
Copy link

.. hey @koutcher, can you please have a look at this? 🤠

@koutcher
Copy link
Collaborator

koutcher commented Apr 1, 2020

The proper way to do this would involve --word-diff=porcelain (see #47) but I understand it would require much more rework of the parser, so this is an interesting step already. There is a problem when hovering the cursor line over empty lines (j,k) as they remain highlighted.

@dvalter
Copy link
Contributor Author

dvalter commented Apr 1, 2020

@koutcher I definitely missed that during my previous testing. It should be fixed now.

@koutcher
Copy link
Collaborator

koutcher commented Apr 2, 2020

What is the purpose of LINE_WDIFF_PLAIN ?

@dvalter
Copy link
Contributor Author

dvalter commented Apr 2, 2020

I feel like since the line is parsed and colorized, it's not default anymore. Now it should not have an impact, but it may help in further development.
If that's not right, I'll remove LINE_WDIFF_PLAIN.

koutcher added a commit to koutcher/tig that referenced this pull request Apr 4, 2020
Add --word-diff=plain colorizing support.

Closes jonas#221
@koutcher
Copy link
Collaborator

koutcher commented Apr 4, 2020

The line type is normally attached to a color line in tigrc so it wouldn't bring anything here. There was a better way to solve the cursor line problem (just change the last parameter of diff_common_add_cell to true) so I merged 9b9e6f2 and did a few adjustments to ensure it will be transparent for people not using word diff. You can have a look to koutcher@41763ae before I push it to jonas/tig.

@dvalter
Copy link
Contributor Author

dvalter commented Apr 4, 2020

The line type is normally attached to a color line in tigrc so it wouldn't bring anything here

There's an alternative use case regarding key handling (i.e. DIFF_STAT), so I thought it may make sense if some action for diff add/del will be added.

You can have a look to koutcher/tig@41763ae before I push it to jonas/tig.

It's absolutely fine. I love that you've added a word-diff CLI argument switch, it was definitely needed there.

@koutcher
Copy link
Collaborator

koutcher commented Apr 5, 2020

Point taken for the line type, we can introduce it later if there is a need for a specific action. Thanks for this contribution!

@koutcher koutcher closed this Apr 5, 2020
@vivien
Copy link
Contributor

vivien commented Jun 9, 2020

When I use tig --word-diff=plain, the changes are shown like [-classic-]{+strict+}. Am I missing something?

@dvalter
Copy link
Contributor Author

dvalter commented Jun 11, 2020

When I use tig --word-diff=plain, the changes are shown like [-classic-]{+strict+}. Am I missing something?

It's an intended behavior, if they have DEL and ADD colors respectively. It should look basically like an output of git show --word-diff=plain.
Screenshot_2020-06-10_22-14-42
Screenshot_2020-06-10_22-15-35

Stripping them is not viable as it will break commits like 4028a49.

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

Successfully merging this pull request may close these issues.

--word-diff
4 participants