Git Product home page Git Product logo

Comments (22)

viceice avatar viceice commented on September 2, 2024 2

I think this can be closed, as it's fixed with v7.2

from supports-color.

ai avatar ai commented on September 2, 2024 1

Seems like we should call @chrispat here

from supports-color.

rethab avatar rethab commented on September 2, 2024 1

@Qix- from what I can tell, this not solved yet:

In the code, this check:

	if (haveStream && !streamIsTTY && forceColor === undefined) {
		return 0;
	}

comes before this part:

	if ('CI' in env) {
      // etc...

When run on GitHub Actions, the first condition already returns 0. This is because of this open issue in the runner: actions/runner#241

As a result of this, chalk does use color in my action. I'd be happy to work out a reproducing example if anyone's interested, but it looks kind of obvious to me given the evidence above.

from supports-color.

Qix- avatar Qix- commented on September 2, 2024

Hey @ai :) Do you have an example I could take a look at? Chalk behaves differently based on how it's used (e.g. with pipes). Can't confirm if this is a bug or not without seeing if there's another issue.

from supports-color.

ai avatar ai commented on September 2, 2024

Sure, here is an example with FORCE_COLOR=2.

I have Node.js script with simple code like:

#!/usr/bin/env node

import chalk from 'chalk'

process.stdout.write(chalk.red('Test'))

When I run this script in CI with:

      - name: Deploy files
        run: ./script.js

I have no colors and I start to have colors only with:

      - name: Deploy files
        run: ./script.js
        env:
          FORCE_COLOR: 2

from supports-color.

Qix- avatar Qix- commented on September 2, 2024

Which version of chalk? chalk@3 uses [email protected] which includes #102, so this should be working.

Can you verify you're at chalk >= 3.0?

from supports-color.

ai avatar ai commented on September 2, 2024
"chalk": "^3.0.0",

I checked that I have GITHUB_ACTIONS env.

Maybe some other check disable it?

from supports-color.

Qix- avatar Qix- commented on September 2, 2024

Very strange. Could you see if process.stdout.isTTY is truthey?

from supports-color.

ai avatar ai commented on September 2, 2024

process.stdout.isTTY is undefined: https://github.com/logux/logux.io/commit/6392d1a99a61710b8a5e5f08e36a2796ea689ff5/checks?check_suite_id=379405498

from supports-color.

Qix- avatar Qix- commented on September 2, 2024

That's why. For whatever reason, Node doesn't seem to think it's outputting to a TTY. This is probably on Github not setting up a proper pseudo terminal environment for actions to run in.

Unfortunately, there's no great way to properly solve this without Github's help. The environment checks have to come after the TTY checks, otherwise we'd break people piping output to other programs (which would get polluted with escape sequences).

Unless we think Github can fix this with PTY support, unfortunately this is a nofix - FORCE_COLOR=1/=2 will have to be used instead.

Sorry about that :/ Wish I had a better answer.

If a member of the Github staff wants to answer, I'll happily re-open this.

from supports-color.

Qix- avatar Qix- commented on September 2, 2024

Took the liberty of contacting Github about it. If they respond positively, I'll open this back up and track it ^^

Thanks for bringing it to our attention!

from supports-color.

ai avatar ai commented on September 2, 2024

I also created an issue (hope I used right place for it) actions/runner-images#218

Thanks for finding the actual reason.

from supports-color.

Qix- avatar Qix- commented on September 2, 2024

Re-opening for visibility, then :)

from supports-color.

ai avatar ai commented on September 2, 2024

Can we just force colors on GITHUB_ACTIONS even without isTTY since we know that GH supports colors?

from supports-color.

Qix- avatar Qix- commented on September 2, 2024

You can, sure. But as a general rule, no. It would break anyone using pipes.

from supports-color.

ai avatar ai commented on September 2, 2024

Oh, I forgot about pipes

from supports-color.

SimenB avatar SimenB commented on September 2, 2024

Solved with https://github.blog/changelog/2020-04-15-github-actions-sets-the-ci-environment-variable-to-true/? Maybe not if it's tty detection that's off 😀

from supports-color.

mshima avatar mshima commented on September 2, 2024

This should be fixed in 651576a

A new release should be great.

from supports-color.

Qix- avatar Qix- commented on September 2, 2024

Yep, thanks for the reminder. Let me know if this isn't solved by upgrading.

from supports-color.

mrmckeb avatar mrmckeb commented on September 2, 2024

Does anyone have this working? We're also seeing level 0 returned due to isTTY being undefined.

As @rethab said, this seems to be an issue on GitHub's side - but given it has been so long, perhaps a workaround can be implemented here?

from supports-color.

peternewman avatar peternewman commented on September 2, 2024

As mentioned at the top @mrmckeb FORCE_COLOR=2 works. See for example my PR here:
https://github.com/openstreetmap/iD/pull/9692/files

Or any of the others referencing this issue and linked to it.

from supports-color.

mrmckeb avatar mrmckeb commented on September 2, 2024

That's a great solution, thanks. I was wondering if anyone had a solution that end-users wouldn't need to implement though.

For now, I've implemented this:

if (env.GITHUB_ACTIONS) {
  const supportsColor = createSupportsColor({ isTTY: true });
  if (supportsColor) {
    chalk.level = supportsColor.level;
  }
}

from supports-color.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.