Skip to content

Commit

Permalink
Chore(*): Replace strip-ansi with node:util stripVTControlCharacters (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
SBoudrias authored Jan 14, 2025
1 parent c6a37cd commit b0ea0d8
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 12 deletions.
4 changes: 2 additions & 2 deletions packages/core/core.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { AsyncResource } from 'node:async_hooks';
import { Stream } from 'node:stream';
import { describe, it, expect, vi } from 'vitest';
import { render } from '@inquirer/testing';
import stripAnsi from 'strip-ansi';
import { stripVTControlCharacters } from 'node:util';
import ansiEscapes from 'ansi-escapes';
import {
createPrompt,
Expand Down Expand Up @@ -744,7 +744,7 @@ describe('Separator', () => {
});

it('renders separator', () => {
expect(stripAnsi(new Separator().separator)).toMatchInlineSnapshot(
expect(stripVTControlCharacters(new Separator().separator)).toMatchInlineSnapshot(
'"──────────────"',
);
expect(new Separator('===').separator).toEqual('===');
Expand Down
1 change: 0 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@
"cli-width": "^4.1.0",
"mute-stream": "^2.0.0",
"signal-exit": "^4.1.0",
"strip-ansi": "^6.0.1",
"wrap-ansi": "^6.2.0",
"yoctocolors-cjs": "^2.1.2"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/lib/screen-manager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import stripAnsi from 'strip-ansi';
import { stripVTControlCharacters } from 'node:util';
import ansiEscapes from 'ansi-escapes';
import { breakLines, readlineWidth } from './utils.js';
import type { InquirerReadline } from '@inquirer/type';
Expand Down Expand Up @@ -33,7 +33,7 @@ export default class ScreenManager {
render(content: string, bottomContent: string = '') {
// Write message to screen and setPrompt to control backspace
const promptLine = lastLine(content);
const rawPromptLine = stripAnsi(promptLine);
const rawPromptLine = stripVTControlCharacters(promptLine);

// Remove the rl.line from our prompt. We can't rely on the content of
// rl.line (mainly because of the password prompt), so just rely on it's
Expand Down
3 changes: 1 addition & 2 deletions packages/testing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@
"dependencies": {
"@inquirer/type": "^3.0.2",
"ansi-escapes": "^4.3.2",
"mute-stream": "^2.0.0",
"strip-ansi": "^6.0.1"
"mute-stream": "^2.0.0"
},
"devDependencies": {
"@arethetypeswrong/cli": "^0.17.2",
Expand Down
6 changes: 3 additions & 3 deletions packages/testing/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Stream } from 'node:stream';
import { stripVTControlCharacters } from 'node:util';
import MuteStream from 'mute-stream';
import stripAnsi from 'strip-ansi';
import ansiEscapes from 'ansi-escapes';
import type { Prompt, Context } from '@inquirer/type';

Expand All @@ -25,7 +25,7 @@ class BufferedStream extends Stream.Writable {
// Stripping the ANSI codes here because Inquirer will push commands ANSI (like cursor move.)
// This is probably fine since we don't care about those for testing; but this could become
// an issue if we ever want to test for those.
if (stripAnsi(str).trim().length > 0) {
if (stripVTControlCharacters(str).trim().length > 0) {
this.#_chunks.push(str);
}
callback();
Expand Down Expand Up @@ -89,7 +89,7 @@ export async function render<const Props, const Value>(
events,
getScreen: ({ raw }: { raw?: boolean } = {}): string => {
const lastScreen = output.getLastChunk({ raw });
return raw ? lastScreen : stripAnsi(lastScreen).trim();
return raw ? lastScreen : stripVTControlCharacters(lastScreen).trim();
},
getFullOutput: (): string => {
return output.getFullOutput();
Expand Down
2 changes: 0 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,6 @@ __metadata:
cli-width: "npm:^4.1.0"
mute-stream: "npm:^2.0.0"
signal-exit: "npm:^4.1.0"
strip-ansi: "npm:^6.0.1"
tshy: "npm:^3.0.2"
wrap-ansi: "npm:^6.2.0"
yoctocolors-cjs: "npm:^2.1.2"
Expand Down Expand Up @@ -789,7 +788,6 @@ __metadata:
"@types/node": "npm:^22.10.5"
ansi-escapes: "npm:^4.3.2"
mute-stream: "npm:^2.0.0"
strip-ansi: "npm:^6.0.1"
tshy: "npm:^3.0.2"
peerDependencies:
"@types/node": ">=18"
Expand Down

0 comments on commit b0ea0d8

Please sign in to comment.