coccigrep
coccigrep copied to clipboard
colorizing is worse than non-colored
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
.
Just pushed a branch adding the -g
option like --grep
: https://github.com/regit/coccigrep/tree/grep
It gives the following result:
Can you give it a try ? (sudo python setup.py install
from the branch should do the trick)
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).
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
.
Just pushed that to master:
@do11 Could you test it ?
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.
Good catch.