paoloantinori/hhighlighter

wrong behaviour with single digit keywords

Opened this issue · 4 comments

$ echo 123 | h 1 2 3
31m132m23

tmux version 1.9.6
zsh version zsh 5.0.7 (x86_64-pc-linux-gnu)

Thanks for reporting this. I will dig into this.

The underlying ack support seems to behaves correctly but h does not.

echo abc | ack --flush --passthru --color --color-match=red a | ack --flush --passthru --color --color-match=yellow b

Interesting. The bug is not with tmux per se but with h and numbers.

This works fine

echo abc | h a b c

This doesn't:

echo 123 | h 1 2 3

The reason for this is that, since h is just a wrapper to build a series of pipes on precedent keyword output, the subsequent interactions will see coming in input also the markup characters, that happen to contain numbers, generating false positives and interleaving the markup.

I think this is more a technical limit of h when asked to highlight single character keywords, in particular numbers.

You can see it with plain ack as well.

echo 123 | ack --noenv --flush --passthru --color --color-match="bold black on_rgb520" '1' |ack --noenv --flush --passthru --color --color-match="bold red on_rgb025" '2' |ack --noenv --flush --passthru --color --color-match="underline bold rgb520" 3

The ANSI color codes are being rewritten by the subsequent calls to ack. Here's a single call. Notice the additional numbers that are added for the ANSI escape sequences.

$ echo 123 | ack --noenv --flush --passthru --color --color-match="bold black on_rgb520" '1' | xxd
0000000: 1b5b 313b 3330 3b34 383b 353b 3230 386d  .[1;30;48;5;208m
0000010: 311b 5b30 6d32 331b 5b30 6d1b 5b4b 0a    1.[0m23.[0m.[K.

This would probably need to be fixed in ack by adding support for multiple search patterns and color-match values in a single execution.

Due to issues like this one, problems with overlapping matches, and - given the constraints of bash scripts - a lack of prospect of these issues being fixed at all in hhighlighter, I decided to create my own multi-color grep tool, and I am making it available to everyone who's interested: https://github.com/EugenDueck/colorexp