-
-
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
--color does not work under Emacs #182
Comments
Tracking down why colors aren't working has historically been a very challenging task because a lot of it is dependent on your environment. For example:
Colors no longer work. The
If I try this with GNU grep, colors still work, even if my
So this could be one possible explanation. There may be other problems. For example, if
In the debug output, I see:
Once again, GNU grep still works. It seems GNU grep will fall back to some default settings that So, can you run Thanks! |
|
Having Indeed, if I set So... It sounds like you need to change your |
Actually colors are working fine not only for GNU/grep, but also |
At least GNU grep hard codes ANSI color escape sequences and AFAIK doesn't actually respect the
What is the correct behavior here? If |
@ticki You seem to know a thing or two about this sort of thing. Can you make sense of this? I notice in your |
Andrew Gallant [email protected] writes:
Ok, just found that if I set TERM to eterm-color colors with ripgrep are BTW ripgrep is using a basic red color, how do we configure which color Thierry |
"it works for me" isn't really a strong reason to assume "it always works," unfortunately.
Colors aren't yet configurable. See: #51 |
From reading the source of |
@thierryvolpiatto @xuchunyang I think the bottom line here is that while |
Andrew Gallant [email protected] writes:
There is no hurry, thanks for all your explanations and sorry to not be
Ok, we will use Thanks again for your help on this. Thierry |
@BurntSushi So TERMINFO is mostly for detecting compatibility, but is only really relevant for very old terminals. Termion implements escapes which are supported by virtually every VTE used today (most of it is straight out of the ANSI standards, some are ones introduced by xterm). For the Windows stuff: I'm not that familiar with the Windows API, but I'm more than willing to accept a PR adding Windows support to Termion (i.e. adding the winapi calls to the formatter, I guess). |
@ticki Got ya. Given that every other tool in this space seems to not care about I would definitely recommend treading carefully with Windows. For Windows, you need to make synchronous API calls to the console you're writing to, which means that you can't really implement Windows support in some arbitrary formatter that can write to anything. For What I'm saying is: as a future user of |
@BurntSushi I agree with that. It would definitely be incredibly hacky to add windows support. |
I'm wondering if resolving this issue would also solve that other issue where ripgrep is inserting strange escape characters to the colored text. |
@kaushalmodi I bet it will, considering the new approach should be isomorphic to what GNU grep does today, which doesn't suffer from the same issue (I think). |
This commit completely guts all of the color handling code and replaces most of it with two new crates: wincolor and termcolor. wincolor provides a simple API to coloring using the Windows console and termcolor provides a platform independent coloring API tuned for multithreaded command line programs. This required a lot more flexibility than what the `term` crate provided, so it was dropped. We instead switch to writing ANSI escape sequences directly and ignore the TERMINFO database. In addition to fixing several bugs, this commit also permits end users to customize colors to a certain extent. For example, this command will set the match color to magenta and the line number background to yellow: rg --colors 'match:fg:magenta' --colors 'line:bg:yellow' foo For tty handling, we've adopted a hack from `git` to do tty detection in MSYS/mintty terminals. As a result, ripgrep should get both color detection and piping correct on Windows regardless of which terminal you use. Finally, switch to line buffering. Performance doesn't seem to be impacted and it's an otherwise more user friendly option. Fixes #37, Fixes #51, Fixes #94, Fixes #117, Fixes #182, Fixes #231
Still not working in emacs with helm and from any emacs terminal (term or shell-mode, eshell) with rg version 0.3.2. However it is working fine with 0.2.3 and the workaround we found:
Here the command line used with 0.3.2 (not highlighting):
Same result with the workaround:
Now with rg version 0.2.3 and this command line (now matches are highlighted as expected):
|
@thierryvolpiatto Thanks for taking the time to try and confirm the fix! Sorry it isn't working right for you. It's hard for me to understand your comment, but you're saying you can't get ripgrep I honestly have no clue what's going on. If you have |
Thanks for looking at this.
Andrew Gallant <[email protected]> writes:
@thierryvolpiatto Thanks for taking the time to try and confirm the
fix! Sorry it isn't working right for you. It's hard for me to
understand your comment, but you're saying you can't get ripgrep 0.3.2
to output colors at all in emacs, regardless of any workaround?
Yes that's it, and 0.2.3 is working fine, I didn't try any version
between 0.2.3 and 0.3.2 though.
Can you try --color ansi instead of --color always?
Still not working
Also, what operation system are you on?
GNU/Linux
Alternatively, --color auto with TERM=eterm-color should also work.
Same not working.
Let me know if I can do something to help debugging.
Thanks.
…--
Thierry
|
@thierryvolpiatto Can you try to reproduce the issue outside of emacs? Basically, what you're reporting doesn't make any sense to me. :-) |
Andrew Gallant <[email protected]> writes:
@thierryvolpiatto Can you try to reproduce the issue outside of emacs?
No, outside of emacs rg works perfectly.
Basically, what you're reporting doesn't make any sense to me. :-)
Sorry if my explanations are confuse, let me know what you are not
understanding.
Thanks.
…--
Thierry
|
@thierryvolpiatto Sorry, I think I understand what you're saying. What I meant was, I don't understand how what you're reporting is actually possible. If you say I think the only thing I can do at this point is try to reproducing it, but I've never used emacs before. (I'm a vim user.) How hard would it be to explain how to reproduce your issue to someone who has never used emacs before? |
Andrew Gallant <[email protected]> writes:
@thierryvolpiatto Sorry, I think I understand what you're saying. What
I meant was, I don't understand how what you're reporting is actually
possible. If you say --color ansi, then ANSI escape sequences should
be emitted no questions asked.
I think the only thing I can do at this point is try to reproducing
it, but I've never used emacs before. (I'm a vim user.) How hard would
it be to explain how to reproduce your issue to someone who has never
used emacs before?
It is easy, no need to install helm, you can use rg in an emacs terminal
as you would use it usually.
1) Install emacs preferably a recent version like emacs-24.5 or emacs-25.1.
Let me know if you have difficulties to install.
2) run from a terminal:
emacs -Q
3) Once emacs started hit M-x ansi-term RET RET (where M is Meta and RET is Return).
4) You have now a prompt, just use rg as usual.
5) To quit emacs hit C-x C-c (Ctrl-c Ctrl-c)
Hope that help.
Thanks.
…--
Thierry
|
Interesting! That did the trick. Something is definitely a little weird, however, I am seeing that the match text is at least bolded, but it's not colored. |
Errrmm, but I am using latest master which has some fixes related to that, so that might not be the case for Anyway, I can reproduce the fundamental problem, so hopefully I can fix this. Thank you. :-) |
Ah! I figured it out. It looks like the emacs terminal has very limited support for ANSI escape sequences, and doesn't actually work with constructs like |
In Emacs, its terminal apparently doesn't support "extended" sets of foreground/background colors. Unless we need to set an "intense" color, we should instead use one of the eight basic color codes. Also, remove the "intense" setting from the default set of colors. It doesn't do much anyway and enables the default color settings to work in Emacs out of the box. Fixes #182 (again)
All right, this should finally be fixed in master. I hope to get a release out soon. |
Andrew Gallant <[email protected]> writes:
All right, this should finally be fixed in master. I hope to get a release out soon.
I installed rust and builded rg from master, and I can confirm rg is now
outputing colors as expected :-).
Many thanks for your quick fix and for rg!
…--
Thierry
|
I'm using rg 0.2.1 and Emacs 25. It looks like
--color
doesn't have effect under Emacs, while other tools such as grep works.M-! echo hello | grep --color=always hello
gives[01;31m�[Khello�[m�[K
M-! echo hello | rg --color=always hello
giveshello
(where is the escape code?)see also emacs-helm/helm#1624 (comment)
The text was updated successfully, but these errors were encountered: