How to forward ANSI escape codes thru ripgrep? #1920
-
Is there any way to forward colors through ripgrep? At least ANSI escape codes. As for example: I want print content of file with syntax highlighting via bat, then filter out some lines by ripgrep and print them with colors of bat (and maybe ripgrep as overlay too). |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The question here is not quite framed right. The issue here isn't whether ripgrep is "forwarding" colors or not. ripgrep prints the bytes it gets exactly as-is. If colors are emitted via ANSI escape sequences, then of course those are sent through as well. Indeed, your example isn't even showing a failure of forwarding colors. What it's showing is that your query for There's really not much ripgrep can do about this. You either have to ensure that your queries don't overlap with syntax highlighting boundaries, or otherwise ensure that your regex is robust with respect to ANSI escape codes. e.g., Maybe something like I think what you actually want is a way to search data that contains ANSI escape codes as if those ANSI escape codes weren't there, but that when it comes time to print the results, those ANSI escape codes should be re-inserted in their original location. This doesn't really fit within ripgrep's project goals, and moreover, implementing such a thing would be quite tricky in practice. |
Beta Was this translation helpful? Give feedback.
The question here is not quite framed right. The issue here isn't whether ripgrep is "forwarding" colors or not. ripgrep prints the bytes it gets exactly as-is. If colors are emitted via ANSI escape sequences, then of course those are sent through as well. Indeed, your example isn't even showing a failure of forwarding colors. What it's showing is that your query for
main(
doesn't produce any results. Why? Well, I'm guessing it's becausebat
is emitting ANSI escape codes betweenmain
and(
, and thus,main(
does not match anything.There's really not much ripgrep can do about this. You either have to ensure that your queries don't overlap with syntax highlighting boundaries, or otherwise e…