-
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: disable if no TTY session (eg; command pipe) (#33)
* Disable color output in pipes * chore: set `isTTY` for CI * fix: allow `FORCE_COLOR` override * chore: run CI w/ `FORCE_COLOR` override * fix: respond to "FORCE_COLOR=0" & GITHUB_ACTIONS * fix: revert GITHUB_ACTIONS read * chore: include bash tests for ENV detect * sigh * debug: print all * fix(bash): remove faulty TTY assumption * chore: addl combos; ignore trailing space Co-authored-by: Luke Edwards <luke.edwards05@gmail.com>
- Loading branch information
Showing
6 changed files
with
61 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/usr/bin/env bash | ||
|
||
code=0 | ||
fail() { | ||
printf "\x1b[31m[FAIL]\x1b[39m %s\n" "$@" >&2 | ||
code=1 | ||
} | ||
|
||
colors() { | ||
printf "\x1b[33m[DEBUG]\x1b[39m \"%s\" :: %s \n" "$2" "$1" | ||
[ "$1" != "foo" ] || fail "$2" | ||
} | ||
|
||
nocolor() { | ||
printf "\x1b[33m[DEBUG]\x1b[39m \"%s\" :: %s \n" "$2" "$1" | ||
[[ "$1" =~ foo* ]] || fail "$2" | ||
} | ||
|
||
faketty() { | ||
script -qfc "$(printf "%q " "$@")" /dev/null | ||
} | ||
|
||
# process.stdout.isTTY = undefined; | ||
printf "\nprocess.stdout.isTTY = %s;\n" `node -p "process.stdout.isTTY"` | ||
nocolor `node -p "require('.').red('foo')"` "FORCE_COLOR=?" | ||
nocolor `FORCE_COLOR=0 node -p "require('.').red('foo')"` "FORCE_COLOR=0" | ||
nocolor `NODE_DISABLE_COLORS=1 node -p "require('.').red('foo')"` "NODE_DISABLE_COLORS=1" | ||
nocolor `NODE_DISABLE_COLORS=1 FORCE_COLOR=1 node -p "require('.').red('foo')"` "NODE_DISABLE_COLORS=1; FORCE_COLOR=1" | ||
colors `FORCE_COLOR=1 node -p "require('.').red('foo')"` "FORCE_COLOR=1" | ||
nocolor `TERM=dumb FORCE_COLOR=1 node -p "require('.').red('foo')"` "TERM=dumb; FORCE_COLOR=1" | ||
nocolor `TERM=dumb node -p "require('.').red('foo')"` "TERM=dumb" | ||
|
||
# process.stdout.isTTY = true; | ||
printf "\n(faketty) process.stdout.isTTY = %s;\n" `faketty node -p "process.stdout.isTTY"` | ||
colors `faketty node -p "require('.').red('foo')"` "FORCE_COLOR=?" | ||
colors `FORCE_COLOR=0 faketty node -p "require('.').red('foo')"` "FORCE_COLOR=0" | ||
nocolor `NODE_DISABLE_COLORS=1 faketty node -p "require('.').red('foo')"` "NODE_DISABLE_COLORS=1" | ||
nocolor `NODE_DISABLE_COLORS=1 FORCE_COLOR=1 faketty node -p "require('.').red('foo')"` "NODE_DISABLE_COLORS=1; FORCE_COLOR=1" | ||
nocolor `TERM=dumb FORCE_COLOR=1 faketty node -p "require('.').red('foo')"` "TERM=dumb; FORCE_COLOR=1" | ||
colors `FORCE_COLOR=1 faketty node -p "require('.').red('foo')"` "FORCE_COLOR=1" | ||
nocolor `TERM=dumb node -r esm test/xyz.js` "TERM=dumb" | ||
|
||
if [ "$code" == "0" ]; then | ||
printf "\x1b[32m[PASS]\x1b[39m $.enabled updates correctly \n" | ||
fi | ||
|
||
exit $code |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import kleur from '../index.mjs'; | ||
console.log(kleur.red('foo')); |