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

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

问题描述

在Git Bash在Windows 7,我偶尔会发生的事情,导致颜色编码失败时,运行黄瓜场景或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


推荐答案

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天全站免登陆