coccigrep icon indicating copy to clipboard operation
coccigrep copied to clipboard

colorizing is worse than non-colored

Open do11 opened this issue 6 years ago • 6 comments

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.

do11 avatar Mar 21 '18 15:03 do11

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)

regit avatar Mar 21 '18 16:03 regit

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 avatar Mar 21 '18 16:03 do11

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.

do11 avatar Mar 21 '18 17:03 do11

Just pushed that to master:

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

@do11 Could you test it ?

regit avatar Mar 21 '18 21:03 regit

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

do11 avatar Mar 21 '18 22:03 do11

Good catch.

regit avatar Mar 21 '18 22:03 regit