Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

option for ignoring terminal escape sequences (eg color codes)? #519

Closed
timotheecour opened this issue Jun 17, 2017 · 1 comment
Closed
Labels
enhancement An enhancement to the functionality of the software. question An issue that is lacking clarity on one or more points.

Comments

@timotheecour
Copy link

Feature request: option for ignoring terminal escape sequences (eg color codes); useful for cases where logs contain color codes (http://misc.flogisoft.com/bash/tip_colors_and_formatting) which makes it hard to search for text, eg:

BEFORE\e[1mCOLOR\e[21mAFTER

desired behavior:

rg 'FORECOLO' #return nothing because of \e[1m
rg -ignore_color_codes 'FORECOLO' #return match

each line would be piped through a filter to remove such codes before attempting to match anything

More generally, we could have an option to filter lines by a regex replace expression before matching:

rg -replace_by_regex='\e[[\d;]+m' 'FORECOLO' #return match

@BurntSushi
Copy link
Owner

TL;DR - No can do, sorry.

First and foremost, it seems like it would be better to just strip the ANSI escape sequences using some other tool before searching. Baking this into ripgrep seems simultaneously niche and a conflation of concerns.

Secondly, ripgrep does not search line by line, so the simple implementation you're imagining probably doesn't work. At the very least, it trivially doesn't work when searching using memory maps. When using the buffered approach, the entire buffer could be transformed to drop ANSI escapes. But there's some subtle complexity there like "what if the buffer ends in the middle of an ANSI escape."

Thirdly, removing the ANSI escapes would throw off some offsets---such as column numbers---as reported by ripgrep.

In sum, I can appreciate why you might want this, but I think it's better solved by preprocessing the file with some other tool. At the end of the day, this feature carries too much implementation complexity for it to be worth it.

@BurntSushi BurntSushi added enhancement An enhancement to the functionality of the software. question An issue that is lacking clarity on one or more points. labels Jun 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An enhancement to the functionality of the software. question An issue that is lacking clarity on one or more points.
Projects
None yet
Development

No branches or pull requests

2 participants