Skip to content
Myr

Use node:util stripVTControlCharacters instead of own code (#2486)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by John Gee · committed by GitHub · parent 987f289 · Browse files · 3 files+5 added−86 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+5 added−86 removed

  • tests:+0 added−69 removed
  • other:+5 added−17 removed

3 files+5 added−86 removed

modified:lib/command.js+3 added-2 removed
1 unmodified line
2import childProcess from 'node:child_process';3import path from 'node:path';4import fs from 'node:fs';5import process from 'node:process';6import { stripVTControlCharacters } from 'node:util';78import { Argument, humanReadableArgName } from './argument.js';9import { CommanderError } from './error.js';9import { Help, stripColor } from './help.js';10import { Help } from './help.js';11import { Option, DualOptions } from './option.js';12import { suggestSimilar } from './suggestSimilar.js';1314export class Command extends EventEmitter {
55 unmodified lines
70 getOutHasColors: () =>71 useColor() ?? (process.stdout.isTTY && process.stdout.hasColors?.()),72 getErrHasColors: () =>73 useColor() ?? (process.stderr.isTTY && process.stderr.hasColors?.()),73 stripColor: (str) => stripColor(str),74 stripColor: (str) => stripVTControlCharacters(str),75 };7677 this._hidden = false;78 /** @type {(Option | null | undefined)} */
2712 unmodified lines
modified:lib/help.js+2 added-15 removed
1import { humanReadableArgName } from './argument.js';2import { stripVTControlCharacters } from 'node:util';34/**5 * TypeScript import types for JSDoc, used by Visual Studio Code IntelliSense and `npm run typescript-checkJS`6 * https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html#import-types
526 unmodified lines
533 * @param {string} str534 * @returns {number}535 */536 displayWidth(str) {536 return stripColor(str).length;537 return stripVTControlCharacters(str).length;538 }539540 /**541 * Style the title for displaying in the help. Called with 'Usage:', 'Options:', etc.
186 unmodified lines
728729 return wrappedLines.join('\n');730 }731}731732/**733 * Strip style ANSI escape sequences from the string. In particular, SGR (Select Graphic Rendition) codes.734 *735 * @param {string} str736 * @returns {string}737 * @package738 */739740export function stripColor(str) {741 // eslint-disable-next-line no-control-regex742 const sgrPattern = /\x1b\[\d*(;\d*)*m/g;743 return str.replace(sgrPattern, '');744}
deleted:tests/help.stripAnsi.test.js-69 removed