在 Windows 7 上的 Git Bash 中,运行 Cucumber 或 rspec 时颜色显示为代码
在 Windows 7 上的 Git Bash 中,我偶尔会发生一些情况,导致运行 Cucumber 场景或 rspec 规范时颜色编码失败。
有时,它是随机固定的(其中随机==我不知道我做了什么导致它被固定)。
因此,当我运行:
$ bundle exec cucumber features
或者
$ bundle exec rspec spec
而不是看到颜色时:
......
3 scenarios (3 passed)
6 steps (6 passed)
我看到类似的内容:
[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m
3 scenarios ([32m3 passed[0m)
6 steps ([32m6 passed[0m)
我知道这些是颜色的代码表示,但我不知道为什么它停止显示颜色,也不知道如何修复它。我缺少什么?
git config --list 的输出:
core.symlinks=false
core.autocrlf=true
color.diff=auto
pack.packsizelimit=2g
help.format=html
http.sslcainfo=/bin/curl-ca-bundle.crt
sendemail.smtpserver=/bin/msmtp.exe
user.name=John Uhri
user.email= *****
color.branch=auto
color.diff=auto
color.interactive=auto
color.status=auto
core.repositoryformatversion=0
core.filemode=false
core.bare=false
core.logallrefupdates=true
core.symlinks=false
core.ignorecase=true
core.hidedotfiles=dotGitOnly
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master
In Git Bash on Windows 7, I occasionally have something happen that causes the color coding to fail when running cucumber scenarios or rspec specs.
Occasionally, it is randomly fixed (where randomly == I don't know what I did to cause it to be fixed).
So when I run:
$ bundle exec cucumber features
Or
$ bundle exec rspec spec
instead of seeing this in color:
......
3 scenarios (3 passed)
6 steps (6 passed)
I see something like:
[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m
3 scenarios ([32m3 passed[0m)
6 steps ([32m6 passed[0m)
I know these are the code representations of the colors, but I don't know why it stops displaying the colors nor do I know how to fix it. What am I missing?
Output from git config --list:
core.symlinks=false
core.autocrlf=true
color.diff=auto
pack.packsizelimit=2g
help.format=html
http.sslcainfo=/bin/curl-ca-bundle.crt
sendemail.smtpserver=/bin/msmtp.exe
user.name=John Uhri
user.email= *****
color.branch=auto
color.diff=auto
color.interactive=auto
color.status=auto
core.repositoryformatversion=0
core.filemode=false
core.bare=false
core.logallrefupdates=true
core.symlinks=false
core.ignorecase=true
core.hidedotfiles=dotGitOnly
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
在 Windows 上,git Bash 使用内置终端,该终端滚动到 cmd 提示符中。如果安装了 cygwin,则可以使用 mintty 终端模拟器(作为“Cygwin Terminal”安装在开始菜单上)。
为什么这很重要?因为 Windows cmd 提示符不解释 ANSI 转义序列。它使用 M$ 颜色控制方案来代替。如果您使用的程序没有在 Windows 上切换到此方案,或通过过滤器,那么您将看到原始转义字符。 Cygwin 的 mintty 控制台完全支持这些代码。
如果颜色通常有效,则这是移植时 cucumber/rspec 中的错误。有人在打印颜色或其他内容时错过了对窗口的检查。在这个问题得到解决之前,解决方法是使用以下 python 脚本:
您需要安装 colorama为此的图书馆。然后只需通过脚本传递输出:
On windows, git Bash uses the built in terminal which is rolled into the cmd prompt. If you install cygwin you can use the mintty terminal emulator (Installed on the start menu as "Cygwin Terminal").
Why is this important? Because the windows cmd prompt term does not interpret ANSI escape sequences. It uses M$ color control scheme instead. If the program you are using does not switch to this scheme on windows, or go through a filter, then you will see the raw escape characters. Cygwin's mintty console has full support for these codes.
If the colors usually work, this is a bug in cucumber/rspec from porting. Somebody missed a check for windows when printing the colors or something. Until this gets fixed, a work around is the following python script:
You will need to install the colorama library for this. Then just pipe your output through the script:
在我的 Windows 7 bash 终端(带有 console2 的 msysgit)上多次尝试获取一些颜色但无果后,我偶然发现了 Jason Karns 博客 'Windows Shell 中的 ANSI 颜色'。
我所要做的就是 解压 ansicon.exe 到永久文件夹并通过该文件夹中的 cmd 运行:
现在所有 bash 日志用颜色代替 [32m 或 [0m 标签,哇!
After a number of fruitless attempts to get some colors on my Windows 7 bash terminals (msysgit with console2), I stumbled on Jason Karns blog 'ANSI color in Windows Shells'.
All I had to do was unzip ansicon.exe to a permanent folder and run via cmd in that folder:
All bash logs now have colors instead of the [32m or [0m tags, woo!
我有相同的 pb,似乎如果您取消设置 TERM 环境变量,它会再次工作。
I have had the same pb, it seems that if you unset the TERM environment variable it works again.
我使用 @aslakhellesoy 的“wac”项目。这有点烦人,因为您必须记住通过它传送命令。但这是我见过的唯一有效的方法。
https://github.com/aslakhellesoy/wac
I use @aslakhellesoy's "wac" project. It's a little annoying because you have to remember to pipe your commands through it. But it's the only thing I've seen work.
https://github.com/aslakhellesoy/wac
我通过设置三个环境变量,使用在 PowerShell(在 Window 的普通控制台中)中运行 Git 的 Git For Windows (V2.5.3) 修复了此问题:
TERM=msys
PAGER='"C:\Program Files \Git\usr\bin\less.exe"'
(注意双引号必须是值的一部分)。--RAW-CONTROL-CHARS
包含在LESS
的值中(因此,根据我的其他偏好:--LONG-PROMPT --no-init --quit- if-one-screen --RAW-CONTROL-CHARS
)。I fixed this with Git For Windows (V2.5.3) running Git within PowerShell (in Window's normal console) by setting three environment variables:
TERM=msys
PAGER='"C:\Program Files\Git\usr\bin\less.exe"'
(note the double quotes need to be part of the value).--RAW-CONTROL-CHARS
inLESS
s value (so with my other preferences:--LONG-PROMPT --no-init --quit-if-one-screen --RAW-CONTROL-CHARS
).尝试安装 win32console gem。
Try installing the win32console gem.
Richard 的建议,即使是在
cmd.exe
(不是 PowerShell)中,也对我有用。我正在运行:
Windows 7(64 位)和 Git-Bash:GNU bash,版本 3.1.23(6)-release (i686-pc-msys)
我必须更改
PAGER
位置匹配我的系统。Richard's suggestions, even in
cmd.exe
(not PowerShell), worked for me.I'm running:
Windows 7 (64-bit) and Git-Bash: GNU bash, version 3.1.23(6)-release (i686-pc-msys)
I had to change the
PAGER
location to match my system.