push neon reactor
This commit is contained in:
+200
@@ -0,0 +1,200 @@
|
||||
# @clack/core
|
||||
|
||||
## 0.3.5
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 4845f4f: Fixes a bug which kept the terminal cursor hidden after a prompt is cancelled
|
||||
- d7b2fb9: Adds missing `LICENSE` file. Since the `package.json` file has always included `"license": "MIT"`, please consider this a licensing clarification rather than a licensing change.
|
||||
|
||||
## 0.3.4
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- a04e418: fix(@clack/core): keyboard input not working after await in spinner
|
||||
- 4f6fcf5: feat(@clack/core): allow tab completion for placeholders
|
||||
|
||||
## 0.3.3
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- cd79076: fix: restore raw mode on unblock
|
||||
|
||||
## 0.3.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- c96eda5: Enable hard line-wrapping behavior for long words without spaces
|
||||
|
||||
## 0.3.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 58a1df1: Fix line duplication bug by automatically wrapping prompts to `process.stdout.columns`
|
||||
|
||||
## 0.3.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- 8a4a12f: Add `GroupMultiSelect` prompt
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 8a4a12f: add `groupMultiselect` prompt
|
||||
|
||||
## 0.2.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- ec812b6: fix `readline` hang on Windows
|
||||
|
||||
## 0.2.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- d74dd05: Adds a `selectKey` prompt type
|
||||
- 54c1bc3: **Breaking Change** `multiselect` has renamed `initialValue` to `initialValues`
|
||||
|
||||
## 0.1.9
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 1251132: Multiselect: return `Value[]` instead of `Option[]`.
|
||||
- 8994382: Add a password prompt to `@clack/prompts`
|
||||
|
||||
## 0.1.8
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- d96071c: Don't mutate `initialValue` in `multiselect`, fix parameter type for `validate()`.
|
||||
|
||||
Credits to @banjo for the bug report and initial PR!
|
||||
|
||||
## 0.1.7
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 6d9e675: Add support for neovim cursor motion (`hjkl`)
|
||||
|
||||
Thanks [@esau-morais](https://github.com/esau-morais) for the assist!
|
||||
|
||||
## 0.1.6
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 7fb5375: Adds a new `defaultValue` option to the text prompt, removes automatic usage of the placeholder value.
|
||||
|
||||
## 0.1.5
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- de1314e: Support `required` option for multi-select
|
||||
|
||||
## 0.1.4
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- ca77da1: Fix multiselect initial value logic
|
||||
- 8aed606: Fix `MaxListenersExceededWarning` by detaching `stdin` listeners on close
|
||||
|
||||
## 0.1.3
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- a99c458: Support `initialValue` option for text prompt
|
||||
|
||||
## 0.1.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Allow isCancel to type guard any unknown value
|
||||
- 7dcad8f: Allow placeholder to be passed to TextPrompt
|
||||
- 2242f13: Fix multiselect returning undefined
|
||||
- b1341d6: Improved placeholder handling
|
||||
|
||||
## 0.1.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 4be7dbf: Ensure raw mode is unset on submit
|
||||
- b480679: Preserve value if validation fails
|
||||
|
||||
## 0.1.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- 7015ec9: Create new prompt: multi-select
|
||||
|
||||
## 0.0.12
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 9d371c3: Fix rendering bug when using y/n to confirm
|
||||
|
||||
## 0.0.11
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 441d5b7: fix select return undefined
|
||||
- d20ef2a: Update keywords, URLs
|
||||
- fe13c2f: fix cursor missing after submit
|
||||
|
||||
## 0.0.10
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- a0cb382: Add `main` entrypoint
|
||||
|
||||
## 0.0.9
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Fix node@16 issue (cannot read "createInterface" of undefined)
|
||||
|
||||
## 0.0.8
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- a4b5e13: Bug fixes, exposes `block` utility
|
||||
|
||||
## 0.0.7
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Fix cursor bug
|
||||
|
||||
## 0.0.6
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Fix error with character check
|
||||
|
||||
## 0.0.5
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 491f9e0: update readme
|
||||
|
||||
## 0.0.4
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 7372d5c: Fix bug with line deletion
|
||||
|
||||
## 0.0.3
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 5605d28: Do not bundle dependencies (take II)
|
||||
|
||||
## 0.0.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 2ee67cb: don't bundle deps
|
||||
|
||||
## 0.0.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 306598e: Initial publish, still WIP
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) Nate Moore
|
||||
|
||||
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:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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.
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
# `@clack/core`
|
||||
|
||||
Clack contains low-level primitives for implementing your own command-line applications.
|
||||
|
||||
Currently, `TextPrompt`, `SelectPrompt`, and `ConfirmPrompt` are exposed as well as the base `Prompt` class.
|
||||
|
||||
Each `Prompt` accepts a `render` function.
|
||||
|
||||
```js
|
||||
import { TextPrompt, isCancel } from '@clack/core';
|
||||
|
||||
const p = new TextPrompt({
|
||||
render() {
|
||||
return `What's your name?\n${this.valueWithCursor}`;
|
||||
},
|
||||
});
|
||||
|
||||
const name = await p.prompt();
|
||||
if (isCancel(name)) {
|
||||
process.exit(0);
|
||||
}
|
||||
```
|
||||
+15
File diff suppressed because one or more lines are too long
+1
File diff suppressed because one or more lines are too long
+151
@@ -0,0 +1,151 @@
|
||||
import { Readable, Writable } from 'node:stream';
|
||||
|
||||
declare function isCancel(value: unknown): value is symbol;
|
||||
interface PromptOptions<Self extends Prompt> {
|
||||
render(this: Omit<Self, 'prompt'>): string | void;
|
||||
placeholder?: string;
|
||||
initialValue?: any;
|
||||
validate?: ((value: any) => string | void) | undefined;
|
||||
input?: Readable;
|
||||
output?: Writable;
|
||||
debug?: boolean;
|
||||
}
|
||||
type State = 'initial' | 'active' | 'cancel' | 'submit' | 'error';
|
||||
declare class Prompt {
|
||||
protected input: Readable;
|
||||
protected output: Writable;
|
||||
private rl;
|
||||
private opts;
|
||||
private _track;
|
||||
private _render;
|
||||
protected _cursor: number;
|
||||
state: State;
|
||||
value: any;
|
||||
error: string;
|
||||
constructor({ render, input, output, ...opts }: PromptOptions<Prompt>, trackValue?: boolean);
|
||||
prompt(): Promise<string | symbol>;
|
||||
private subscribers;
|
||||
on(event: string, cb: (...args: any) => any): void;
|
||||
once(event: string, cb: (...args: any) => any): void;
|
||||
emit(event: string, ...data: any[]): void;
|
||||
private unsubscribe;
|
||||
private onKeypress;
|
||||
protected close(): void;
|
||||
private restoreCursor;
|
||||
private _prevFrame;
|
||||
private render;
|
||||
}
|
||||
|
||||
interface ConfirmOptions extends PromptOptions<ConfirmPrompt> {
|
||||
active: string;
|
||||
inactive: string;
|
||||
initialValue?: boolean;
|
||||
}
|
||||
declare class ConfirmPrompt extends Prompt {
|
||||
get cursor(): 0 | 1;
|
||||
private get _value();
|
||||
constructor(opts: ConfirmOptions);
|
||||
}
|
||||
|
||||
interface GroupMultiSelectOptions<T extends {
|
||||
value: any;
|
||||
}> extends PromptOptions<GroupMultiSelectPrompt<T>> {
|
||||
options: Record<string, T[]>;
|
||||
initialValues?: T['value'][];
|
||||
required?: boolean;
|
||||
cursorAt?: T['value'];
|
||||
}
|
||||
declare class GroupMultiSelectPrompt<T extends {
|
||||
value: any;
|
||||
}> extends Prompt {
|
||||
options: (T & {
|
||||
group: string | boolean;
|
||||
})[];
|
||||
cursor: number;
|
||||
getGroupItems(group: string): T[];
|
||||
isGroupSelected(group: string): boolean;
|
||||
private toggleValue;
|
||||
constructor(opts: GroupMultiSelectOptions<T>);
|
||||
}
|
||||
|
||||
interface MultiSelectOptions<T extends {
|
||||
value: any;
|
||||
}> extends PromptOptions<MultiSelectPrompt<T>> {
|
||||
options: T[];
|
||||
initialValues?: T['value'][];
|
||||
required?: boolean;
|
||||
cursorAt?: T['value'];
|
||||
}
|
||||
declare class MultiSelectPrompt<T extends {
|
||||
value: any;
|
||||
}> extends Prompt {
|
||||
options: T[];
|
||||
cursor: number;
|
||||
private get _value();
|
||||
private toggleAll;
|
||||
private toggleValue;
|
||||
constructor(opts: MultiSelectOptions<T>);
|
||||
}
|
||||
|
||||
interface PasswordOptions extends PromptOptions<PasswordPrompt> {
|
||||
mask?: string;
|
||||
}
|
||||
declare class PasswordPrompt extends Prompt {
|
||||
valueWithCursor: string;
|
||||
private _mask;
|
||||
get cursor(): number;
|
||||
get masked(): any;
|
||||
constructor({ mask, ...opts }: PasswordOptions);
|
||||
}
|
||||
|
||||
interface SelectOptions<T extends {
|
||||
value: any;
|
||||
}> extends PromptOptions<SelectPrompt<T>> {
|
||||
options: T[];
|
||||
initialValue?: T['value'];
|
||||
}
|
||||
declare class SelectPrompt<T extends {
|
||||
value: any;
|
||||
}> extends Prompt {
|
||||
options: T[];
|
||||
cursor: number;
|
||||
private get _value();
|
||||
private changeValue;
|
||||
constructor(opts: SelectOptions<T>);
|
||||
}
|
||||
|
||||
interface SelectKeyOptions<T extends {
|
||||
value: any;
|
||||
}> extends PromptOptions<SelectKeyPrompt<T>> {
|
||||
options: T[];
|
||||
}
|
||||
declare class SelectKeyPrompt<T extends {
|
||||
value: any;
|
||||
}> extends Prompt {
|
||||
options: T[];
|
||||
cursor: number;
|
||||
constructor(opts: SelectKeyOptions<T>);
|
||||
}
|
||||
|
||||
interface TextOptions extends PromptOptions<TextPrompt> {
|
||||
placeholder?: string;
|
||||
defaultValue?: string;
|
||||
}
|
||||
declare class TextPrompt extends Prompt {
|
||||
valueWithCursor: string;
|
||||
get cursor(): number;
|
||||
constructor(opts: TextOptions);
|
||||
}
|
||||
|
||||
declare function block({ input, output, overwrite, hideCursor, }?: {
|
||||
input?: (NodeJS.ReadStream & {
|
||||
fd: 0;
|
||||
}) | undefined;
|
||||
output?: (NodeJS.WriteStream & {
|
||||
fd: 1;
|
||||
}) | undefined;
|
||||
overwrite?: boolean | undefined;
|
||||
hideCursor?: boolean | undefined;
|
||||
}): () => void;
|
||||
|
||||
export { ConfirmPrompt, GroupMultiSelectPrompt, MultiSelectPrompt, PasswordPrompt, Prompt, SelectKeyPrompt, SelectPrompt, type State, TextPrompt, block, isCancel };
|
||||
+151
@@ -0,0 +1,151 @@
|
||||
import { Readable, Writable } from 'node:stream';
|
||||
|
||||
declare function isCancel(value: unknown): value is symbol;
|
||||
interface PromptOptions<Self extends Prompt> {
|
||||
render(this: Omit<Self, 'prompt'>): string | void;
|
||||
placeholder?: string;
|
||||
initialValue?: any;
|
||||
validate?: ((value: any) => string | void) | undefined;
|
||||
input?: Readable;
|
||||
output?: Writable;
|
||||
debug?: boolean;
|
||||
}
|
||||
type State = 'initial' | 'active' | 'cancel' | 'submit' | 'error';
|
||||
declare class Prompt {
|
||||
protected input: Readable;
|
||||
protected output: Writable;
|
||||
private rl;
|
||||
private opts;
|
||||
private _track;
|
||||
private _render;
|
||||
protected _cursor: number;
|
||||
state: State;
|
||||
value: any;
|
||||
error: string;
|
||||
constructor({ render, input, output, ...opts }: PromptOptions<Prompt>, trackValue?: boolean);
|
||||
prompt(): Promise<string | symbol>;
|
||||
private subscribers;
|
||||
on(event: string, cb: (...args: any) => any): void;
|
||||
once(event: string, cb: (...args: any) => any): void;
|
||||
emit(event: string, ...data: any[]): void;
|
||||
private unsubscribe;
|
||||
private onKeypress;
|
||||
protected close(): void;
|
||||
private restoreCursor;
|
||||
private _prevFrame;
|
||||
private render;
|
||||
}
|
||||
|
||||
interface ConfirmOptions extends PromptOptions<ConfirmPrompt> {
|
||||
active: string;
|
||||
inactive: string;
|
||||
initialValue?: boolean;
|
||||
}
|
||||
declare class ConfirmPrompt extends Prompt {
|
||||
get cursor(): 0 | 1;
|
||||
private get _value();
|
||||
constructor(opts: ConfirmOptions);
|
||||
}
|
||||
|
||||
interface GroupMultiSelectOptions<T extends {
|
||||
value: any;
|
||||
}> extends PromptOptions<GroupMultiSelectPrompt<T>> {
|
||||
options: Record<string, T[]>;
|
||||
initialValues?: T['value'][];
|
||||
required?: boolean;
|
||||
cursorAt?: T['value'];
|
||||
}
|
||||
declare class GroupMultiSelectPrompt<T extends {
|
||||
value: any;
|
||||
}> extends Prompt {
|
||||
options: (T & {
|
||||
group: string | boolean;
|
||||
})[];
|
||||
cursor: number;
|
||||
getGroupItems(group: string): T[];
|
||||
isGroupSelected(group: string): boolean;
|
||||
private toggleValue;
|
||||
constructor(opts: GroupMultiSelectOptions<T>);
|
||||
}
|
||||
|
||||
interface MultiSelectOptions<T extends {
|
||||
value: any;
|
||||
}> extends PromptOptions<MultiSelectPrompt<T>> {
|
||||
options: T[];
|
||||
initialValues?: T['value'][];
|
||||
required?: boolean;
|
||||
cursorAt?: T['value'];
|
||||
}
|
||||
declare class MultiSelectPrompt<T extends {
|
||||
value: any;
|
||||
}> extends Prompt {
|
||||
options: T[];
|
||||
cursor: number;
|
||||
private get _value();
|
||||
private toggleAll;
|
||||
private toggleValue;
|
||||
constructor(opts: MultiSelectOptions<T>);
|
||||
}
|
||||
|
||||
interface PasswordOptions extends PromptOptions<PasswordPrompt> {
|
||||
mask?: string;
|
||||
}
|
||||
declare class PasswordPrompt extends Prompt {
|
||||
valueWithCursor: string;
|
||||
private _mask;
|
||||
get cursor(): number;
|
||||
get masked(): any;
|
||||
constructor({ mask, ...opts }: PasswordOptions);
|
||||
}
|
||||
|
||||
interface SelectOptions<T extends {
|
||||
value: any;
|
||||
}> extends PromptOptions<SelectPrompt<T>> {
|
||||
options: T[];
|
||||
initialValue?: T['value'];
|
||||
}
|
||||
declare class SelectPrompt<T extends {
|
||||
value: any;
|
||||
}> extends Prompt {
|
||||
options: T[];
|
||||
cursor: number;
|
||||
private get _value();
|
||||
private changeValue;
|
||||
constructor(opts: SelectOptions<T>);
|
||||
}
|
||||
|
||||
interface SelectKeyOptions<T extends {
|
||||
value: any;
|
||||
}> extends PromptOptions<SelectKeyPrompt<T>> {
|
||||
options: T[];
|
||||
}
|
||||
declare class SelectKeyPrompt<T extends {
|
||||
value: any;
|
||||
}> extends Prompt {
|
||||
options: T[];
|
||||
cursor: number;
|
||||
constructor(opts: SelectKeyOptions<T>);
|
||||
}
|
||||
|
||||
interface TextOptions extends PromptOptions<TextPrompt> {
|
||||
placeholder?: string;
|
||||
defaultValue?: string;
|
||||
}
|
||||
declare class TextPrompt extends Prompt {
|
||||
valueWithCursor: string;
|
||||
get cursor(): number;
|
||||
constructor(opts: TextOptions);
|
||||
}
|
||||
|
||||
declare function block({ input, output, overwrite, hideCursor, }?: {
|
||||
input?: (NodeJS.ReadStream & {
|
||||
fd: 0;
|
||||
}) | undefined;
|
||||
output?: (NodeJS.WriteStream & {
|
||||
fd: 1;
|
||||
}) | undefined;
|
||||
overwrite?: boolean | undefined;
|
||||
hideCursor?: boolean | undefined;
|
||||
}): () => void;
|
||||
|
||||
export { ConfirmPrompt, GroupMultiSelectPrompt, MultiSelectPrompt, PasswordPrompt, Prompt, SelectKeyPrompt, SelectPrompt, type State, TextPrompt, block, isCancel };
|
||||
+151
@@ -0,0 +1,151 @@
|
||||
import { Readable, Writable } from 'node:stream';
|
||||
|
||||
declare function isCancel(value: unknown): value is symbol;
|
||||
interface PromptOptions<Self extends Prompt> {
|
||||
render(this: Omit<Self, 'prompt'>): string | void;
|
||||
placeholder?: string;
|
||||
initialValue?: any;
|
||||
validate?: ((value: any) => string | void) | undefined;
|
||||
input?: Readable;
|
||||
output?: Writable;
|
||||
debug?: boolean;
|
||||
}
|
||||
type State = 'initial' | 'active' | 'cancel' | 'submit' | 'error';
|
||||
declare class Prompt {
|
||||
protected input: Readable;
|
||||
protected output: Writable;
|
||||
private rl;
|
||||
private opts;
|
||||
private _track;
|
||||
private _render;
|
||||
protected _cursor: number;
|
||||
state: State;
|
||||
value: any;
|
||||
error: string;
|
||||
constructor({ render, input, output, ...opts }: PromptOptions<Prompt>, trackValue?: boolean);
|
||||
prompt(): Promise<string | symbol>;
|
||||
private subscribers;
|
||||
on(event: string, cb: (...args: any) => any): void;
|
||||
once(event: string, cb: (...args: any) => any): void;
|
||||
emit(event: string, ...data: any[]): void;
|
||||
private unsubscribe;
|
||||
private onKeypress;
|
||||
protected close(): void;
|
||||
private restoreCursor;
|
||||
private _prevFrame;
|
||||
private render;
|
||||
}
|
||||
|
||||
interface ConfirmOptions extends PromptOptions<ConfirmPrompt> {
|
||||
active: string;
|
||||
inactive: string;
|
||||
initialValue?: boolean;
|
||||
}
|
||||
declare class ConfirmPrompt extends Prompt {
|
||||
get cursor(): 0 | 1;
|
||||
private get _value();
|
||||
constructor(opts: ConfirmOptions);
|
||||
}
|
||||
|
||||
interface GroupMultiSelectOptions<T extends {
|
||||
value: any;
|
||||
}> extends PromptOptions<GroupMultiSelectPrompt<T>> {
|
||||
options: Record<string, T[]>;
|
||||
initialValues?: T['value'][];
|
||||
required?: boolean;
|
||||
cursorAt?: T['value'];
|
||||
}
|
||||
declare class GroupMultiSelectPrompt<T extends {
|
||||
value: any;
|
||||
}> extends Prompt {
|
||||
options: (T & {
|
||||
group: string | boolean;
|
||||
})[];
|
||||
cursor: number;
|
||||
getGroupItems(group: string): T[];
|
||||
isGroupSelected(group: string): boolean;
|
||||
private toggleValue;
|
||||
constructor(opts: GroupMultiSelectOptions<T>);
|
||||
}
|
||||
|
||||
interface MultiSelectOptions<T extends {
|
||||
value: any;
|
||||
}> extends PromptOptions<MultiSelectPrompt<T>> {
|
||||
options: T[];
|
||||
initialValues?: T['value'][];
|
||||
required?: boolean;
|
||||
cursorAt?: T['value'];
|
||||
}
|
||||
declare class MultiSelectPrompt<T extends {
|
||||
value: any;
|
||||
}> extends Prompt {
|
||||
options: T[];
|
||||
cursor: number;
|
||||
private get _value();
|
||||
private toggleAll;
|
||||
private toggleValue;
|
||||
constructor(opts: MultiSelectOptions<T>);
|
||||
}
|
||||
|
||||
interface PasswordOptions extends PromptOptions<PasswordPrompt> {
|
||||
mask?: string;
|
||||
}
|
||||
declare class PasswordPrompt extends Prompt {
|
||||
valueWithCursor: string;
|
||||
private _mask;
|
||||
get cursor(): number;
|
||||
get masked(): any;
|
||||
constructor({ mask, ...opts }: PasswordOptions);
|
||||
}
|
||||
|
||||
interface SelectOptions<T extends {
|
||||
value: any;
|
||||
}> extends PromptOptions<SelectPrompt<T>> {
|
||||
options: T[];
|
||||
initialValue?: T['value'];
|
||||
}
|
||||
declare class SelectPrompt<T extends {
|
||||
value: any;
|
||||
}> extends Prompt {
|
||||
options: T[];
|
||||
cursor: number;
|
||||
private get _value();
|
||||
private changeValue;
|
||||
constructor(opts: SelectOptions<T>);
|
||||
}
|
||||
|
||||
interface SelectKeyOptions<T extends {
|
||||
value: any;
|
||||
}> extends PromptOptions<SelectKeyPrompt<T>> {
|
||||
options: T[];
|
||||
}
|
||||
declare class SelectKeyPrompt<T extends {
|
||||
value: any;
|
||||
}> extends Prompt {
|
||||
options: T[];
|
||||
cursor: number;
|
||||
constructor(opts: SelectKeyOptions<T>);
|
||||
}
|
||||
|
||||
interface TextOptions extends PromptOptions<TextPrompt> {
|
||||
placeholder?: string;
|
||||
defaultValue?: string;
|
||||
}
|
||||
declare class TextPrompt extends Prompt {
|
||||
valueWithCursor: string;
|
||||
get cursor(): number;
|
||||
constructor(opts: TextOptions);
|
||||
}
|
||||
|
||||
declare function block({ input, output, overwrite, hideCursor, }?: {
|
||||
input?: (NodeJS.ReadStream & {
|
||||
fd: 0;
|
||||
}) | undefined;
|
||||
output?: (NodeJS.WriteStream & {
|
||||
fd: 1;
|
||||
}) | undefined;
|
||||
overwrite?: boolean | undefined;
|
||||
hideCursor?: boolean | undefined;
|
||||
}): () => void;
|
||||
|
||||
export { ConfirmPrompt, GroupMultiSelectPrompt, MultiSelectPrompt, PasswordPrompt, Prompt, SelectKeyPrompt, SelectPrompt, type State, TextPrompt, block, isCancel };
|
||||
+15
File diff suppressed because one or more lines are too long
+1
File diff suppressed because one or more lines are too long
+62
@@ -0,0 +1,62 @@
|
||||
{
|
||||
"name": "@clack/core",
|
||||
"version": "0.3.5",
|
||||
"type": "module",
|
||||
"main": "./dist/index.cjs",
|
||||
"module": "./dist/index.mjs",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"import": "./dist/index.mjs",
|
||||
"require": "./dist/index.cjs"
|
||||
},
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"types": "./dist/index.d.ts",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/natemoo-re/clack",
|
||||
"directory": "packages/core"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/natemoo-re/clack/issues"
|
||||
},
|
||||
"homepage": "https://github.com/natemoo-re/clack/tree/main/packages/core#readme",
|
||||
"files": [
|
||||
"dist",
|
||||
"CHANGELOG.md"
|
||||
],
|
||||
"keywords": [
|
||||
"ask",
|
||||
"clack",
|
||||
"cli",
|
||||
"command-line",
|
||||
"command",
|
||||
"input",
|
||||
"interact",
|
||||
"interface",
|
||||
"menu",
|
||||
"prompt",
|
||||
"prompts",
|
||||
"stdin",
|
||||
"ui"
|
||||
],
|
||||
"author": {
|
||||
"name": "Nate Moore",
|
||||
"email": "nate@natemoo.re",
|
||||
"url": "https://twitter.com/n_moore"
|
||||
},
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"picocolors": "^1.0.0",
|
||||
"sisteransi": "^1.0.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"vitest": "^1.6.0",
|
||||
"wrap-ansi": "^8.1.0"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "unbuild",
|
||||
"test": "vitest run"
|
||||
}
|
||||
}
|
||||
+242
@@ -0,0 +1,242 @@
|
||||
# @clack/prompts
|
||||
|
||||
## 0.6.3
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- c96eda5: Enable hard line-wrapping behavior for long words without spaces
|
||||
- Updated dependencies [c96eda5]
|
||||
- @clack/core@0.3.2
|
||||
|
||||
## 0.6.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 58a1df1: Fix line duplication bug by automatically wrapping prompts to `process.stdout.columns`
|
||||
- Updated dependencies [58a1df1]
|
||||
- @clack/core@0.3.1
|
||||
|
||||
## 0.6.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- ca08fb6: Support complex value types for `select`, `multiselect` and `groupMultiselect`.
|
||||
|
||||
## 0.6.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- 8a4a12f: add `groupMultiselect` prompt
|
||||
- 165a1b3: Add `log` APIs. Supports `log.info`, `log.success`, `log.warn`, and `log.error`. For low-level control, `log.message` is also exposed.
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [8a4a12f]
|
||||
- Updated dependencies [8a4a12f]
|
||||
- @clack/core@0.3.0
|
||||
|
||||
## 0.5.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- cc11917: Update default `password` mask
|
||||
- Updated dependencies [ec812b6]
|
||||
- @clack/core@0.2.1
|
||||
|
||||
## 0.5.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- d74dd05: Adds a `selectKey` prompt type
|
||||
- 54c1bc3: **Breaking Change** `multiselect` has renamed `initialValue` to `initialValues`
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [d74dd05]
|
||||
- Updated dependencies [54c1bc3]
|
||||
- @clack/core@0.2.0
|
||||
|
||||
## 0.4.5
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 1251132: Multiselect: return `Value[]` instead of `Option[]`.
|
||||
- 8994382: Add a password prompt to `@clack/prompts`
|
||||
- Updated dependencies [1251132]
|
||||
- Updated dependencies [8994382]
|
||||
- @clack/core@0.1.9
|
||||
|
||||
## 0.4.4
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- d96071c: Don't mutate `initialValue` in `multiselect`, fix parameter type for `validate()`.
|
||||
|
||||
Credits to @banjo for the bug report and initial PR!
|
||||
|
||||
- Updated dependencies [d96071c]
|
||||
- @clack/core@0.1.8
|
||||
|
||||
## 0.4.3
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 83d890e: Fix text cancel display bug
|
||||
|
||||
## 0.4.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Update README
|
||||
|
||||
## 0.4.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 7fb5375: Adds a new `defaultValue` option to the text prompt, removes automatic usage of the placeholder value.
|
||||
- Updated dependencies [7fb5375]
|
||||
- @clack/core@0.1.6
|
||||
|
||||
## 0.4.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- 61b88b6: Add `group` construct to group many prompts together
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- de1314e: Support `required` option for multi-select
|
||||
- Updated dependencies [de1314e]
|
||||
- @clack/core@0.1.5
|
||||
|
||||
## 0.3.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- 493c592: Improve types for select/multiselect prompts. Numbers and booleans are now supported as the `value` option.
|
||||
- 15558e3: Improved Windows/non-unicode support
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- ca77da1: Fix multiselect initial value logic
|
||||
- Updated dependencies [ca77da1]
|
||||
- Updated dependencies [8aed606]
|
||||
- @clack/core@0.1.4
|
||||
|
||||
## 0.2.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 94b24d9: Fix CJS `ansi-regex` interop
|
||||
|
||||
## 0.2.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- a99c458: Support `initialValue` option for text prompt
|
||||
- Updated dependencies [a99c458]
|
||||
- @clack/core@0.1.3
|
||||
|
||||
## 0.2.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- Improved type safety
|
||||
- b1341d6: Updated styles, new note component
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [7dcad8f]
|
||||
- Updated dependencies [2242f13]
|
||||
- Updated dependencies [b1341d6]
|
||||
- @clack/core@0.1.2
|
||||
|
||||
## 0.1.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- fa09bf5: Use circle for radio, square for checkbox
|
||||
- Updated dependencies [4be7dbf]
|
||||
- Updated dependencies [b480679]
|
||||
- @clack/core@0.1.1
|
||||
|
||||
## 0.1.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- 7015ec9: Create new prompt: multi-select
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [7015ec9]
|
||||
- @clack/core@0.1.0
|
||||
|
||||
## 0.0.10
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- e0b49e5: Update spinner so it actually spins
|
||||
|
||||
## 0.0.9
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Update README
|
||||
|
||||
## 0.0.8
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [9d371c3]
|
||||
- @clack/core@0.0.12
|
||||
|
||||
## 0.0.7
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Update README
|
||||
|
||||
## 0.0.6
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- d20ef2a: Update keywords, URLs
|
||||
- Updated dependencies [441d5b7]
|
||||
- Updated dependencies [d20ef2a]
|
||||
- Updated dependencies [fe13c2f]
|
||||
- @clack/core@0.0.11
|
||||
|
||||
## 0.0.5
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Update README
|
||||
|
||||
## 0.0.4
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 80404ab: Update README
|
||||
|
||||
## 0.0.3
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- a0cb382: Add `main` entrypoint
|
||||
- Updated dependencies [a0cb382]
|
||||
- @clack/core@0.0.10
|
||||
|
||||
## 0.0.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies
|
||||
- @clack/core@0.0.9
|
||||
|
||||
## 0.0.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- a4b5e13: Initial release
|
||||
- Updated dependencies [a4b5e13]
|
||||
- @clack/core@0.0.8
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) Nate Moore
|
||||
|
||||
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:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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.
|
||||
|
||||
---
|
||||
|
||||
`ansi-regex` is adapted from https://github.com/chalk/ansi-regex
|
||||
|
||||
MIT License
|
||||
|
||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
||||
|
||||
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:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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.
|
||||
+158
@@ -0,0 +1,158 @@
|
||||
# `@clack/prompts`
|
||||
|
||||
Effortlessly build beautiful command-line apps 🪄 [Try the demo](https://stackblitz.com/edit/clack-prompts?file=index.js)
|
||||
|
||||

|
||||
|
||||
---
|
||||
|
||||
`@clack/prompts` is an opinionated, pre-styled wrapper around [`@clack/core`](https://www.npmjs.com/package/@clack/core).
|
||||
|
||||
- 🤏 80% smaller than other options
|
||||
- 💎 Beautiful, minimal UI
|
||||
- ✅ Simple API
|
||||
- 🧱 Comes with `text`, `confirm`, `select`, `multiselect`, and `spinner` components
|
||||
|
||||
## Basics
|
||||
|
||||
### Setup
|
||||
|
||||
The `intro` and `outro` functions will print a message to begin or end a prompt session, respectively.
|
||||
|
||||
```js
|
||||
import { intro, outro } from '@clack/prompts';
|
||||
|
||||
intro(`create-my-app`);
|
||||
// Do stuff
|
||||
outro(`You're all set!`);
|
||||
```
|
||||
|
||||
### Cancellation
|
||||
|
||||
The `isCancel` function is a guard that detects when a user cancels a question with `CTRL + C`. You should handle this situation for each prompt, optionally providing a nice cancellation message with the `cancel` utility.
|
||||
|
||||
```js
|
||||
import { isCancel, cancel, text } from '@clack/prompts';
|
||||
|
||||
const value = await text(/* TODO */);
|
||||
|
||||
if (isCancel(value)) {
|
||||
cancel('Operation cancelled.');
|
||||
process.exit(0);
|
||||
}
|
||||
```
|
||||
|
||||
## Components
|
||||
|
||||
### Text
|
||||
|
||||
The text component accepts a single line of text.
|
||||
|
||||
```js
|
||||
import { text } from '@clack/prompts';
|
||||
|
||||
const meaning = await text({
|
||||
message: 'What is the meaning of life?',
|
||||
placeholder: 'Not sure',
|
||||
initialValue: '42',
|
||||
validate(value) {
|
||||
if (value.length === 0) return `Value is required!`;
|
||||
},
|
||||
});
|
||||
```
|
||||
|
||||
### Confirm
|
||||
|
||||
The confirm component accepts a yes or no answer. The result is a boolean value of `true` or `false`.
|
||||
|
||||
```js
|
||||
import { confirm } from '@clack/prompts';
|
||||
|
||||
const shouldContinue = await confirm({
|
||||
message: 'Do you want to continue?',
|
||||
});
|
||||
```
|
||||
|
||||
### Select
|
||||
|
||||
The select component allows a user to choose one value from a list of options. The result is the `value` prop of a given option.
|
||||
|
||||
```js
|
||||
import { select } from '@clack/prompts';
|
||||
|
||||
const projectType = await select({
|
||||
message: 'Pick a project type.',
|
||||
options: [
|
||||
{ value: 'ts', label: 'TypeScript' },
|
||||
{ value: 'js', label: 'JavaScript' },
|
||||
{ value: 'coffee', label: 'CoffeeScript', hint: 'oh no' },
|
||||
],
|
||||
});
|
||||
```
|
||||
|
||||
### Multi-Select
|
||||
|
||||
The `multiselect` component allows a user to choose many values from a list of options. The result is an array with all selected `value` props.
|
||||
|
||||
```js
|
||||
import { multiselect } from '@clack/prompts';
|
||||
|
||||
const additionalTools = await multiselect({
|
||||
message: 'Select additional tools.',
|
||||
options: [
|
||||
{ value: 'eslint', label: 'ESLint', hint: 'recommended' },
|
||||
{ value: 'prettier', label: 'Prettier' },
|
||||
{ value: 'gh-action', label: 'GitHub Action' },
|
||||
],
|
||||
required: false,
|
||||
});
|
||||
```
|
||||
|
||||
### Spinner
|
||||
|
||||
The spinner component surfaces a pending action, such as a long-running download or dependency installation.
|
||||
|
||||
```js
|
||||
import { spinner } from '@clack/prompts';
|
||||
|
||||
const s = spinner();
|
||||
s.start('Installing via npm');
|
||||
// Do installation
|
||||
s.stop('Installed via npm');
|
||||
```
|
||||
|
||||
## Utilities
|
||||
|
||||
### Grouping
|
||||
|
||||
Grouping prompts together is a great way to keep your code organized. This accepts a JSON object with a name that can be used to reference the group later. The second argument is an optional but has a `onCancel` callback that will be called if the user cancels one of the prompts in the group.
|
||||
|
||||
```js
|
||||
import * as p from '@clack/prompts';
|
||||
|
||||
const group = await p.group(
|
||||
{
|
||||
name: () => p.text({ message: 'What is your name?' }),
|
||||
age: () => p.text({ message: 'What is your age?' }),
|
||||
color: ({ results }) =>
|
||||
p.multiselect({
|
||||
message: `What is your favorite color ${results.name}?`,
|
||||
options: [
|
||||
{ value: 'red', label: 'Red' },
|
||||
{ value: 'green', label: 'Green' },
|
||||
{ value: 'blue', label: 'Blue' },
|
||||
],
|
||||
}),
|
||||
},
|
||||
{
|
||||
// On Cancel callback that wraps the group
|
||||
// So if the user cancels one of the prompts in the group this function will be called
|
||||
onCancel: ({ results }) => {
|
||||
p.cancel('Operation cancelled.');
|
||||
process.exit(0);
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
console.log(group.name, group.age, group.color);
|
||||
```
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
"use strict";const core=require("@clack/core"),process$1=require("node:process"),color=require("picocolors"),sisteransi=require("sisteransi");function isUnicodeSupported(){return process$1.platform!=="win32"?process$1.env.TERM!=="linux":Boolean(process$1.env.CI)||Boolean(process$1.env.WT_SESSION)||Boolean(process$1.env.TERMINUS_SUBLIME)||process$1.env.ConEmuTask==="{cmd::Cmder}"||process$1.env.TERM_PROGRAM==="Terminus-Sublime"||process$1.env.TERM_PROGRAM==="vscode"||process$1.env.TERM==="xterm-256color"||process$1.env.TERM==="alacritty"||process$1.env.TERMINAL_EMULATOR==="JetBrains-JediTerm"}const unicode=isUnicodeSupported(),s=(t,n)=>unicode?t:n,S_STEP_ACTIVE=s("\u25C6","*"),S_STEP_CANCEL=s("\u25A0","x"),S_STEP_ERROR=s("\u25B2","x"),S_STEP_SUBMIT=s("\u25C7","o"),S_BAR_START=s("\u250C","T"),S_BAR=s("\u2502","|"),S_BAR_END=s("\u2514","\u2014"),S_RADIO_ACTIVE=s("\u25CF",">"),S_RADIO_INACTIVE=s("\u25CB"," "),S_CHECKBOX_ACTIVE=s("\u25FB","[\u2022]"),S_CHECKBOX_SELECTED=s("\u25FC","[+]"),S_CHECKBOX_INACTIVE=s("\u25FB","[ ]"),S_PASSWORD_MASK=s("\u25AA","\u2022"),S_BAR_H=s("\u2500","-"),S_CORNER_TOP_RIGHT=s("\u256E","+"),S_CONNECT_LEFT=s("\u251C","+"),S_CORNER_BOTTOM_RIGHT=s("\u256F","+"),S_INFO=s("\u25CF","\u2022"),S_SUCCESS=s("\u25C6","*"),S_WARN=s("\u25B2","!"),S_ERROR=s("\u25A0","x"),symbol=t=>{switch(t){case"initial":case"active":return color.cyan(S_STEP_ACTIVE);case"cancel":return color.red(S_STEP_CANCEL);case"error":return color.yellow(S_STEP_ERROR);case"submit":return color.green(S_STEP_SUBMIT)}},text=t=>new core.TextPrompt({validate:t.validate,placeholder:t.placeholder,defaultValue:t.defaultValue,initialValue:t.initialValue,render(){const n=`${color.gray(S_BAR)}
|
||||
${symbol(this.state)} ${t.message}
|
||||
`,r=t.placeholder?color.inverse(t.placeholder[0])+color.dim(t.placeholder.slice(1)):color.inverse(color.hidden("_")),e=this.value?this.valueWithCursor:r;switch(this.state){case"error":return`${n.trim()}
|
||||
${color.yellow(S_BAR)} ${e}
|
||||
${color.yellow(S_BAR_END)} ${color.yellow(this.error)}
|
||||
`;case"submit":return`${n}${color.gray(S_BAR)} ${color.dim(this.value||t.placeholder)}`;case"cancel":return`${n}${color.gray(S_BAR)} ${color.strikethrough(color.dim(this.value??""))}${this.value?.trim()?`
|
||||
`+color.gray(S_BAR):""}`;default:return`${n}${color.cyan(S_BAR)} ${e}
|
||||
${color.cyan(S_BAR_END)}
|
||||
`}}}).prompt(),password=t=>new core.PasswordPrompt({validate:t.validate,mask:t.mask??S_PASSWORD_MASK,render(){const n=`${color.gray(S_BAR)}
|
||||
${symbol(this.state)} ${t.message}
|
||||
`,r=this.valueWithCursor,e=this.masked;switch(this.state){case"error":return`${n.trim()}
|
||||
${color.yellow(S_BAR)} ${e}
|
||||
${color.yellow(S_BAR_END)} ${color.yellow(this.error)}
|
||||
`;case"submit":return`${n}${color.gray(S_BAR)} ${color.dim(e)}`;case"cancel":return`${n}${color.gray(S_BAR)} ${color.strikethrough(color.dim(e??""))}${e?`
|
||||
`+color.gray(S_BAR):""}`;default:return`${n}${color.cyan(S_BAR)} ${r}
|
||||
${color.cyan(S_BAR_END)}
|
||||
`}}}).prompt(),confirm=t=>{const n=t.active??"Yes",r=t.inactive??"No";return new core.ConfirmPrompt({active:n,inactive:r,initialValue:t.initialValue??!0,render(){const e=`${color.gray(S_BAR)}
|
||||
${symbol(this.state)} ${t.message}
|
||||
`,i=this.value?n:r;switch(this.state){case"submit":return`${e}${color.gray(S_BAR)} ${color.dim(i)}`;case"cancel":return`${e}${color.gray(S_BAR)} ${color.strikethrough(color.dim(i))}
|
||||
${color.gray(S_BAR)}`;default:return`${e}${color.cyan(S_BAR)} ${this.value?`${color.green(S_RADIO_ACTIVE)} ${n}`:`${color.dim(S_RADIO_INACTIVE)} ${color.dim(n)}`} ${color.dim("/")} ${this.value?`${color.dim(S_RADIO_INACTIVE)} ${color.dim(r)}`:`${color.green(S_RADIO_ACTIVE)} ${r}`}
|
||||
${color.cyan(S_BAR_END)}
|
||||
`}}}).prompt()},select=t=>{const n=(r,e)=>{const i=r.label??String(r.value);return e==="active"?`${color.green(S_RADIO_ACTIVE)} ${i} ${r.hint?color.dim(`(${r.hint})`):""}`:e==="selected"?`${color.dim(i)}`:e==="cancelled"?`${color.strikethrough(color.dim(i))}`:`${color.dim(S_RADIO_INACTIVE)} ${color.dim(i)}`};return new core.SelectPrompt({options:t.options,initialValue:t.initialValue,render(){const r=`${color.gray(S_BAR)}
|
||||
${symbol(this.state)} ${t.message}
|
||||
`;switch(this.state){case"submit":return`${r}${color.gray(S_BAR)} ${n(this.options[this.cursor],"selected")}`;case"cancel":return`${r}${color.gray(S_BAR)} ${n(this.options[this.cursor],"cancelled")}
|
||||
${color.gray(S_BAR)}`;default:return`${r}${color.cyan(S_BAR)} ${this.options.map((e,i)=>n(e,i===this.cursor?"active":"inactive")).join(`
|
||||
${color.cyan(S_BAR)} `)}
|
||||
${color.cyan(S_BAR_END)}
|
||||
`}}}).prompt()},selectKey=t=>{const n=(r,e="inactive")=>{const i=r.label??String(r.value);return e==="selected"?`${color.dim(i)}`:e==="cancelled"?`${color.strikethrough(color.dim(i))}`:e==="active"?`${color.bgCyan(color.gray(` ${r.value} `))} ${i} ${r.hint?color.dim(`(${r.hint})`):""}`:`${color.gray(color.bgWhite(color.inverse(` ${r.value} `)))} ${i} ${r.hint?color.dim(`(${r.hint})`):""}`};return new core.SelectKeyPrompt({options:t.options,initialValue:t.initialValue,render(){const r=`${color.gray(S_BAR)}
|
||||
${symbol(this.state)} ${t.message}
|
||||
`;switch(this.state){case"submit":return`${r}${color.gray(S_BAR)} ${n(this.options.find(e=>e.value===this.value),"selected")}`;case"cancel":return`${r}${color.gray(S_BAR)} ${n(this.options[0],"cancelled")}
|
||||
${color.gray(S_BAR)}`;default:return`${r}${color.cyan(S_BAR)} ${this.options.map((e,i)=>n(e,i===this.cursor?"active":"inactive")).join(`
|
||||
${color.cyan(S_BAR)} `)}
|
||||
${color.cyan(S_BAR_END)}
|
||||
`}}}).prompt()},multiselect=t=>{const n=(r,e)=>{const i=r.label??String(r.value);return e==="active"?`${color.cyan(S_CHECKBOX_ACTIVE)} ${i} ${r.hint?color.dim(`(${r.hint})`):""}`:e==="selected"?`${color.green(S_CHECKBOX_SELECTED)} ${color.dim(i)}`:e==="cancelled"?`${color.strikethrough(color.dim(i))}`:e==="active-selected"?`${color.green(S_CHECKBOX_SELECTED)} ${i} ${r.hint?color.dim(`(${r.hint})`):""}`:e==="submitted"?`${color.dim(i)}`:`${color.dim(S_CHECKBOX_INACTIVE)} ${color.dim(i)}`};return new core.MultiSelectPrompt({options:t.options,initialValues:t.initialValues,required:t.required??!0,cursorAt:t.cursorAt,validate(r){if(this.required&&r.length===0)return`Please select at least one option.
|
||||
${color.reset(color.dim(`Press ${color.gray(color.bgWhite(color.inverse(" space ")))} to select, ${color.gray(color.bgWhite(color.inverse(" enter ")))} to submit`))}`},render(){let r=`${color.gray(S_BAR)}
|
||||
${symbol(this.state)} ${t.message}
|
||||
`;switch(this.state){case"submit":return`${r}${color.gray(S_BAR)} ${this.options.filter(({value:e})=>this.value.includes(e)).map(e=>n(e,"submitted")).join(color.dim(", "))||color.dim("none")}`;case"cancel":{const e=this.options.filter(({value:i})=>this.value.includes(i)).map(i=>n(i,"cancelled")).join(color.dim(", "));return`${r}${color.gray(S_BAR)} ${e.trim()?`${e}
|
||||
${color.gray(S_BAR)}`:""}`}case"error":{const e=this.error.split(`
|
||||
`).map((i,c)=>c===0?`${color.yellow(S_BAR_END)} ${color.yellow(i)}`:` ${i}`).join(`
|
||||
`);return r+color.yellow(S_BAR)+" "+this.options.map((i,c)=>{const a=this.value.includes(i.value),l=c===this.cursor;return l&&a?n(i,"active-selected"):a?n(i,"selected"):n(i,l?"active":"inactive")}).join(`
|
||||
${color.yellow(S_BAR)} `)+`
|
||||
`+e+`
|
||||
`}default:return`${r}${color.cyan(S_BAR)} ${this.options.map((e,i)=>{const c=this.value.includes(e.value),a=i===this.cursor;return a&&c?n(e,"active-selected"):c?n(e,"selected"):n(e,a?"active":"inactive")}).join(`
|
||||
${color.cyan(S_BAR)} `)}
|
||||
${color.cyan(S_BAR_END)}
|
||||
`}}}).prompt()},groupMultiselect=t=>{const n=(r,e,i=[])=>{const c=r.label??String(r.value),a=typeof r.group=="string",l=a&&(i[i.indexOf(r)+1]??{group:!0}),o=a&&l.group===!0,u=a?`${o?S_BAR_END:S_BAR} `:"";return e==="active"?`${color.dim(u)}${color.cyan(S_CHECKBOX_ACTIVE)} ${c} ${r.hint?color.dim(`(${r.hint})`):""}`:e==="group-active"?`${u}${color.cyan(S_CHECKBOX_ACTIVE)} ${color.dim(c)}`:e==="group-active-selected"?`${u}${color.green(S_CHECKBOX_SELECTED)} ${color.dim(c)}`:e==="selected"?`${color.dim(u)}${color.green(S_CHECKBOX_SELECTED)} ${color.dim(c)}`:e==="cancelled"?`${color.strikethrough(color.dim(c))}`:e==="active-selected"?`${color.dim(u)}${color.green(S_CHECKBOX_SELECTED)} ${c} ${r.hint?color.dim(`(${r.hint})`):""}`:e==="submitted"?`${color.dim(c)}`:`${color.dim(u)}${color.dim(S_CHECKBOX_INACTIVE)} ${color.dim(c)}`};return new core.GroupMultiSelectPrompt({options:t.options,initialValues:t.initialValues,required:t.required??!0,cursorAt:t.cursorAt,validate(r){if(this.required&&r.length===0)return`Please select at least one option.
|
||||
${color.reset(color.dim(`Press ${color.gray(color.bgWhite(color.inverse(" space ")))} to select, ${color.gray(color.bgWhite(color.inverse(" enter ")))} to submit`))}`},render(){let r=`${color.gray(S_BAR)}
|
||||
${symbol(this.state)} ${t.message}
|
||||
`;switch(this.state){case"submit":return`${r}${color.gray(S_BAR)} ${this.options.filter(({value:e})=>this.value.includes(e)).map(e=>n(e,"submitted")).join(color.dim(", "))}`;case"cancel":{const e=this.options.filter(({value:i})=>this.value.includes(i)).map(i=>n(i,"cancelled")).join(color.dim(", "));return`${r}${color.gray(S_BAR)} ${e.trim()?`${e}
|
||||
${color.gray(S_BAR)}`:""}`}case"error":{const e=this.error.split(`
|
||||
`).map((i,c)=>c===0?`${color.yellow(S_BAR_END)} ${color.yellow(i)}`:` ${i}`).join(`
|
||||
`);return`${r}${color.yellow(S_BAR)} ${this.options.map((i,c,a)=>{const l=this.value.includes(i.value)||i.group===!0&&this.isGroupSelected(`${i.value}`),o=c===this.cursor;return!o&&typeof i.group=="string"&&this.options[this.cursor].value===i.group?n(i,l?"group-active-selected":"group-active",a):o&&l?n(i,"active-selected",a):l?n(i,"selected",a):n(i,o?"active":"inactive",a)}).join(`
|
||||
${color.yellow(S_BAR)} `)}
|
||||
${e}
|
||||
`}default:return`${r}${color.cyan(S_BAR)} ${this.options.map((e,i,c)=>{const a=this.value.includes(e.value)||e.group===!0&&this.isGroupSelected(`${e.value}`),l=i===this.cursor;return!l&&typeof e.group=="string"&&this.options[this.cursor].value===e.group?n(e,a?"group-active-selected":"group-active",c):l&&a?n(e,"active-selected",c):a?n(e,"selected",c):n(e,l?"active":"inactive",c)}).join(`
|
||||
${color.cyan(S_BAR)} `)}
|
||||
${color.cyan(S_BAR_END)}
|
||||
`}}}).prompt()},strip=t=>t.replace(ansiRegex(),""),note=(t="",n="")=>{const r=`
|
||||
${t}
|
||||
`.split(`
|
||||
`),e=Math.max(r.reduce((c,a)=>(a=strip(a),a.length>c?a.length:c),0),strip(n).length)+2,i=r.map(c=>`${color.gray(S_BAR)} ${color.dim(c)}${" ".repeat(e-strip(c).length)}${color.gray(S_BAR)}`).join(`
|
||||
`);process.stdout.write(`${color.gray(S_BAR)}
|
||||
${color.green(S_STEP_SUBMIT)} ${color.reset(n)} ${color.gray(S_BAR_H.repeat(Math.max(e-n.length-1,1))+S_CORNER_TOP_RIGHT)}
|
||||
${i}
|
||||
${color.gray(S_CONNECT_LEFT+S_BAR_H.repeat(e+2)+S_CORNER_BOTTOM_RIGHT)}
|
||||
`)},cancel=(t="")=>{process.stdout.write(`${color.gray(S_BAR_END)} ${color.red(t)}
|
||||
|
||||
`)},intro=(t="")=>{process.stdout.write(`${color.gray(S_BAR_START)} ${t}
|
||||
`)},outro=(t="")=>{process.stdout.write(`${color.gray(S_BAR)}
|
||||
${color.gray(S_BAR_END)} ${t}
|
||||
|
||||
`)},log={message:(t="",{symbol:n=color.gray(S_BAR)}={})=>{const r=[`${color.gray(S_BAR)}`];if(t){const[e,...i]=t.split(`
|
||||
`);r.push(`${n} ${e}`,...i.map(c=>`${color.gray(S_BAR)} ${c}`))}process.stdout.write(`${r.join(`
|
||||
`)}
|
||||
`)},info:t=>{log.message(t,{symbol:color.blue(S_INFO)})},success:t=>{log.message(t,{symbol:color.green(S_SUCCESS)})},step:t=>{log.message(t,{symbol:color.green(S_STEP_SUBMIT)})},warn:t=>{log.message(t,{symbol:color.yellow(S_WARN)})},warning:t=>{log.warn(t)},error:t=>{log.message(t,{symbol:color.red(S_ERROR)})}},frames=unicode?["\u25D2","\u25D0","\u25D3","\u25D1"]:["\u2022","o","O","0"],spinner=()=>{let t,n;const r=unicode?80:120;return{start(e=""){e=e.replace(/\.?\.?\.$/,""),t=core.block(),process.stdout.write(`${color.gray(S_BAR)}
|
||||
${color.magenta("\u25CB")} ${e}
|
||||
`);let i=0,c=0;n=setInterval(()=>{let a=frames[i];process.stdout.write(sisteransi.cursor.move(-999,-1)),process.stdout.write(`${color.magenta(a)} ${e}${Math.floor(c)>=1?".".repeat(Math.floor(c)).slice(0,3):""}
|
||||
`),i=i===frames.length-1?0:i+1,c=c===frames.length?0:c+.125},r)},stop(e=""){process.stdout.write(sisteransi.cursor.move(-999,-2)),process.stdout.write(sisteransi.erase.down(2)),clearInterval(n),process.stdout.write(`${color.gray(S_BAR)}
|
||||
${color.green(S_STEP_SUBMIT)} ${e}
|
||||
`),t()}}};function ansiRegex(){const t=["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)","(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))"].join("|");return new RegExp(t,"g")}const group=async(t,n)=>{const r={},e=Object.keys(t);for(const i of e){const c=t[i],a=await c({results:r})?.catch(l=>{throw l});if(typeof n?.onCancel=="function"&&core.isCancel(a)){r[i]="canceled",n.onCancel({results:r});continue}r[i]=a}return r};exports.isCancel=core.isCancel,exports.cancel=cancel,exports.confirm=confirm,exports.group=group,exports.groupMultiselect=groupMultiselect,exports.intro=intro,exports.log=log,exports.multiselect=multiselect,exports.note=note,exports.outro=outro,exports.password=password,exports.select=select,exports.selectKey=selectKey,exports.spinner=spinner,exports.text=text;
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
export { isCancel } from '@clack/core';
|
||||
|
||||
interface TextOptions {
|
||||
message: string;
|
||||
placeholder?: string;
|
||||
defaultValue?: string;
|
||||
initialValue?: string;
|
||||
validate?: (value: string) => string | void;
|
||||
}
|
||||
declare const text: (opts: TextOptions) => Promise<string | symbol>;
|
||||
interface PasswordOptions {
|
||||
message: string;
|
||||
mask?: string;
|
||||
validate?: (value: string) => string | void;
|
||||
}
|
||||
declare const password: (opts: PasswordOptions) => Promise<string | symbol>;
|
||||
interface ConfirmOptions {
|
||||
message: string;
|
||||
active?: string;
|
||||
inactive?: string;
|
||||
initialValue?: boolean;
|
||||
}
|
||||
declare const confirm: (opts: ConfirmOptions) => Promise<boolean | symbol>;
|
||||
type Primitive = Readonly<string | boolean | number>;
|
||||
type Option<Value> = Value extends Primitive ? {
|
||||
value: Value;
|
||||
label?: string;
|
||||
hint?: string;
|
||||
} : {
|
||||
value: Value;
|
||||
label: string;
|
||||
hint?: string;
|
||||
};
|
||||
interface SelectOptions<Options extends Option<Value>[], Value> {
|
||||
message: string;
|
||||
options: Options;
|
||||
initialValue?: Value;
|
||||
}
|
||||
declare const select: <Options extends Option<Value>[], Value>(opts: SelectOptions<Options, Value>) => Promise<symbol | Value>;
|
||||
declare const selectKey: <Options extends Option<Value>[], Value extends string>(opts: SelectOptions<Options, Value>) => Promise<symbol | Value>;
|
||||
interface MultiSelectOptions<Options extends Option<Value>[], Value> {
|
||||
message: string;
|
||||
options: Options;
|
||||
initialValues?: Value[];
|
||||
required?: boolean;
|
||||
cursorAt?: Value;
|
||||
}
|
||||
declare const multiselect: <Options extends Option<Value>[], Value>(opts: MultiSelectOptions<Options, Value>) => Promise<symbol | Value[]>;
|
||||
interface GroupMultiSelectOptions<Options extends Option<Value>[], Value> {
|
||||
message: string;
|
||||
options: Record<string, Options>;
|
||||
initialValues?: Value[];
|
||||
required?: boolean;
|
||||
cursorAt?: Value;
|
||||
}
|
||||
declare const groupMultiselect: <Options extends Option<Value>[], Value>(opts: GroupMultiSelectOptions<Options, Value>) => Promise<symbol | Value[]>;
|
||||
declare const note: (message?: string, title?: string) => void;
|
||||
declare const cancel: (message?: string) => void;
|
||||
declare const intro: (title?: string) => void;
|
||||
declare const outro: (message?: string) => void;
|
||||
type LogMessageOptions = {
|
||||
symbol?: string;
|
||||
};
|
||||
declare const log: {
|
||||
message: (message?: string, { symbol }?: LogMessageOptions) => void;
|
||||
info: (message: string) => void;
|
||||
success: (message: string) => void;
|
||||
step: (message: string) => void;
|
||||
warn: (message: string) => void;
|
||||
/** alias for `log.warn()`. */
|
||||
warning: (message: string) => void;
|
||||
error: (message: string) => void;
|
||||
};
|
||||
declare const spinner: () => {
|
||||
start(message?: string): void;
|
||||
stop(message?: string): void;
|
||||
};
|
||||
type PromptGroupAwaitedReturn<T> = {
|
||||
[P in keyof T]: Exclude<Awaited<T[P]>, symbol>;
|
||||
};
|
||||
interface PromptGroupOptions<T> {
|
||||
/**
|
||||
* Control how the group can be canceld
|
||||
* if one of the prompts is canceld.
|
||||
*/
|
||||
onCancel?: (opts: {
|
||||
results: Partial<PromptGroupAwaitedReturn<T>>;
|
||||
}) => void;
|
||||
}
|
||||
type PromptGroup<T> = {
|
||||
[P in keyof T]: (opts: {
|
||||
results: Partial<PromptGroupAwaitedReturn<T>>;
|
||||
}) => void | Promise<T[P] | void>;
|
||||
};
|
||||
/**
|
||||
* Define a group of prompts to be displayed
|
||||
* and return a results of objects within the group
|
||||
*/
|
||||
declare const group: <T>(prompts: PromptGroup<T>, opts?: PromptGroupOptions<T> | undefined) => Promise<PromptGroupAwaitedReturn<T>>;
|
||||
|
||||
export { ConfirmOptions, GroupMultiSelectOptions, LogMessageOptions, MultiSelectOptions, PasswordOptions, PromptGroup, PromptGroupAwaitedReturn, PromptGroupOptions, SelectOptions, TextOptions, cancel, confirm, group, groupMultiselect, intro, log, multiselect, note, outro, password, select, selectKey, spinner, text };
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
import{TextPrompt as T,PasswordPrompt as B,ConfirmPrompt as O,SelectPrompt as I,SelectKeyPrompt as M,MultiSelectPrompt as P,GroupMultiSelectPrompt as V,block as j,isCancel as x}from"@clack/core";export{isCancel}from"@clack/core";import d from"node:process";import e from"picocolors";import{cursor as E,erase as k}from"sisteransi";function N(){return d.platform!=="win32"?d.env.TERM!=="linux":Boolean(d.env.CI)||Boolean(d.env.WT_SESSION)||Boolean(d.env.TERMINUS_SUBLIME)||d.env.ConEmuTask==="{cmd::Cmder}"||d.env.TERM_PROGRAM==="Terminus-Sublime"||d.env.TERM_PROGRAM==="vscode"||d.env.TERM==="xterm-256color"||d.env.TERM==="alacritty"||d.env.TERMINAL_EMULATOR==="JetBrains-JediTerm"}const p=N(),u=(r,n)=>p?r:n,W=u("\u25C6","*"),D=u("\u25A0","x"),F=u("\u25B2","x"),f=u("\u25C7","o"),L=u("\u250C","T"),a=u("\u2502","|"),o=u("\u2514","\u2014"),w=u("\u25CF",">"),S=u("\u25CB"," "),_=u("\u25FB","[\u2022]"),y=u("\u25FC","[+]"),A=u("\u25FB","[ ]"),q=u("\u25AA","\u2022"),R=u("\u2500","-"),G=u("\u256E","+"),H=u("\u251C","+"),K=u("\u256F","+"),U=u("\u25CF","\u2022"),Z=u("\u25C6","*"),z=u("\u25B2","!"),X=u("\u25A0","x"),h=r=>{switch(r){case"initial":case"active":return e.cyan(W);case"cancel":return e.red(D);case"error":return e.yellow(F);case"submit":return e.green(f)}},J=r=>new T({validate:r.validate,placeholder:r.placeholder,defaultValue:r.defaultValue,initialValue:r.initialValue,render(){const n=`${e.gray(a)}
|
||||
${h(this.state)} ${r.message}
|
||||
`,s=r.placeholder?e.inverse(r.placeholder[0])+e.dim(r.placeholder.slice(1)):e.inverse(e.hidden("_")),t=this.value?this.valueWithCursor:s;switch(this.state){case"error":return`${n.trim()}
|
||||
${e.yellow(a)} ${t}
|
||||
${e.yellow(o)} ${e.yellow(this.error)}
|
||||
`;case"submit":return`${n}${e.gray(a)} ${e.dim(this.value||r.placeholder)}`;case"cancel":return`${n}${e.gray(a)} ${e.strikethrough(e.dim(this.value??""))}${this.value?.trim()?`
|
||||
`+e.gray(a):""}`;default:return`${n}${e.cyan(a)} ${t}
|
||||
${e.cyan(o)}
|
||||
`}}}).prompt(),Y=r=>new B({validate:r.validate,mask:r.mask??q,render(){const n=`${e.gray(a)}
|
||||
${h(this.state)} ${r.message}
|
||||
`,s=this.valueWithCursor,t=this.masked;switch(this.state){case"error":return`${n.trim()}
|
||||
${e.yellow(a)} ${t}
|
||||
${e.yellow(o)} ${e.yellow(this.error)}
|
||||
`;case"submit":return`${n}${e.gray(a)} ${e.dim(t)}`;case"cancel":return`${n}${e.gray(a)} ${e.strikethrough(e.dim(t??""))}${t?`
|
||||
`+e.gray(a):""}`;default:return`${n}${e.cyan(a)} ${s}
|
||||
${e.cyan(o)}
|
||||
`}}}).prompt(),Q=r=>{const n=r.active??"Yes",s=r.inactive??"No";return new O({active:n,inactive:s,initialValue:r.initialValue??!0,render(){const t=`${e.gray(a)}
|
||||
${h(this.state)} ${r.message}
|
||||
`,i=this.value?n:s;switch(this.state){case"submit":return`${t}${e.gray(a)} ${e.dim(i)}`;case"cancel":return`${t}${e.gray(a)} ${e.strikethrough(e.dim(i))}
|
||||
${e.gray(a)}`;default:return`${t}${e.cyan(a)} ${this.value?`${e.green(w)} ${n}`:`${e.dim(S)} ${e.dim(n)}`} ${e.dim("/")} ${this.value?`${e.dim(S)} ${e.dim(s)}`:`${e.green(w)} ${s}`}
|
||||
${e.cyan(o)}
|
||||
`}}}).prompt()},ee=r=>{const n=(s,t)=>{const i=s.label??String(s.value);return t==="active"?`${e.green(w)} ${i} ${s.hint?e.dim(`(${s.hint})`):""}`:t==="selected"?`${e.dim(i)}`:t==="cancelled"?`${e.strikethrough(e.dim(i))}`:`${e.dim(S)} ${e.dim(i)}`};return new I({options:r.options,initialValue:r.initialValue,render(){const s=`${e.gray(a)}
|
||||
${h(this.state)} ${r.message}
|
||||
`;switch(this.state){case"submit":return`${s}${e.gray(a)} ${n(this.options[this.cursor],"selected")}`;case"cancel":return`${s}${e.gray(a)} ${n(this.options[this.cursor],"cancelled")}
|
||||
${e.gray(a)}`;default:return`${s}${e.cyan(a)} ${this.options.map((t,i)=>n(t,i===this.cursor?"active":"inactive")).join(`
|
||||
${e.cyan(a)} `)}
|
||||
${e.cyan(o)}
|
||||
`}}}).prompt()},te=r=>{const n=(s,t="inactive")=>{const i=s.label??String(s.value);return t==="selected"?`${e.dim(i)}`:t==="cancelled"?`${e.strikethrough(e.dim(i))}`:t==="active"?`${e.bgCyan(e.gray(` ${s.value} `))} ${i} ${s.hint?e.dim(`(${s.hint})`):""}`:`${e.gray(e.bgWhite(e.inverse(` ${s.value} `)))} ${i} ${s.hint?e.dim(`(${s.hint})`):""}`};return new M({options:r.options,initialValue:r.initialValue,render(){const s=`${e.gray(a)}
|
||||
${h(this.state)} ${r.message}
|
||||
`;switch(this.state){case"submit":return`${s}${e.gray(a)} ${n(this.options.find(t=>t.value===this.value),"selected")}`;case"cancel":return`${s}${e.gray(a)} ${n(this.options[0],"cancelled")}
|
||||
${e.gray(a)}`;default:return`${s}${e.cyan(a)} ${this.options.map((t,i)=>n(t,i===this.cursor?"active":"inactive")).join(`
|
||||
${e.cyan(a)} `)}
|
||||
${e.cyan(o)}
|
||||
`}}}).prompt()},re=r=>{const n=(s,t)=>{const i=s.label??String(s.value);return t==="active"?`${e.cyan(_)} ${i} ${s.hint?e.dim(`(${s.hint})`):""}`:t==="selected"?`${e.green(y)} ${e.dim(i)}`:t==="cancelled"?`${e.strikethrough(e.dim(i))}`:t==="active-selected"?`${e.green(y)} ${i} ${s.hint?e.dim(`(${s.hint})`):""}`:t==="submitted"?`${e.dim(i)}`:`${e.dim(A)} ${e.dim(i)}`};return new P({options:r.options,initialValues:r.initialValues,required:r.required??!0,cursorAt:r.cursorAt,validate(s){if(this.required&&s.length===0)return`Please select at least one option.
|
||||
${e.reset(e.dim(`Press ${e.gray(e.bgWhite(e.inverse(" space ")))} to select, ${e.gray(e.bgWhite(e.inverse(" enter ")))} to submit`))}`},render(){let s=`${e.gray(a)}
|
||||
${h(this.state)} ${r.message}
|
||||
`;switch(this.state){case"submit":return`${s}${e.gray(a)} ${this.options.filter(({value:t})=>this.value.includes(t)).map(t=>n(t,"submitted")).join(e.dim(", "))||e.dim("none")}`;case"cancel":{const t=this.options.filter(({value:i})=>this.value.includes(i)).map(i=>n(i,"cancelled")).join(e.dim(", "));return`${s}${e.gray(a)} ${t.trim()?`${t}
|
||||
${e.gray(a)}`:""}`}case"error":{const t=this.error.split(`
|
||||
`).map((i,c)=>c===0?`${e.yellow(o)} ${e.yellow(i)}`:` ${i}`).join(`
|
||||
`);return s+e.yellow(a)+" "+this.options.map((i,c)=>{const l=this.value.includes(i.value),$=c===this.cursor;return $&&l?n(i,"active-selected"):l?n(i,"selected"):n(i,$?"active":"inactive")}).join(`
|
||||
${e.yellow(a)} `)+`
|
||||
`+t+`
|
||||
`}default:return`${s}${e.cyan(a)} ${this.options.map((t,i)=>{const c=this.value.includes(t.value),l=i===this.cursor;return l&&c?n(t,"active-selected"):c?n(t,"selected"):n(t,l?"active":"inactive")}).join(`
|
||||
${e.cyan(a)} `)}
|
||||
${e.cyan(o)}
|
||||
`}}}).prompt()},se=r=>{const n=(s,t,i=[])=>{const c=s.label??String(s.value),l=typeof s.group=="string",$=l&&(i[i.indexOf(s)+1]??{group:!0}),v=l&&$.group===!0,m=l?`${v?o:a} `:"";return t==="active"?`${e.dim(m)}${e.cyan(_)} ${c} ${s.hint?e.dim(`(${s.hint})`):""}`:t==="group-active"?`${m}${e.cyan(_)} ${e.dim(c)}`:t==="group-active-selected"?`${m}${e.green(y)} ${e.dim(c)}`:t==="selected"?`${e.dim(m)}${e.green(y)} ${e.dim(c)}`:t==="cancelled"?`${e.strikethrough(e.dim(c))}`:t==="active-selected"?`${e.dim(m)}${e.green(y)} ${c} ${s.hint?e.dim(`(${s.hint})`):""}`:t==="submitted"?`${e.dim(c)}`:`${e.dim(m)}${e.dim(A)} ${e.dim(c)}`};return new V({options:r.options,initialValues:r.initialValues,required:r.required??!0,cursorAt:r.cursorAt,validate(s){if(this.required&&s.length===0)return`Please select at least one option.
|
||||
${e.reset(e.dim(`Press ${e.gray(e.bgWhite(e.inverse(" space ")))} to select, ${e.gray(e.bgWhite(e.inverse(" enter ")))} to submit`))}`},render(){let s=`${e.gray(a)}
|
||||
${h(this.state)} ${r.message}
|
||||
`;switch(this.state){case"submit":return`${s}${e.gray(a)} ${this.options.filter(({value:t})=>this.value.includes(t)).map(t=>n(t,"submitted")).join(e.dim(", "))}`;case"cancel":{const t=this.options.filter(({value:i})=>this.value.includes(i)).map(i=>n(i,"cancelled")).join(e.dim(", "));return`${s}${e.gray(a)} ${t.trim()?`${t}
|
||||
${e.gray(a)}`:""}`}case"error":{const t=this.error.split(`
|
||||
`).map((i,c)=>c===0?`${e.yellow(o)} ${e.yellow(i)}`:` ${i}`).join(`
|
||||
`);return`${s}${e.yellow(a)} ${this.options.map((i,c,l)=>{const $=this.value.includes(i.value)||i.group===!0&&this.isGroupSelected(`${i.value}`),v=c===this.cursor;return!v&&typeof i.group=="string"&&this.options[this.cursor].value===i.group?n(i,$?"group-active-selected":"group-active",l):v&&$?n(i,"active-selected",l):$?n(i,"selected",l):n(i,v?"active":"inactive",l)}).join(`
|
||||
${e.yellow(a)} `)}
|
||||
${t}
|
||||
`}default:return`${s}${e.cyan(a)} ${this.options.map((t,i,c)=>{const l=this.value.includes(t.value)||t.group===!0&&this.isGroupSelected(`${t.value}`),$=i===this.cursor;return!$&&typeof t.group=="string"&&this.options[this.cursor].value===t.group?n(t,l?"group-active-selected":"group-active",c):$&&l?n(t,"active-selected",c):l?n(t,"selected",c):n(t,$?"active":"inactive",c)}).join(`
|
||||
${e.cyan(a)} `)}
|
||||
${e.cyan(o)}
|
||||
`}}}).prompt()},b=r=>r.replace(ue(),""),ie=(r="",n="")=>{const s=`
|
||||
${r}
|
||||
`.split(`
|
||||
`),t=Math.max(s.reduce((c,l)=>(l=b(l),l.length>c?l.length:c),0),b(n).length)+2,i=s.map(c=>`${e.gray(a)} ${e.dim(c)}${" ".repeat(t-b(c).length)}${e.gray(a)}`).join(`
|
||||
`);process.stdout.write(`${e.gray(a)}
|
||||
${e.green(f)} ${e.reset(n)} ${e.gray(R.repeat(Math.max(t-n.length-1,1))+G)}
|
||||
${i}
|
||||
${e.gray(H+R.repeat(t+2)+K)}
|
||||
`)},ne=(r="")=>{process.stdout.write(`${e.gray(o)} ${e.red(r)}
|
||||
|
||||
`)},ae=(r="")=>{process.stdout.write(`${e.gray(L)} ${r}
|
||||
`)},ce=(r="")=>{process.stdout.write(`${e.gray(a)}
|
||||
${e.gray(o)} ${r}
|
||||
|
||||
`)},g={message:(r="",{symbol:n=e.gray(a)}={})=>{const s=[`${e.gray(a)}`];if(r){const[t,...i]=r.split(`
|
||||
`);s.push(`${n} ${t}`,...i.map(c=>`${e.gray(a)} ${c}`))}process.stdout.write(`${s.join(`
|
||||
`)}
|
||||
`)},info:r=>{g.message(r,{symbol:e.blue(U)})},success:r=>{g.message(r,{symbol:e.green(Z)})},step:r=>{g.message(r,{symbol:e.green(f)})},warn:r=>{g.message(r,{symbol:e.yellow(z)})},warning:r=>{g.warn(r)},error:r=>{g.message(r,{symbol:e.red(X)})}},C=p?["\u25D2","\u25D0","\u25D3","\u25D1"]:["\u2022","o","O","0"],le=()=>{let r,n;const s=p?80:120;return{start(t=""){t=t.replace(/\.?\.?\.$/,""),r=j(),process.stdout.write(`${e.gray(a)}
|
||||
${e.magenta("\u25CB")} ${t}
|
||||
`);let i=0,c=0;n=setInterval(()=>{let l=C[i];process.stdout.write(E.move(-999,-1)),process.stdout.write(`${e.magenta(l)} ${t}${Math.floor(c)>=1?".".repeat(Math.floor(c)).slice(0,3):""}
|
||||
`),i=i===C.length-1?0:i+1,c=c===C.length?0:c+.125},s)},stop(t=""){process.stdout.write(E.move(-999,-2)),process.stdout.write(k.down(2)),clearInterval(n),process.stdout.write(`${e.gray(a)}
|
||||
${e.green(f)} ${t}
|
||||
`),r()}}};function ue(){const r=["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)","(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))"].join("|");return new RegExp(r,"g")}const $e=async(r,n)=>{const s={},t=Object.keys(r);for(const i of t){const c=r[i],l=await c({results:s})?.catch($=>{throw $});if(typeof n?.onCancel=="function"&&x(l)){s[i]="canceled",n.onCancel({results:s});continue}s[i]=l}return s};export{ne as cancel,Q as confirm,$e as group,se as groupMultiselect,ae as intro,g as log,re as multiselect,ie as note,ce as outro,Y as password,ee as select,te as selectKey,le as spinner,J as text};
|
||||
Generated
Vendored
+12
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
Detect whether the terminal supports Unicode.
|
||||
|
||||
@example
|
||||
```
|
||||
import isUnicodeSupported from 'is-unicode-supported';
|
||||
|
||||
isUnicodeSupported();
|
||||
//=> true
|
||||
```
|
||||
*/
|
||||
export default function isUnicodeSupported(): boolean;
|
||||
Generated
Vendored
+17
@@ -0,0 +1,17 @@
|
||||
import process from 'node:process';
|
||||
|
||||
export default function isUnicodeSupported() {
|
||||
if (process.platform !== 'win32') {
|
||||
return process.env.TERM !== 'linux'; // Linux console (kernel)
|
||||
}
|
||||
|
||||
return Boolean(process.env.CI)
|
||||
|| Boolean(process.env.WT_SESSION) // Windows Terminal
|
||||
|| Boolean(process.env.TERMINUS_SUBLIME) // Terminus (<0.2.27)
|
||||
|| process.env.ConEmuTask === '{cmd::Cmder}' // ConEmu and cmder
|
||||
|| process.env.TERM_PROGRAM === 'Terminus-Sublime'
|
||||
|| process.env.TERM_PROGRAM === 'vscode'
|
||||
|| process.env.TERM === 'xterm-256color'
|
||||
|| process.env.TERM === 'alacritty'
|
||||
|| process.env.TERMINAL_EMULATOR === 'JetBrains-JediTerm';
|
||||
}
|
||||
Generated
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
||||
|
||||
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:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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.
|
||||
Generated
Vendored
+43
@@ -0,0 +1,43 @@
|
||||
{
|
||||
"name": "is-unicode-supported",
|
||||
"version": "1.3.0",
|
||||
"description": "Detect whether the terminal supports Unicode",
|
||||
"license": "MIT",
|
||||
"repository": "sindresorhus/is-unicode-supported",
|
||||
"funding": "https://github.com/sponsors/sindresorhus",
|
||||
"author": {
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "https://sindresorhus.com"
|
||||
},
|
||||
"type": "module",
|
||||
"exports": "./index.js",
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && ava && tsd"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"index.d.ts"
|
||||
],
|
||||
"keywords": [
|
||||
"terminal",
|
||||
"unicode",
|
||||
"detect",
|
||||
"utf8",
|
||||
"console",
|
||||
"shell",
|
||||
"support",
|
||||
"supports",
|
||||
"supported",
|
||||
"check",
|
||||
"detection"
|
||||
],
|
||||
"devDependencies": {
|
||||
"ava": "^4.0.1",
|
||||
"tsd": "^0.19.1",
|
||||
"xo": "^0.47.0"
|
||||
}
|
||||
}
|
||||
Generated
Vendored
+35
@@ -0,0 +1,35 @@
|
||||
# is-unicode-supported
|
||||
|
||||
> Detect whether the terminal supports Unicode
|
||||
|
||||
This can be useful to decide whether to use Unicode characters or fallback ASCII characters in command-line output.
|
||||
|
||||
Note that the check is quite naive. It just assumes all non-Windows terminals support Unicode and hard-codes which Windows terminals that do support Unicode. However, I have been using this logic in some popular packages for years without problems.
|
||||
|
||||
## Install
|
||||
|
||||
```sh
|
||||
npm install is-unicode-supported
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
import isUnicodeSupported from 'is-unicode-supported';
|
||||
|
||||
isUnicodeSupported();
|
||||
//=> true
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### isUnicodeSupported()
|
||||
|
||||
Returns a `boolean` for whether the terminal supports Unicode.
|
||||
|
||||
## Related
|
||||
|
||||
- [is-interactive](https://github.com/sindresorhus/is-interactive) - Check if stdout or stderr is interactive
|
||||
- [supports-color](https://github.com/chalk/supports-color) - Detect whether a terminal supports color
|
||||
- [figures](https://github.com/sindresorhus/figures) - Unicode symbols with Windows fallbacks
|
||||
- [log-symbols](https://github.com/sindresorhus/log-symbols) - Colored symbols for various log levels
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
{
|
||||
"name": "@clack/prompts",
|
||||
"version": "0.6.3",
|
||||
"type": "module",
|
||||
"main": "./dist/index.cjs",
|
||||
"module": "./dist/index.mjs",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"import": "./dist/index.mjs",
|
||||
"require": "./dist/index.cjs"
|
||||
},
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"types": "./dist/index.d.ts",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/natemoo-re/clack",
|
||||
"directory": "packages/prompts"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/natemoo-re/clack/issues"
|
||||
},
|
||||
"homepage": "https://github.com/natemoo-re/clack/tree/main/packages/prompts#readme",
|
||||
"files": [
|
||||
"dist",
|
||||
"CHANGELOG.md"
|
||||
],
|
||||
"author": {
|
||||
"name": "Nate Moore",
|
||||
"email": "nate@natemoo.re",
|
||||
"url": "https://twitter.com/n_moore"
|
||||
},
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"ask",
|
||||
"clack",
|
||||
"cli",
|
||||
"command-line",
|
||||
"command",
|
||||
"input",
|
||||
"interact",
|
||||
"interface",
|
||||
"menu",
|
||||
"prompt",
|
||||
"prompts",
|
||||
"stdin",
|
||||
"ui"
|
||||
],
|
||||
"packageManager": "pnpm@7.6.0",
|
||||
"dependencies": {
|
||||
"@clack/core": "^0.3.2",
|
||||
"picocolors": "^1.0.0",
|
||||
"sisteransi": "^1.0.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"is-unicode-supported": "^1.3.0"
|
||||
},
|
||||
"bundledDependencies": [
|
||||
"is-unicode-supported"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "unbuild"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user