Skip to content

Commit

Permalink
Merge pull request #7 from BenoitZugmeyer/allow-forcing-colors
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinhagemeister committed Mar 31, 2021
2 parents 4a8f654 + d128fa9 commit 8f591d8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@ import { red, cyan } from 'kolorist';
console.log(red(`Error: something failed in ${cyan('my-file.js')}.`));
```

You can also disable colors globally via the following environment variables:
You can also disable or enable colors globally via the following environment variables:

- `NODE_DISABLE_COLORS`
- `TERM=dumb`
- `FORCE_COLOR=0`
- disable:
- `NODE_DISABLE_COLORS`
- `TERM=dumb`
- `FORCE_COLOR=0`

- enable:
- `FORCE_COLOR=1`

On top of that you can disable colors right from node:

Expand Down
12 changes: 7 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ let supportLevel: SupportLevel = SupportLevel.none;

if (globalVar.process && globalVar.process.env && globalVar.process.stdout) {
const { FORCE_COLOR, NODE_DISABLE_COLORS, TERM } = globalVar.process.env;
enabled =
!NODE_DISABLE_COLORS &&
TERM !== 'dumb' &&
FORCE_COLOR !== '0' &&
process.stdout.isTTY;
if (NODE_DISABLE_COLORS || FORCE_COLOR === '0') {
enabled = false;
} else if (FORCE_COLOR === '1') {
enabled = true;
} else {
enabled = TERM !== 'dumb' && process.stdout.isTTY;
}

if (enabled) {
supportLevel = TERM && TERM.endsWith('-256color')
Expand Down

0 comments on commit 8f591d8

Please sign in to comment.