gpt4 book ai didi

git - 在 Windows 7 上的 Git Bash 中,颜色在运行 Cucumber 或 rspec 时显示为代码

转载 作者:IT王子 更新时间:2023-10-29 00:50:30 26 4
gpt4 key购买 nike

在 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

最佳答案

在 Windows 上,git Bash 使用内置的终端,该终端被滚动到 cmd 提示符中。如果安装了 cygwin,则可以使用 mintty 终端仿真器(在开始菜单上安装为“Cygwin 终端”)。

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

如果颜色通常有效,则这是 cucumber/rspec 中移植的错误。有人在打印颜色或其他内容时错过了窗口检查。在这个问题得到解决之前,解决方法是使用以下 python 脚本:

#!/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为此的图书馆。然后只需通过脚本管道输出:

$ bundle exec rspec spec | colorFilter.py

关于git - 在 Windows 7 上的 Git Bash 中,颜色在运行 Cucumber 或 rspec 时显示为代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5921556/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com