Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to maintain console colors #69

Closed
mikeerickson opened this issue Feb 6, 2017 · 5 comments
Closed

How to maintain console colors #69

mikeerickson opened this issue Feb 6, 2017 · 5 comments

Comments

@mikeerickson
Copy link
Sponsor

I have created a simple script:

	execa('bash',['./scripts/lint-styles.sh'])
		.then(result => {
			console.log(result.stdout);
		});

This script calls

#!/usr/bin/env bash

./node_modules/.bin/sass-lint "./resources/assets/sass/*.s+(a|c)ss" -q -v

When executed, the output is correct, but it does not have the color output which displays when executing from cli

@SamVerschueren
Copy link
Contributor

Try this

execa('bash',['./scripts/lint-styles.sh'], {stdio: 'inherit'})

@shellscape
Copy link

I've found that in most cases (not confirmed outside of an OSX env), using the option env: { FORCE_COLOR: true } works as well, without having to use {stdio: 'inherit'}, which can cause other issues #70.

Some bins/apps also have options, like Mocha --colors, which will force colors as well.

@mikeerickson
Copy link
Sponsor Author

@SamVerschueren @shellscape Thanks gents, I went with the env: { FORCE_COLOR: true } option (the stdio option as producing some spurious null output in addition to colors.

var execa = require('execa');

execa("eslint", ["./src/**/*.js"], {env: {FORCE_COLOR: true}})
  .then(result => {
	console.log(result.stdout);
});

@LiranBri
Copy link

LiranBri commented Oct 7, 2020

note that true is not a valid env variable value, as env variables are always of type string. if you use typescript, it would not get passed.

so should be:

var execa = require('execa');

execa("eslint", ["./src/**/*.js"], {env: {FORCE_COLOR: 'true'}})
  .then(result => {
	console.log(result.stdout);
});

@Samrose-Ahmed
Copy link

Not that using stdio:inherit will not let you access stdout/stderr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants