-
-
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
ripgrep output is invisible in PowerShell #342
Comments
These are the default styles used by ripgrep in all circumstances: Lines 706 to 711 in f5a2d02
let mut specs = vec![
"path:fg:magenta".parse().unwrap(),
"line:fg:green".parse().unwrap(),
"match:fg:red".parse().unwrap(),
"match:style:bold".parse().unwrap(),
]; In other words, ripgrep isn't changing anything on you. I can't really explain what you're observing though. Maybe the blend of colors makes it invisible? Maybe Powershell has a more limited color palette and can't display magenta? I don't know. You might consider trying to experiment with the color settings, which are configurable on the command line:
I would rather have a single set of defaults with no smarts. If those don't work for whatever reason, then I'd like to encourage users to set their own colors with the |
I'm not sure why the colour changes between the consoles, but this is the solution I'm using to work around it thanks to your suggestion. For anyone else who runs into this issue, this should fix it: Add-Content $PROFILE -Encoding UTF8 "`r`nfunction rg { rg.exe --colors 'path:bg:white' `$args }`r`n" |
@nzbart Oh cool! Could you explain your |
That command line adds the following to the current user's PowerShell profile, whose path is stored in the variable function rg { rg.exe --colors 'path:bg:white' $args } Unfortunately, it may not be 100% reliable in all cases depending on how people have configured their profile, so I'd be a bit reluctant to promote it to the official docs. Something that might be worth adding to the docs is that the simplest way to install ripgrep on Windows may be the Chocolatey package that @dstcruz has kindly created: Chocolatey is an increasingly popular way of installing software from the command-line. For example to install ripgrep: choco install ripgrep |
@nzbart Awesome, thanks for the info! I'll try to improve the docs soon with your helpful feedback. :-) |
@nzbart Note that when you use such alias (through function) rg will not work through pipe P.s. the problem is that when you try to pipe output to such function. It will not pipe output to |
@DoumanAsh is there anyway to work around that and write a functional alias on Windows? |
It took a bit of re-search but so far i found simple solution: function grep {
$input | rg.exe --hidden $args
} $input goes obviously for piping, and it works just fine even if you would have no pipe. Reference to powershell builtin variables https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.core/about/about_automatic_variables |
@DoumanAsh nice improvement, thanks! |
@DoumanAsh I've found that the function above doesn't seem to work unless piping into it (Windows 10): > gcm rg | select -expand definition
$input | rg.exe --colors 'path:bg:white' $args
> set-content -Path test.txt -Value "Something" -Encoding UTF8
> rg thing
> rg.exe thing
test.txt
1:Something
> ls | cat | rg thing
1:Something Does the test scenario above work for you (run steps in a clean directory)? |
It works for me:
Maybe it depends on version of powershell? You can do it by starting powershell with option I tested on version from 3 to 5 and it works. Cannot go below because my profile wouldn't load :D |
@DoumanAsh That is strange. Could you please confirm that This is my PowerShell version: > $PSVersionTable.PSVersion.ToString()
5.1.14393.693 |
Opps... you're right, i forgot that i aliased it to |
Ok, i suspect |
Ok, i found work-arond: function grep {
$count = @($input).Count
$input.Reset()
if ($count) {
$input | rg.exe --hidden $args
}
else {
rg.exe --hidden $args
}
} Basically i convert $input to Array and count number of elements. |
Unfortunately, it's just much simpler to go back to the Silver Searcher than it is to have to work around this issue on every Windows machine I work on. Below is a comparison of these two tools when run in in the default PowerShell window on a clean Windows 10 install: As stated in my original post, it does work when starting the default cmd.exe console rather than PowerShell: Hopefully, the out-of-the-box experience will be improved in a future version for Windows PowerShell users. As an additional curiosity, I'm unsure why the UTF8 BOM is rendered differently by ripgrep between the two consoles. |
@nzbart I don't understand how ripgrep can work on all possible terminal color schemes out of the box. I think what you're saying is, "ag happens to pick a default color that works in my color scheme"? |
I think the underlying issue here is not that the ripgrep color scheme doesn't match the Powershell scheme, but that the colorization isn't always working properly on Powershell.
The same thing happens with Note that this seems to only happen with the powershell.exe executable itself. If I open cmd.exe and invoke powershell within that window, everything works fine. These were all tested with Powershell 5.0.10586.117 (note: not the most recent version) on Windows 7 with the default Powershell color scheme.
|
@elirnm If you toggle between |
Interesting. So I can't really tell if there's an actual bug in the communication with the Windows console. It seems like not? Maybe ripgrep should pick a default color scheme on Windows that fits the default color scheme of PowerShell and call it a day? |
I don't know much about console coloring, but PowerShell/PowerShell#2381 might be relevant. Also https://stackoverflow.com/questions/20541456/list-of-all-colors-available-for-powershell |
I'm using black color sceheme in powershell and it looks fine to me. |
@DoumanAsh By "looks fine" do you mean it's readable or do you mean the colors are actually correct? If you execute It should obviously be perfectly readable on any shell where the background color doesn't conflict with ripgrep's colors. |
Here is example of my look: https://i.imgur.com/gXU5l00.png
|
What version of Powershell do you have? |
I'm using latest PS |
I just updated to Powershell version 5.1.14409.1005 and it still doesn't work correctly for me. Both magenta and yellow print the wrong colors. Maybe something with different Windows versions? I don't know. |
@elirnm I think you might have hit upon the problem in your comment above (#342 (comment)) - well diagnosed! @BurntSushi you asked above (#342 (comment)) whether this was a big problem. I prefer ripgrep over Silver Searcher, but they are both great tools, and one of them works out of the box on multiple machines without having to come up with unsatisfactory workarounds. Each of the PowerShell workarounds we tried above have some kind of deficiency that makes it annoying to use, along with the fact that I work on multiple machines that need the workaround applied instead of just running I still use ripgrep in Vim via Grepper because console colour isn't a problem in this case, and because ripgrep has some very useful features such as understanding .gitignore files and having the |
This is because the default shortcuts for Windows Powershell use a customization of the standard console color palette, redefining "DarkMagenta" to be RGB(1,36,86) and "DarkYellow" to be RGB(238,237,240), then setting the background color as "DarkMagenta." This was done in order to give powershell a custom, distinctive blue color, see https://www.leeholmes.com/blog/2008/06/01/powershells-noble-blue/. They overwrote dark magenta because it was judged to be rarely used (speculation). Dark yellow was updated because it didn't have enough contrast against the new blue background. You can see the 2 altered colors when you compare options from Powershell and Cmd: The overriding of the RGB values is done via the registry: Upshot is that any tools that write with DarkMagenta foreground are gonna be invisible in standard powershell consoles. IMO this was a total hack from Microsoft, but at this point it's spilled milk. I think one possible workaround is to check if rg is 1. running on windows and 2. current console background color is dark magenta. That's a very strong indication that you are within a powershell console, and regardless file names will be invisible (either magenta/magenta or "noble blue"/"noble blue"). In this case output file names with intense magenta (which will still look good). |
I am open to any easily maintainable hack that fixes this. Even something like, "change the default colors on Windows regardless of shell" would be OK with me I think. |
@latkin Sure! I can help you get it into a non-hacky state. :-) |
When I launch cmd.exe and run PowerShell from within that console window, the output is perfectly legible:
However, if I launch PowerShell and run rg within the default window, it appears that ripgrep renders the file name in blue rather than magenta, making it invisible:
When I tried setting my colour scheme using the PowerShell console configuration window (Alt-Space, P from within the console) so that it matched the cmd.exe settings, I noticed that ripgrep was outputting blue text.
Why would ripgrep change the output colour of the file name in some cases, particularly when the background colour is blue, and is it possible to make this algorithm a bit smarter?
The text was updated successfully, but these errors were encountered: