Here is a patch which colorizes pattern matches in qgrep's output (when not using -C or $NOCOLOR, and not in --invert-match mode). The code it adds is almost all in the qgrep_print_line() function which i had introduced in the previous -A/-B patch. Other minor impacts on the code are: - the FUN type which was local to grep_main() is now global, since qgrep_print_line() uses it too now. Thus i've renamed it QGREP_STR_FUN. - the regexp compilation flags (reflags) no more default to REG_NOSUB. As for performances, a few benchs show that: - the search itself is not slower than before (seems that REG_NOSUB was not really making any difference, and nothing else has changed), - at the contrary, the display of matching lines is significantly slower than before when in color mode. But i don't think it's an issue in real world use cases. Actually, the only problem i see with this patch is that it changes a default behavior of qgrep. There may be some scripts around which rely on it not putting colors in its output... Sure, i could make this new feature optional, but: - it's the default in all portage-utils applets to print colors when not using the "-C" option or the NOCOLOR env var, - we are a bit short in meaningful short options ("-c" in particular is already used for "--count"). I think this issue falls under one of the portage-utils' TODO items: "- disable color when tty = NULL; may break less?" I tend to agree this would be a good thing. Maybe something like this: - by default, use colors if (tty != NULL), - with "-C", disable colors, - with "--some-new-option", force enable colors (useful to pipe $PAGER). But again, the problem is to find a free short option letter... Or maybe it could be "-C" too, when used twice?
Created attachment 115148 [details, diff] qgrep-colorize_matches_in_output.patch This patch is for CVS rev 1.20.
Oops, this patch live-locks with zero-length matches... I will attach a fixed version ASAP.
Created attachment 115163 [details, diff] qgrep-colorize_matches_in_output.patch This one should be safer...
/var/cvsroot/gentoo-projects/portage-utils/qgrep.c,v <-- qgrep.c new revision: 1.21; previous revision: 1.20 Merged this patch of yours and qgrep-context-names.diff from bug ??? in one commit.
Can the syntax highlighter here replace the one used in quse? Can the two be merged into a global one? Example: quse -e nls
(In reply to comment #4) > /var/cvsroot/gentoo-projects/portage-utils/qgrep.c,v <-- qgrep.c > new revision: 1.21; previous revision: 1.20 > > Merged this patch of yours and qgrep-context-names.diff from bug ??? in one > commit. > Looks like you've merge the patch from #172338 (qgrepping through installed ebuilds (in the VDB)) instead of this one
(In reply to comment #6) > Looks like you've merge the patch from #172338 (qgrepping through installed > ebuilds (in the VDB)) instead of this one As stated I merged two things in with the same commit.
This is released in 0.1.25 Bug #168334 ; q -r dies with a segfault after emerge --sync Bug #168442 ; does not properly parse the profile location Bug #170795 ; add a -E/--eclass option to qgrep Bug #170797 ; add a -s/--skip-comments option to qgrep Bug #171024 ; opening '/usr/portage/.metadata.x' failed Bug #171374 ; Misc enhancements for qgrep Bug #172240 ; -A/-B options for qgrep (context lines) Bug #172338 ; qgrepping through installed ebuilds (in the VDB) Bug #173005 ; Colorized output for qgrep.
Closing