-
-
Notifications
You must be signed in to change notification settings - Fork 32k
lib: support FORCE_COLOR
for non TTY streams
#48034
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,6 +121,7 @@ const { | |
commonPrefix, | ||
} = require('internal/readline/utils'); | ||
const { Console } = require('console'); | ||
const { shouldColorize } = require('internal/util/colors'); | ||
const CJSModule = require('internal/modules/cjs/loader').Module; | ||
let _builtinLibs = ArrayPrototypeFilter( | ||
CJSModule.builtinModules, | ||
|
@@ -270,11 +271,7 @@ function REPLServer(prompt, | |
|
||
if (options.terminal && options.useColors === undefined) { | ||
// If possible, check if stdout supports colors or not. | ||
if (options.output.hasColors) { | ||
options.useColors = options.output.hasColors(); | ||
} else if (process.env.NODE_DISABLE_COLORS === undefined) { | ||
options.useColors = true; | ||
} | ||
options.useColors = shouldColorize(options.output) || process.env.NODE_DISABLE_COLORS === undefined; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I realize this was there before this PR, but it seems weird to me to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, can probably be fixed in a follow-up PR There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @aduh95 tested your example, it will be an empty string, not undefined: NODE_DISABLE_COLORS= node -p "util.inspect(process.env.NODE_DISABLE_COLORS)"
'' |
||
} | ||
|
||
// TODO(devsnek): Add a test case for custom eval functions. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict'; | ||
|
||
require('../../common'); | ||
|
||
console.log(123, 'foo', { bar: 'baz' }); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[33m123[39m foo { bar: [32m'baz'[39m } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
throw new Error('Should include grayed stack trace') |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
*force_colors.js:1 | ||
throw new Error('Should include grayed stack trace') | ||
^ | ||
|
||
Error: Should include grayed stack trace | ||
at Object.<anonymous> [90m(/[39mtest*force_colors.js:1:7[90m)[39m | ||
[90m at Module._compile (node:internal*modules*cjs*loader:1255:14)[39m | ||
[90m at Module._extensions..js (node:internal*modules*cjs*loader:1309:10)[39m | ||
[90m at Module.load (node:internal*modules*cjs*loader:1113:32)[39m | ||
[90m at Module._load (node:internal*modules*cjs*loader:960:12)[39m | ||
[90m at Function.executeUserEntryPoint [as runMain] (node:internal*modules*run_main:83:12)[39m | ||
[90m at node:internal*main*run_main_module:23:47[39m | ||
|
||
Node.js * |
Uh oh!
There was an error while loading. Please reload this page.