File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3,10 +3,11 @@ import childProcess from 'node:child_process';
33import path from 'node:path' ;
44import fs from 'node:fs' ;
55import process from 'node:process' ;
6+ import { stripVTControlCharacters } from 'node:util' ;
67
78import { Argument , humanReadableArgName } from './argument.js' ;
89import { CommanderError } from './error.js' ;
9- import { Help , stripColor } from './help.js' ;
10+ import { Help } from './help.js' ;
1011import { Option , DualOptions } from './option.js' ;
1112import { suggestSimilar } from './suggestSimilar.js' ;
1213
@@ -70,7 +71,7 @@ export class Command extends EventEmitter {
7071 useColor ( ) ?? ( process . stdout . isTTY && process . stdout . hasColors ?. ( ) ) ,
7172 getErrHasColors : ( ) =>
7273 useColor ( ) ?? ( process . stderr . isTTY && process . stderr . hasColors ?. ( ) ) ,
73- stripColor : ( str ) => stripColor ( str ) ,
74+ stripColor : ( str ) => stripVTControlCharacters ( str ) ,
7475 } ;
7576
7677 this . _hidden = false ;
Original file line number Diff line number Diff line change 11import { humanReadableArgName } from './argument.js' ;
2+ import { stripVTControlCharacters } from 'node:util' ;
23
34/**
45 * TypeScript import types for JSDoc, used by Visual Studio Code IntelliSense and `npm run typescript-checkJS`
@@ -533,7 +534,7 @@ export class Help {
533534 * @returns {number }
534535 */
535536 displayWidth ( str ) {
536- return stripColor ( str ) . length ;
537+ return stripVTControlCharacters ( str ) . length ;
537538 }
538539
539540 /**
@@ -728,17 +729,3 @@ export class Help {
728729 return wrappedLines . join ( '\n' ) ;
729730 }
730731}
731-
732- /**
733- * Strip style ANSI escape sequences from the string. In particular, SGR (Select Graphic Rendition) codes.
734- *
735- * @param {string } str
736- * @returns {string }
737- * @package
738- */
739-
740- export function stripColor ( str ) {
741- // eslint-disable-next-line no-control-regex
742- const sgrPattern = / \x1b \[ \d * ( ; \d * ) * m / g;
743- return str . replace ( sgrPattern , '' ) ;
744- }
Load diff This file was deleted.
You can’t perform that action at this time.
0 commit comments