在 Windows 7 上的 Git Bash 中,颜色在运行 Cucumber 或 rspec 时显示为代码 [英] In Git Bash on Windows 7, Colors display as code when running Cucumber or rspec

查看:14
本文介绍了在 Windows 7 上的 Git Bash 中,颜色在运行 Cucumber 或 rspec 时显示为代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Windows 7 上的 Git Bash 中,我偶尔会发生一些事情,导致在运行黄瓜场景或 rspec 规范时颜色编码失败.

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).

所以当我跑步时:

$ 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)

我知道这些是颜色的代码表示,但我不知道为什么它停止显示颜色,也不知道如何修复它.我错过了什么?

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?

来自 git config --list 的输出:

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

推荐答案

在 Windows 上,git Bash 使用内置的终端,该终端会滚动到 cmd 提示符中.如果您安装 cygwin,您可以使用 mintty 终端模拟器(在开始菜单上安装为Cygwin 终端").

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").

为什么这很重要?因为windows cmd 提示词不解释ANSI 转义序列.它使用 M$ 颜色控制方案代替.如果您使用的程序没有在 Windows 上切换到此方案,或者没有通过过滤器,那么您将看到原始转义字符.Cygwin 的 mintty 控制台完全支持这些代码.

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.

如果颜色通常有效,这是来自移植的黄瓜/rspec 中的错误.有人在打印颜色或其他东西时错过了检查窗口.在此问题得到解决之前,解决方法是以下 python 脚本:

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:

#!/usr/bin/env python
# Filter ANSI escapes from stdin to stdout
from __future__ import print_function
from colorama import init
import sys
init()

for line in sys.stdin.readlines():
    print(line)

您需要为此安装 colorama 库.然后只需通过脚本管道输出:

You will need to install the colorama library for this. Then just pipe your output through the script:

$ bundle exec rspec spec | colorFilter.py

这篇关于在 Windows 7 上的 Git Bash 中,颜色在运行 Cucumber 或 rspec 时显示为代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