Skip to content

Commit 1904e57

Browse files
authoredJan 4, 2025··
Replace custom ANSI regex logic with Node built-in (#224)
1 parent edd4425 commit 1904e57

File tree

3 files changed

+6
-26
lines changed

3 files changed

+6
-26
lines changed
 

‎.changeset/slimy-dolphins-press.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@clack/prompts": patch
3+
---
4+
5+
Replace custom utility for stripping ANSI control sequences with Node's built-in [`stripVTControlCharacters`](https://nodejs.org/docs/latest/api/util.html#utilstripvtcontrolcharactersstr) utility.

‎packages/prompts/LICENSE

-14
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,3 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
77
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
88

99
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10-
11-
---
12-
13-
`ansi-regex` is adapted from https://github.com/chalk/ansi-regex
14-
15-
MIT License
16-
17-
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
18-
19-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
20-
21-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
22-
23-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

‎packages/prompts/src/index.ts

+1-12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { stripVTControlCharacters as strip } from 'node:util';
12
import {
23
ConfirmPrompt,
34
GroupMultiSelectPrompt,
@@ -569,7 +570,6 @@ export const groupMultiselect = <Value>(opts: GroupMultiSelectOptions<Value>) =>
569570
}).prompt() as Promise<Value[] | symbol>;
570571
};
571572

572-
const strip = (str: string) => str.replace(ansiRegex(), '');
573573
export const note = (message = '', title = '') => {
574574
const lines = `\n${message}\n`.split('\n');
575575
const titleLen = strip(title).length;
@@ -740,17 +740,6 @@ export const spinner = () => {
740740
};
741741
};
742742

743-
// Adapted from https://github.com/chalk/ansi-regex
744-
// @see LICENSE
745-
function ansiRegex() {
746-
const pattern = [
747-
'[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)',
748-
'(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))',
749-
].join('|');
750-
751-
return new RegExp(pattern, 'g');
752-
}
753-
754743
export type PromptGroupAwaitedReturn<T> = {
755744
[P in keyof T]: Exclude<Awaited<T[P]>, symbol>;
756745
};

0 commit comments

Comments
 (0)
Please sign in to comment.