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

Show difference from previous line #22

Open
YAMLcase opened this issue Feb 11, 2022 · 7 comments
Open

Show difference from previous line #22

YAMLcase opened this issue Feb 11, 2022 · 7 comments

Comments

@YAMLcase
Copy link

YAMLcase commented Feb 11, 2022

I'm starting to become more than a basic hl user and the config I have in mind is to highlight what is different from the line above. The idea is to compare from delimiter to delimiter a line with the line above it, and when a diff is detected, that "cell" is colored as well as the rest of the line, even if later cells are the same as previous. Here's an example I mocked up in an RTF editor:

image

@mbornet-hl
Copy link
Owner

Hello,
interesting functionality ... Let me think about it.

@YAMLcase
Copy link
Author

Hello,
interesting functionality ... Let me think about it.

Great news! FYI: I asked over on r/commandline if there was a tool that did just this and I got a few code snippets in response but no dedicated tool.

In case you're curious:
https://www.reddit.com/r/commandline/comments/sq1y3o/diff_for_single_file_showing_changes_from

@mbornet-hl
Copy link
Owner

mbornet-hl commented Feb 14, 2022

Here is just a small modification of the AWK script found on reddit, that alternates colors :

#/bin/bash

awk 'BEGIN {
	FS = OFS = ",";
	if (getline == 1) {
		print;
	}
	split($0, previous);
	idx_color	= 0;
}
{
	current = $0;
	for (i=1; i<=NF; i++) {
		if ($i != previous[i]) {
			$i = sprintf("\033[3%dm%s", 1 + idx_color, $i);
			break;
		}
	}
	print $0 "\033[0m";
	split(current, previous);
	idx_color	= (idx_color + 1) % 4;
}' "$1"

image

I'm thinking about how to implement a more generic solution in hl. But sorry, I have other options to implement in hl before that one.

@mailsanchu
Copy link

Any plans to support this natively?

@mbornet-hl
Copy link
Owner

Hello,
I have some other functionalities to implement in "hl", in "RPN", and in other projects. I have many technical articles to write for Linux magazines, and a lot of other things to do, and I only work on these projects during my free time (week-ends and holidays). Things would go much faster if I were paid for these developments and if I could work on them at full time, but no one currently supports me financially, so as this functionality doesn't have a high priority in my tasks list and a solution exists with a script, I don't think I could implement it soon.

@YAMLcase
Copy link
Author

Thank you for the awesome tool and hard work. I use it everyday

@mbornet-hl
Copy link
Owner

Thank you for your comment !
I'm glad to see that this tool is useful. I'd like to do more, but sometimes I need to sleep ... ;-)

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