[Toybox] [PATCH] grep: Make --color highlight all matches on a line.

enh enh at google.com
Tue Sep 21 19:56:30 PDT 2021


On Tue, Sep 21, 2021, 18:25 Rob Landley <rob at landley.net> wrote:

> On 9/21/21 1:54 PM, Peter Collingbourne via Toybox wrote:
> > This matches the behavior of GNU grep.
>
> Well, _sort_ of. The test you added won't pass TEST_HOST because:
>
> $ echo hello | grep --color=always l | hd
> 00000000  68 65 1b 5b 30 31 3b 33  31 6d 1b 5b 4b 6c 1b 5b
> |he.[01;31m.[Kl.[|
> 00000010  6d 1b 5b 4b 1b 5b 30 31  3b 33 31 6d 1b 5b 4b 6c
> |m.[K.[01;31m.[Kl|
> 00000020  1b 5b 6d 1b 5b 4b 6f 0a                           |.[m.[Ko.|
>
> Different escapes. (The behavior's probably good enough, but the test
> isn't.)
>
> Hmmm, I don't need to specify the zero to go back to grey, do I?


Iirc from writing a terminal emulator, for *all* escapes that take a
numeric argument, missing it out is equivalent to supplying 0. But, yeah,
\x1b[m for \x1b[0m is by far the most common case of that.

The \e[K is
> definitely funky though, that's delete until end of line...? (Why...?)
>
> And to be honest I'm tempted to remember the current color and optimize out
> unnecessary color change escapes. Hmmm...
>
> Thanks for the bug fix, good catch. Lemme poke at this a bit...
>
> Rob
> _______________________________________________
> Toybox mailing list
> Toybox at lists.landley.net
> http://lists.landley.net/listinfo.cgi/toybox-landley.net
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20210921/f65b9efd/attachment.htm>


More information about the Toybox mailing list