-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Add extended color support #452
Conversation
@@ -954,6 +954,58 @@ impl<W: io::Write> Ansi<W> { | |||
} | |||
} | |||
} | |||
macro_rules! write_var_ansi_code { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some eyes on this would be good if its preferred over format!
. I've added some test cases here but could have missed something.
Adds 256-color and 24-bit truecolor support to ripgrep. This only provides output support on ansi terminals. Windows will fallback to white for any argument given.
@scottchiefbaker just highlighted a problem with the color parsing (no surprises there). I've just squashed the fix into this commit and made a quick test script which can be used to check if the parsing code matches visually. https://gist.github.com/tiehuis/15f6a85c1b8fe691008c10b4d325a7c3 |
I can confirm that I've tested this branch and it does everything I want for this feature. Colors are accurate and simple to specify. This pull-request gets my 👍 for merge. Good work @tiehuis |
@tiehuis I don't know enough (any) rust to speak the quality of this code, but I think the implementation and output are great. What are your thoughts on this PR? |
I've added my notes about this in the initial post. It's up to BurntSushi whether it gets merged or not and if any changes need to be made. I know he has a lot of other things to tend to as well so I usually don't want to be too overbearing. He does a great job at managing his various projects so just give him a bit of time and this'll get looked at eventually. |
@BurntSushi any thoughts on this PR? It's working pretty well for me. |
I just wanted to add that the Windows 10 console has supported 256 ansi colours for a while and since Creators Update supports 24 bit RGB. Other commonly used terminal emulators such as mintty and ConEmu also support 24 bit colours. Since ripgrep already has a flag for ansi colours, please don't just disable by default on Windows. Windows users can opt in/out depending on what they are using. As an aside, ripgrep is roughly twice as fast on windows with |
@leafgarland Can you please elaborate? What does your comment have to do specifically with this PR? |
@tiehuis Sorry I've been dragging my feet looking at this! Thanks so much for doing it! At first glance, this looks pretty good but I'll want to do a more thorough review before merging. |
@BurntSushi I was commenting because the description mentioned that this PR was defaulting to white on Windows. |
Can't have a long conversation right now but just had a quick look and I think this should handle ansi codes correctly on windows if The only thing that should be updated potentially is the Haven't tested at all on Windows however, so wanted a minimal change incorporating the functionality first. It should be simple to add support for Windows later if needed with no real trouble. Would be great if you could try out the branch to confirm though! |
@leafgarland That's only when printing using the console APIs. It looks like this PR doesn't do anything special with the ANSI codes when those are used on Windows (which seems correct to me). |
Ok, thanks. Sorry, I should have looked at the code! |
Yeah, this is potentially future work. Def out of scope for this PR. :-) AFAIK, you actually need to make an API call to enable ANSI support in Windows 10 terminals, so it requires some Windows knowledge. |
What is the current state of this pull request? What needs to be done to get it merged? |
@weiznich It's waiting on me giving it a more careful review. I'll try to look soon. |
@weiznich I looked at your PR for Rust, and I'm a little confused. What feature does that implement that's related to this? Or would it be a new feature for ripgrep you're waiting to implement? |
@alexcrichton moved the coloring in cargo to termcolor with this commit. After that it is only possible to use the 8 predefined color codes. This may result in a colors that are barley readable(See my old PR for an example). |
@BurntSushi have you had a chance to review this at all? I'd really like to see this landed. |
@BurntSushi any movement on this? I'd really like to see better colors in ripgrep. |
Fixes #261.
format!
macro. Its more complicated and I'm not entirely sure the benefit but it can always be changed back if the extra allocations are favored over the more complex code.