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

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

问题描述

在Git的Bash在Windows 7上,我偶尔有事情发生,导致颜色编码运行黄瓜方案或RSpec的规格时失败。

有时,它是随机的固定(其中随机==我不知道我做了什么导致它是固定的)。

所以,当我运行:

  $捆绑EXEC黄瓜功能

或者

  $束EXEC rspec的规范

而不是颜色看到的是:

  ...... 情景3(3传递)
 6个步骤(6传递)

我看到的是这样的:

  [32米[0分[32米[0分[32米[0分[32米[0分[32米[0分[32米。[0米 3情景([32立方米传递[0米)
 6步([32m6传递[0米)

我知道这些颜色的code再presentations,但我不知道为什么它停止显示的颜色也不知道如何解决它。我缺少什么?


这混帐配置--list输出:

  core.symlinks = FALSE
core.autocrlf =真
color.diff =汽车
pack.packsizelimit =2克
help.format = HTML
http.sslcainfo = / bin中/卷曲-CA-bundle.crt
sendemail.smtpserver = / bin中/ msmtp.exe
user.name =约翰Uhri
user.email = *****
color.branch =汽车
color.diff =汽车
color.interactive =汽车
color.status =汽车
core.repositoryformatversion = 0
core.filemode = FALSE
core.bare = FALSE
core.logallrefupdates =真
core.symlinks = FALSE
core.ignorecase =真
core.hidedotfiles = dotGitOnly
remote.origin.fetch = +裁判/头/ *:裁判/遥控器/产地/ *
branch.master.remote =由来
branch.master.merge =裁判/头/主


解决方案

在窗口,混帐Bash使用内置在其中滚进了CMD提示符终端。如果您安装Cygwin可以使用mintty终端仿真器(安装在开始菜单的Cygwin的终端上)。

为什么这很重要?由于Windows的命令提示符长期的不跨preT ANSI转义序列的。它采用M $的色彩控制方案,而不是。如果您使用的程序不切换到该方案在Windows上,或经过一个过滤器,然后你会看到原始的转义字符。 Cygwin的mintty控制台对这些codeS全力支持。

如果颜色通常工作,这是从移植黄瓜/ RSpec的一个bug。打印颜色或东西时,有人错过了窗口的支票。在此之前得到固定,周围的工作就是下面的python脚本:

 #!的/ usr /斌/包膜蟒蛇
#过滤器ANSI从标准输入逃逸到stdout
从__future__进口print_function
从COLORAMA进口的init
进口SYS
在里面()在sys.stdin.readlines线():
    打印(行)

您将需要安装 COLORAMA 库这一点。然后,只需管你通过脚本输出:

  $束EXEC rspec的规格| colorFilter.py

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

解决方案

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:

#!/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)

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

$ bundle exec rspec spec | colorFilter.py

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

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