In Git Bash on Windows 7, Colors display as code when running Cucumber or rspec

后端 未结 7 1911
予麋鹿
予麋鹿 2020-12-10 04:44

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

7条回答
  •  自闭症患者
    2020-12-10 05:19

    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
    

提交回复
热议问题