File tree Expand file tree Collapse file tree 1 file changed +20
-5
lines changed Expand file tree Collapse file tree 1 file changed +20
-5
lines changed Original file line number Diff line number Diff line change 11'use strict'
22
33const chalk = require ( 'chalk' )
4+ const { stdout : { level } = { } } = require ( 'supports-color' )
45
5- const getColors = function ( { opts : { colors } } ) {
6- // Can disable or force colors with `opts.colors`.
7- // chalk will automatically disable colors if output does not support it.
8- const chalkOpts = { enabled : Boolean ( colors ) }
9-
6+ const getColors = function ( { opts } ) {
7+ const chalkOpts = getChalkOpts ( { opts } )
108 return chalk . constructor ( chalkOpts )
119}
1210
11+ // Can disable or force colors with `opts.colors`.
12+ // chalk will automatically disable colors if output does not support it.
13+ const getChalkOpts = function ( { opts : { colors } } ) {
14+ if ( colors === undefined ) {
15+ return { }
16+ }
17+
18+ if ( colors === false ) {
19+ return { enabled : false }
20+ }
21+
22+ // Chalk `level` must be set otherwise `enabled` will be noop if terminal
23+ // does not support color (e.g. during a shell file redirection)
24+ // However it should only be set if it is `undefined` or `0`
25+ return { enabled : true , level : level || 2 }
26+ }
27+
1328module . exports = {
1429 getColors,
1530}
You can’t perform that action at this time.
0 commit comments