What color options exist for ack(-grep) for colorization of output, logs, etc?
Asked Answered
E

2

15

Where can one find a listing of all color combinations or such available to use with ack(-grep)? I find that passing logs through ack-grep can be quite helpful at detecting errors, warnings or various other conditions especially with colorization, however I haven't found an authoritative list of what combos may be used, etc.

tail -f development.log \
| ack-grep --flush --passthru --color --color-match=yellow "^.*warning.*"

I've seen options such as the standard colors: red, blue, yellow, green, etc.

And I've seen that you can use "white on_green"

But what else?

Enrica answered 8/3, 2012 at 21:35 Comment(0)
V
25

ack uses Perl's Term::ANSIColor module, so you can check what is available to you with:

perldoc Term::ANSIColor

Here's the relevant excerpt.

   The recognized normal foreground color attributes (colors 0 to 7) are:

     black  red  green  yellow  blue  magenta  cyan  white

   The corresponding bright foreground color attributes (colors 8 to 15)
   are:

     bright_black  bright_red      bright_green  bright_yellow
     bright_blue   bright_magenta  bright_cyan   bright_white

   The recognized normal background color attributes (colors 0 to 7) are:

     on_black  on_red      on_green  on_yellow
     on_blue   on_magenta  on_cyan   on_white

   The recognized bright background color attributes (colors 8 to 15) are:

     on_bright_black  on_bright_red      on_bright_green  on_bright_yellow
     on_bright_blue   on_bright_magenta  on_bright_cyan   on_bright_white

   For any of the above listed attributes, case is not significant.

I'm glad to see you using --passthru, too.

We'd welcome you on the ack-users mailing list

Vineland answered 8/3, 2012 at 23:3 Comment(3)
I added a ticket for ack 2.0 to explain it: github.com/petdance/ack2/issues/26Vineland
On a linux (Ubuntu 11.10) server I'm seeing that the bright_ are evoking an error: Invalid attribute name bright_black at /usr/share/perl5/App/Ack.pm line 1155 - Should this be brought over to the mailing list at this point?Enrica
It's really a Term::ANSIColor issue, but sure, bring it to ack-users.Vineland
G
10

Another interesting thing to do is to create a ~/.ackrc with default configuration like:

--color
--color-match=on_white
--color-filename=red
--color-lineno=magenta

To get readable results on white console background for instance. (Actually the reason why I started to search and found this question and the helpful reply from @andy-lester).

Georgiana answered 17/2, 2016 at 13:54 Comment(1)
I had the same problem. Thanks!| What if when using ag?? is there a solution for thatHominoid

© 2022 - 2024 — McMap. All rights reserved.