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

feat: add support for rg #1

Merged
merged 1 commit into from
Sep 26, 2023
Merged

Conversation

wjdwndud0114
Copy link

@wjdwndud0114 wjdwndud0114 commented Sep 15, 2023

For live grep, I use rg like: rg --column --line-number --no-heading --color=always --smart-case -- <query> which has color.

Added logic to grab the path for the icon while filtering out the ASCII color codes and keeping everything performant.

image image image

@MaartenStaa
Copy link
Owner

Very nice, thanks for the PR! I'm on vacation right now, and will review in detail when I'm back. One thing I noticed that you could improve is that right now, extract_filepath always allocates, even if there are no escape codes. You could change it to return a Cow<str>. Then, when there are no escape codes in the string, you can just return a Cow::Borrowed.

@wjdwndud0114
Copy link
Author

wjdwndud0114 commented Sep 15, 2023

Thank you for the suggestion! This is my first time using Rust and used a lot of chatGPT so there are probably a lot of holes.

Looked into Cow concept, but I think since we are doing a to_lowercase or essentially to_ascii_lowercase for each char, it always allocates? Or would a check for ascii char help before doing the to_ascii_lowercase to keep track of if there was an lowercase mutation?

I could also just add a specific case for my rg usage which is check if the input starts with the color code and extract until the next color code, but that's probably be too specific.

@MaartenStaa
Copy link
Owner

Right, that's a good point about to_lowercase and always allocating. I'm going to merge this as-is and iterate a bit to see if I can incorporate the Cow. I also want to add some tests and possibly benchmarks, I'll ping you when I add my changes 🙂

@MaartenStaa MaartenStaa merged commit bb1ceaa into MaartenStaa:main Sep 26, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants