ANSI color output in webview?!?

Hello,

I just recognized that in one of my GitHub Action workflows which I ported over from travis no ANSI colors are shown in the Webview of the output. Is there some setting or are ANSI color escape sequences are simply stripped in GitHub Actions while with travis they are perfectly displayed in the webview?

In the actual job that is run I use the nodejs-based mocha test framework and in its output Mocha uses ANSI escape sequences to either show success with a green arrow or in case of a failure with a red cross and this works perfectly in the Travis webview while in the GitHub Actions job output view no ANSI colors are displayed at all.

So does anyone have an idea how to enable ANSI colors in the webview or is this simply a missing feature?!?

Thanks in advance.

Yes, we support ANSI colors.

I haven’t used Mocha specifically. Many test runners check for an env var or terminal setting before they output color.

Hi @jens-maus ,

What do you mean of ‘ANSI color escape sequences’ here? Could you please show a screenshot in travis?

Checked on my side, with below command, the ANSI escape sequences works in bash output as expected.

echo -e "\033[31;1;4mHello\033[0m"

ANSIColor.png

Thanks.

@weide-zhou wrote:

 

What do you mean of ‘ANSI color escape sequences’? Could you please show a screenshot?

I mean the following. This is the output on travis, e.g.:

Bildschirmfoto 2020-02-14 um 08.50.32.png

And the same output, but on GitHub Actions looks like:

Bildschirmfoto 2020-02-14 um 08.51.06.png

So please note the color difference and that within GitHub Actions no colorized output is presented at all. That’s why I was wondering how to enable ANSI color output in GitHub Actions or if this is a missing feature.

1 Like

@mscoutermarsh wrote:
Yes, we support ANSI colors.

I haven’t used Mocha specifically. Many test runners check for an env var or terminal setting before they output color.

Do you know which terminal settings or env variable as used to enable this is GitHub Actions? In fact, I already tried to set the TERM variable to “xterm-256color” right before starting the mocha test, but this didn’t help. So I was wondering if there might be a standard TERM/ENV variable which I need to setup in the workflow and if so, why it is not setup per default as in travis I never had to care about that and ANSI color output is the default.

Ok, after some more investigation I could solve the problem myself. I simply had to add the command-line option –colors when executing mocha (see https://github.com/jens-maus/occu-test/commit/0a57c8fadda3e7d4d8f2043c7171dc4d6a10966e).

So somehow with the default environment of GitHub Actions mocha could not identify itself that it is running within a TTY enabled device and thus enable ANSI color output itself. See here (https://github.com/mochajs/mocha/issues/1304) for similar discussions to force mocha to output ANSI colors on non tty devices. So the remaining question that might be there is, why isn’t the GitHub Actions environment not identified as a proper TTY device by mocha while within travis there isn’t any issue and mocha outputs all content using ANSI colors?!?

1 Like

Hi @jens-maus ,

Glad to know it’s been resolved by adding the command-line option –colors when executing mocha.

It’s recommended to raise a ticket here where github action managers will take a review. Thanks.

FYI, if you’re using chalk, you may also set the environment variable FORCE_COLOR to 0 for no color, 1 for more color, 2 for even more color, or 3 for the most colorful of colors:

env:
  FORCE_COLOR: 3

For some libraries, though, this will not be enough or annoying warnings will print in the webview because it is  not technically a TTY. For example, boxen needs a TTY so this repeated error message shows up:

Screen Shot 2020-05-11 at 5.30.43 PM.png

1 Like

There does indeed seem to be a problem with GitHub Actions not working as one would expect with

TERM=xterm

or

TERM=xterm-256color

. I’ve tried both of these to try and get some colored output from my xUnit tests, but neither one works (where they do work when running the tests locally, on Linux).

Here is one example of such a job: https://github.com/perlun/perlang/runs/690297760?check_suite_focus=true

@weide-zhouIf no issue has been created for this yet, please let me know and I’ll file one. Not all tools support a FORCE_COLOR flag, unfortunately, so it would be important to get GitHub Actions working more flawlessly in this regard.

2 Likes

Hi @perlun ,

Thanks for your checking! Please raise a feedback/feature_request ticket here where github product manager will take a review.

Regards.