Skip to content

Commit

Permalink
Chore: Replace ansi-escapes with @inquirer/core/ansi
Browse files Browse the repository at this point in the history
  • Loading branch information
SBoudrias committed Nov 17, 2024
1 parent 9671d9a commit 15fcfbe
Show file tree
Hide file tree
Showing 11 changed files with 11 additions and 26 deletions.
1 change: 0 additions & 1 deletion packages/checkbox/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@
"@inquirer/core": "^10.1.0",
"@inquirer/figures": "^1.0.8",
"@inquirer/type": "^3.0.1",
"ansi-escapes": "^4.3.2",
"yoctocolors-cjs": "^2.1.2"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/checkbox/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import {
type Theme,
type Status,
} from '@inquirer/core';
import { cursorHide } from '@inquirer/core/ansi';
import type { PartialDeep } from '@inquirer/type';
import colors from 'yoctocolors-cjs';
import figures from '@inquirer/figures';
import ansiEscapes from 'ansi-escapes';

type CheckboxTheme = {
icon: {
Expand Down Expand Up @@ -300,7 +300,7 @@ export default createPrompt(
error = `\n${theme.style.error(errorMsg)}`;
}

return `${prefix} ${message}${helpTipTop}\n${page}${helpTipBottom}${choiceDescription}${error}${ansiEscapes.cursorHide}`;
return `${prefix} ${message}${helpTipTop}\n${page}${helpTipBottom}${choiceDescription}${error}${cursorHide}`;
},
);

