@@ -30,6 +30,7 @@ const {
3030 ERR_INCOMPATIBLE_OPTION_PAIR ,
3131 } ,
3232} = require ( 'internal/errors' ) ;
33+ const { validateInteger } = require ( 'internal/validators' ) ;
3334const { previewEntries } = internalBinding ( 'util' ) ;
3435const { Buffer : { isBuffer } } = require ( 'buffer' ) ;
3536const {
@@ -47,11 +48,14 @@ const kTraceBegin = 'b'.charCodeAt(0);
4748const kTraceEnd = 'e' . charCodeAt ( 0 ) ;
4849const kTraceInstant = 'n' . charCodeAt ( 0 ) ;
4950
51+ const kMaxGroupIndentation = 1000 ;
52+
5053// Lazy loaded for startup performance.
5154let cliTable ;
5255
5356// Track amount of indentation required via `console.group()`.
5457const kGroupIndent = Symbol ( 'kGroupIndent' ) ;
58+ const kGroupIndentationWidth = Symbol ( 'kGroupIndentWidth' ) ;
5559const kFormatForStderr = Symbol ( 'kFormatForStderr' ) ;
5660const kFormatForStdout = Symbol ( 'kFormatForStdout' ) ;
5761const kGetInspectOptions = Symbol ( 'kGetInspectOptions' ) ;
@@ -87,7 +91,8 @@ function Console(options /* or: stdout, stderr, ignoreErrors = true */) {
8791 stderr = stdout ,
8892 ignoreErrors = true ,
8993 colorMode = 'auto' ,
90- inspectOptions
94+ inspectOptions,
95+ groupIndentation,
9196 } = options ;
9297
9398 if ( ! stdout || typeof stdout . write !== 'function' ) {
@@ -100,6 +105,11 @@ function Console(options /* or: stdout, stderr, ignoreErrors = true */) {
100105 if ( typeof colorMode !== 'boolean' && colorMode !== 'auto' )
101106 throw new ERR_INVALID_ARG_VALUE ( 'colorMode' , colorMode ) ;
102107
108+ if ( groupIndentation !== undefined ) {
109+ validateInteger ( groupIndentation , 'groupIndentation' ,
110+ 0 , kMaxGroupIndentation ) ;
111+ }
112+
103113 if ( typeof inspectOptions === 'object' && inspectOptions !== null ) {
104114 if ( inspectOptions . colors !== undefined &&
105115 options . colorMode !== undefined ) {
@@ -124,7 +134,7 @@ function Console(options /* or: stdout, stderr, ignoreErrors = true */) {
124134 }
125135
126136 this [ kBindStreamsEager ] ( stdout , stderr ) ;
127- this [ kBindProperties ] ( ignoreErrors , colorMode ) ;
137+ this [ kBindProperties ] ( ignoreErrors , colorMode , groupIndentation ) ;
128138}
129139
130140const consolePropAttributes = {
@@ -175,7 +185,8 @@ Console.prototype[kBindStreamsLazy] = function(object) {
175185 } ) ;
176186} ;
177187
178- Console . prototype [ kBindProperties ] = function ( ignoreErrors , colorMode ) {
188+ Console . prototype [ kBindProperties ] = function ( ignoreErrors , colorMode ,
189+ groupIndentation = 2 ) {
179190 ObjectDefineProperties ( this , {
180191 '_stdoutErrorHandler' : {
181192 ...consolePropAttributes ,
@@ -194,7 +205,11 @@ Console.prototype[kBindProperties] = function(ignoreErrors, colorMode) {
194205 [ kCounts ] : { ...consolePropAttributes , value : new Map ( ) } ,
195206 [ kColorMode ] : { ...consolePropAttributes , value : colorMode } ,
196207 [ kIsConsole ] : { ...consolePropAttributes , value : true } ,
197- [ kGroupIndent ] : { ...consolePropAttributes , value : '' }
208+ [ kGroupIndent ] : { ...consolePropAttributes , value : '' } ,
209+ [ kGroupIndentationWidth ] : {
210+ ...consolePropAttributes ,
211+ value : groupIndentation
212+ } ,
198213 } ) ;
199214} ;
200215
@@ -397,12 +412,13 @@ const consoleMethods = {
397412 if ( data . length > 0 ) {
398413 this . log ( ...data ) ;
399414 }
400- this [ kGroupIndent ] += ' ' ;
415+ this [ kGroupIndent ] += ' ' . repeat ( this [ kGroupIndentationWidth ] ) ;
401416 } ,
402417
403418 groupEnd ( ) {
404419 this [ kGroupIndent ] =
405- this [ kGroupIndent ] . slice ( 0 , this [ kGroupIndent ] . length - 2 ) ;
420+ this [ kGroupIndent ] . slice ( 0 , this [ kGroupIndent ] . length -
421+ this [ kGroupIndentationWidth ] ) ;
406422 } ,
407423
408424 // https://console.spec.whatwg.org/#table
0 commit comments