Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 173005 - app-portage/portage-utils - Colorized output for qgrep
Summary: app-portage/portage-utils - Colorized output for qgrep
Status: RESOLVED FIXED
Alias: None
Product: Portage Development
Classification: Unclassified
Component: Third-Party Tools (show other bugs)
Hardware: All Linux
: High enhancement (vote)
Assignee: Portage Utils Team
URL:
Whiteboard:
Keywords: InVCS
Depends on:
Blocks:
 
Reported: 2007-04-01 13:07 UTC by TGL
Modified: 2007-04-05 18:43 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
qgrep-colorize_matches_in_output.patch (qgrep-colorize_matches_in_output.patch,6.25 KB, patch)
2007-04-01 13:09 UTC, TGL
Details | Diff
qgrep-colorize_matches_in_output.patch (qgrep-colorize_matches_in_output.patch,6.38 KB, patch)
2007-04-01 15:20 UTC, TGL
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description TGL 2007-04-01 13:07:42 UTC
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?
Comment 1 TGL 2007-04-01 13:09:03 UTC
Created attachment 115148 [details, diff]
qgrep-colorize_matches_in_output.patch

This patch is for CVS rev 1.20.
Comment 2 TGL 2007-04-01 15:06:53 UTC
Oops, this patch live-locks with zero-length matches... I will attach a fixed version ASAP.
Comment 3 TGL 2007-04-01 15:20:41 UTC
Created attachment 115163 [details, diff]
qgrep-colorize_matches_in_output.patch

This one should be safer...
Comment 4 solar (RETIRED) gentoo-dev 2007-04-02 17:06:31 UTC
/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.
Comment 5 solar (RETIRED) gentoo-dev 2007-04-02 17:08:46 UTC
Can the syntax highlighter here replace the one used in quse? 
Can the two be merged into a global one?
Example: quse -e nls
Comment 6 samLT 2007-04-03 17:32:53 UTC
(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
Comment 7 solar (RETIRED) gentoo-dev 2007-04-03 18:10:32 UTC
(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.
Comment 8 solar (RETIRED) gentoo-dev 2007-04-05 18:42:21 UTC
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.
Comment 9 solar (RETIRED) gentoo-dev 2007-04-05 18:43:07 UTC
Closing