Expand Down
1 change: 0 additions & 1 deletion packages/inquirer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@
"@inquirer/core": "^10.1.0",
"@inquirer/prompts": "^7.1.0",
"@inquirer/type": "^3.0.1",
"ansi-escapes": "^4.3.2",
"mute-stream": "^2.0.0",
"run-async": "^3.0.0",
"rxjs": "^7.8.1"
Expand Down
4 changes: 2 additions & 2 deletions packages/inquirer/src/ui/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import {
import runAsync from 'run-async';
import MuteStream from 'mute-stream';
import { AbortPromptError } from '@inquirer/core';
import { cursorShow } from '@inquirer/core/ansi';
import type { InquirerReadline } from '@inquirer/type';
import ansiEscapes from 'ansi-escapes';
import type {
Answers,
Question,
Expand Down Expand Up @@ -325,7 +325,7 @@ export default class PromptsRunner<A extends Answers> {
rl.removeListener('SIGINT', onForceClose);
rl.setPrompt('');
rl.output.unmute();
rl.output.write(ansiEscapes.cursorShow);
rl.output.write(cursorShow);
rl.output.end();
rl.close();
};
Expand Down
3 changes: 1 addition & 2 deletions packages/password/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@
},
"dependencies": {
"@inquirer/core": "^10.1.0",
"@inquirer/type": "^3.0.1",
"ansi-escapes": "^4.3.2"
"@inquirer/type": "^3.0.1"
},
"devDependencies": {
"@arethetypeswrong/cli": "^0.17.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/password/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
type Theme,
type Status,
} from '@inquirer/core';
import ansiEscapes from 'ansi-escapes';
import { cursorHide } from '@inquirer/core/ansi';
import type { PartialDeep } from '@inquirer/type';

type PasswordConfig = {
Expand Down Expand Up @@ -63,7 +63,7 @@ export default createPrompt<string, PasswordConfig>((config, done) => {
const maskChar = typeof config.mask === 'string' ? config.mask : '*';
formattedValue = maskChar.repeat(value.length);
} else if (status !== 'done') {
helpTip = `${theme.style.help('[input is masked]')}${ansiEscapes.cursorHide}`;
helpTip = `${theme.style.help('[input is masked]')}${cursorHide}`;
}

if (status === 'done') {
Expand Down
1 change: 0 additions & 1 deletion packages/select/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@
"@inquirer/core": "^10.1.0",
"@inquirer/figures": "^1.0.8",
"@inquirer/type": "^3.0.1",
"ansi-escapes": "^4.3.2",
"yoctocolors-cjs": "^2.1.2"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/select/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import {
type Theme,
type Status,
} from '@inquirer/core';
import { cursorHide } from '@inquirer/core/ansi';
import type { PartialDeep } from '@inquirer/type';
import colors from 'yoctocolors-cjs';
import figures from '@inquirer/figures';
import ansiEscapes from 'ansi-escapes';

type SelectTheme = {
icon: { cursor: string };
Expand Down Expand Up @@ -246,7 +246,7 @@ export default createPrompt(
? `\n${theme.style.description(selectedChoice.description)}`
: ``;

return `${[prefix, message, helpTipTop].filter(Boolean).join(' ')}\n${page}${helpTipBottom}${choiceDescription}${ansiEscapes.cursorHide}`;
return `${[prefix, message, helpTipTop].filter(Boolean).join(' ')}\n${page}${helpTipBottom}${choiceDescription}${cursorHide}`;
},
);

Expand Down
1 change: 0 additions & 1 deletion packages/testing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@
},
"dependencies": {
"@inquirer/type": "^3.0.1",
"ansi-escapes": "^4.3.2",
"mute-stream": "^2.0.0",
"strip-ansi": "^6.0.1"
},
Expand Down
7 changes: 1 addition & 6 deletions packages/testing/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { Stream } from 'node:stream';
import MuteStream from 'mute-stream';
import stripAnsi from 'strip-ansi';
import ansiEscapes from 'ansi-escapes';
import type { Prompt, Context } from '@inquirer/type';

const ignoredAnsi = new Set([ansiEscapes.cursorHide, ansiEscapes.cursorShow]);

class BufferedStream extends Stream.Writable {
#_fullOutput: string = '';
#_chunks: Array<string> = [];
Expand All @@ -18,9 +15,7 @@ class BufferedStream extends Stream.Writable {

// There's some ANSI Inquirer just send to keep state of the terminal clear; we'll ignore those since they're
// unlikely to be used by end users or part of prompt code.
if (!ignoredAnsi.has(str)) {
this.#_rawChunks.push(str);
}
this.#_rawChunks.push(str);

// 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
Expand Down
7 changes: 1 addition & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,6 @@ __metadata:
"@inquirer/testing": "npm:^2.1.37"
"@inquirer/type": "npm:^3.0.1"
"@repo/tsconfig": "workspace:*"
ansi-escapes: "npm:^4.3.2"
tshy: "npm:^3.0.2"
yoctocolors-cjs: "npm:^2.1.2"
peerDependencies:
Expand Down Expand Up @@ -664,7 +663,6 @@ __metadata:
"@inquirer/testing": "npm:^2.1.37"
"@inquirer/type": "npm:^3.0.1"
"@repo/tsconfig": "workspace:*"
ansi-escapes: "npm:^4.3.2"
tshy: "npm:^3.0.2"
peerDependencies:
"@types/node": ">=18"
Expand Down Expand Up @@ -766,7 +764,6 @@ __metadata:
"@inquirer/testing": "npm:^2.1.37"
"@inquirer/type": "npm:^3.0.1"
"@repo/tsconfig": "workspace:*"
ansi-escapes: "npm:^4.3.2"
tshy: "npm:^3.0.2"
yoctocolors-cjs: "npm:^2.1.2"
peerDependencies:
Expand All @@ -783,7 +780,6 @@ __metadata:
"@repo/tsconfig": "workspace:*"
"@types/mute-stream": "npm:^0.0.4"
"@types/node": "npm:^22.9.0"
ansi-escapes: "npm:^4.3.2"
mute-stream: "npm:^2.0.0"
strip-ansi: "npm:^6.0.1"
tshy: "npm:^3.0.2"
Expand Down Expand Up @@ -2220,7 +2216,7 @@ __metadata:
languageName: node
linkType: hard

"ansi-escapes@npm:^4.2.1, ansi-escapes@npm:^4.3.2":
"ansi-escapes@npm:^4.2.1":
version: 4.3.2
resolution: "ansi-escapes@npm:4.3.2"
dependencies:
Expand Down Expand Up @@ -4801,7 +4797,6 @@ __metadata:
"@inquirer/type": "npm:^3.0.1"
"@repo/tsconfig": "workspace:*"
"@types/mute-stream": "npm:^0.0.4"
ansi-escapes: "npm:^4.3.2"
mute-stream: "npm:^2.0.0"
run-async: "npm:^3.0.0"
rxjs: "npm:^7.8.1"
Expand Down

0 comments on commit 15fcfbe

Please sign in to comment.