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

colorizing is worse than non-colored #17

Open
do11 opened this issue Mar 21, 2018 · 6 comments
Open

colorizing is worse than non-colored #17

do11 opened this issue Mar 21, 2018 · 6 comments

Comments

@do11
Copy link

do11 commented Mar 21, 2018

Thanks for coccigrep! But, first time I see program which have colored output worse than non-colored. For example

linux/fs/ext4$ coccigrep  -t 'struct posix_acl' -a a_entries -c .
./acl.c: l.45 -0, l.45 +0, struct posix_acl *acl
                acl->a_entries[n].e_tag  = le16_to_cpu(entry->e_tag);
./acl.c: l.46 -0, l.46 +0, struct posix_acl *acl
                acl->a_entries[n].e_perm = le16_to_cpu(entry->e_perm);
...

Text struct is highlighted with bright green which distracts attention on every line from grep match to context column. Same search w/o colors is much easier to see:

./acl.c:45 (struct posix_acl *acl):             acl->a_entries[n].e_tag  = le16_to_cpu(entry->e_tag);
./acl.c:46 (struct posix_acl *acl):             acl->a_entries[n].e_perm = le16_to_cpu(entry->e_perm);
./acl.c:48 (struct posix_acl *acl):             switch (acl->a_entries[n].e_tag) {
./acl.c:61 (struct posix_acl *acl):                     acl->a_entries[n].e_uid =
./acl.c:69 (struct posix_acl *acl):                     acl->a_entries[n].e_gid =
./acl.c:105 (struct posix_acl *acl):            const struct posix_acl_entry *acl_e = &acl->a_entries[n];

But, it would benefit from colors. Can you make it by default to color just match text, like gnu grep do, and do not split lines into two? Also, why suddenly l.45 -0, l.45 +0 instead of just :45.

@regit
Copy link
Owner

regit commented Mar 21, 2018

Just pushed a branch adding the -g option like --grep: https://github.com/regit/coccigrep/tree/grep

It gives the following result:

screenshot from 2018-03-21 17-36-20

Can you give it a try ? (sudo python setup.py install from the branch should do the trick)

@do11
Copy link
Author

do11 commented Mar 21, 2018

Thanks! This is much better. I think additional option is not needed, just show output in this mode if context is 0 lines. Also, pls, highlight -a argument (which is a_entries in our example) in red, while remain highlighting acl in green (this is useful).

@do11
Copy link
Author

do11 commented Mar 21, 2018

Additional thought: if you choose rule to highlight both -t and -a (better in different colors but not necessarily), in that case text (struct posix_acl *acl) is not needed, as we always would see acl (as different from -a string) and understand it's type match. Thus a lot of screen output could be saved from clobbering with similar text. This would warrant -g option if you don't want to change default formatting.

ps. (Not too important feature requests.) If you want to make it more similar to gnu grep - line numbers not needed by default, in grep they are enabled with -n option. And in addition to -C n grep allows shortcut -n.

@regit
Copy link
Owner

regit commented Mar 21, 2018

Just pushed that to master:

screenshot from 2018-03-21 22-24-52

@do11 Could you test it ?

@do11
Copy link
Author

do11 commented Mar 21, 2018

It works nice. Thanks much!

ps. Ah. Except, in just -t mode, when symbol is already highlighted its second entry on the line is not highlighted.
coccigrep-22-03-2018 0-42-59

@regit
Copy link
Owner

regit commented Mar 21, 2018

Good catch.

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

2 participants