@clack/prompts
Advanced tools
+31
-0
| # @clack/prompts | ||
| ## 1.5.0 | ||
| ### Minor Changes | ||
| - [#543](https://github.com/bombshell-dev/clack/pull/543) [`83428ac`](https://github.com/bombshell-dev/clack/commit/83428ac6d8bc5eda87615cc7b1f14e0c8b16e1b6) Thanks [@florian-lefebvre](https://github.com/florian-lefebvre)! - Adds support for Standard Schema validation | ||
| Prompts accept an optional `validate()` function to validate user input. While a function provides more flexibility and customization over your validation, it can be a bit verbose. To help solve this, there are libraries that provide schema-based validation to make shorthand and type-strict validation substantially easier. | ||
| Libraries following the [Standard Schema specification](https://github.com/standard-schema/standard-schema) are now natively supported. For example, using [Arktype](https://arktype.io/): | ||
| ```diff | ||
| import { text } from '@clack/prompts'; | ||
| import { type } from 'arktype'; | ||
| const name = await text({ | ||
| message: 'Enter your email', | ||
| + validate: type('string.email').describe('Invalid email'), | ||
| }); | ||
| ``` | ||
| ### Patch Changes | ||
| - [#542](https://github.com/bombshell-dev/clack/pull/542) [`adb6af9`](https://github.com/bombshell-dev/clack/commit/adb6af9f5fb39408934323a7415beb46b63ecd9a) Thanks [@ghostdevv](https://github.com/ghostdevv)! - docs: add jsdoc for `box`, `group`, and `group-multi-select` | ||
| - [#534](https://github.com/bombshell-dev/clack/pull/534) [`3dcb31a`](https://github.com/bombshell-dev/clack/commit/3dcb31a7d63827d95a5a52ac630cbd48e3a68364) Thanks [@MattStypa](https://github.com/MattStypa)! - Fixed spaces and uppercase characters in multiline prompt | ||
| - [#540](https://github.com/bombshell-dev/clack/pull/540) [`3170ed9`](https://github.com/bombshell-dev/clack/commit/3170ed94dc2a6ed7973228d46c664fb7461969ad) Thanks [@ghostdevv](https://github.com/ghostdevv)! - docs: add jsdoc for `autocomplete`, `confirm`, and `path` prompts | ||
| - Updated dependencies [[`83428ac`](https://github.com/bombshell-dev/clack/commit/83428ac6d8bc5eda87615cc7b1f14e0c8b16e1b6), [`3dcb31a`](https://github.com/bombshell-dev/clack/commit/3dcb31a7d63827d95a5a52ac630cbd48e3a68364)]: | ||
| - @clack/core@1.4.0 | ||
| ## 1.4.0 | ||
@@ -4,0 +35,0 @@ |
+313
-27
@@ -1,2 +0,2 @@ | ||
| import { State, AutocompletePrompt, DateFormat } from '@clack/core'; | ||
| import { State, AutocompletePrompt, Validate, DateFormat } from '@clack/core'; | ||
| export { ClackSettings, DateFormat, isCancel, settings, updateSettings } from '@clack/core'; | ||
@@ -101,26 +101,34 @@ import { Readable, Writable } from 'node:stream'; | ||
| /** | ||
| * Options for the {@link autocomplete} prompt. | ||
| */ | ||
| interface AutocompleteSharedOptions<Value> extends CommonOptions { | ||
| /** | ||
| * The message to display to the user. | ||
| * The message or question shown to the user above the input. | ||
| */ | ||
| message: string; | ||
| /** | ||
| * Available options for the autocomplete prompt. | ||
| * The options to present, or a function that returns the options to present | ||
| * allowing for custom search/filtering. | ||
| * | ||
| * @see https://bomb.sh/docs/clack/packages/prompts/#dynamic-options-getter | ||
| */ | ||
| options: Option<Value>[] | ((this: AutocompletePrompt<Option<Value>>) => Option<Value>[]); | ||
| /** | ||
| * Maximum number of items to display at once. | ||
| * The maximum number of items/options to display in the autocomplete list at once. | ||
| */ | ||
| maxItems?: number; | ||
| /** | ||
| * Placeholder text to display when no input is provided. | ||
| * Placeholder text displayed when the search field is empty. When set, pressing | ||
| * tab copies the placeholder into the input. | ||
| */ | ||
| placeholder?: string; | ||
| /** | ||
| * Validates the value | ||
| * A function or a [Standard Schema](https://github.com/standard-schema/standard-schema) | ||
| * that validates user input. If a custom function is given, you should return a `string` or `Error` | ||
| * to show as a validation error, or `undefined` to accept the result. | ||
| */ | ||
| validate?: (value: Value | Value[] | undefined) => string | Error | undefined; | ||
| validate?: Validate<Value | Value[]>; | ||
| /** | ||
| * Custom filter function to match options against search input. | ||
| * If not provided, a default filter that matches label, hint, and value is used. | ||
| * Custom filter function to match options against the search input. | ||
| */ | ||
@@ -131,18 +139,47 @@ filter?: (search: string, option: Option<Value>) => boolean; | ||
| /** | ||
| * The initial selected value. | ||
| * The initially selected option from the list. | ||
| */ | ||
| initialValue?: Value; | ||
| /** | ||
| * The initial user input | ||
| * The starting value shown in the users input box. | ||
| */ | ||
| initialUserInput?: string; | ||
| } | ||
| /** | ||
| * The `autocomplete` prompt combines a text input with a searchable list of options. | ||
| * It's perfect for when you have a large list of options and want to help users | ||
| * find what they're looking for quickly. | ||
| * | ||
| * @see https://bomb.sh/docs/clack/packages/prompts/#autocomplete | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { autocomplete } from '@clack/prompts'; | ||
| * | ||
| * const framework = await autocomplete({ | ||
| * message: 'Search for a framework', | ||
| * options: [ | ||
| * { value: 'next', label: 'Next.js', hint: 'React framework' }, | ||
| * { value: 'astro', label: 'Astro', hint: 'Content-focused' }, | ||
| * { value: 'svelte', label: 'SvelteKit', hint: 'Compile-time framework' }, | ||
| * { value: 'remix', label: 'Remix', hint: 'Full stack framework' }, | ||
| * { value: 'nuxt', label: 'Nuxt', hint: 'Vue framework' }, | ||
| * ], | ||
| * placeholder: 'Type to search...', | ||
| * maxItems: 5, | ||
| * }); | ||
| * ``` | ||
| */ | ||
| declare const autocomplete: <Value>(opts: AutocompleteOptions<Value>) => Promise<Value | symbol>; | ||
| /** | ||
| * Options for the {@link autocompleteMultiselect} prompt | ||
| */ | ||
| interface AutocompleteMultiSelectOptions<Value> extends AutocompleteSharedOptions<Value> { | ||
| /** | ||
| * The initial selected values | ||
| * The initially selected option(s) from the list. | ||
| */ | ||
| initialValues?: Value[]; | ||
| /** | ||
| * If true, at least one option must be selected | ||
| * When `true` at least one option must be selected. | ||
| * @default false | ||
| */ | ||
@@ -152,25 +189,138 @@ required?: boolean; | ||
| /** | ||
| * Integrated autocomplete multiselect - combines type-ahead filtering with multiselect in one UI | ||
| * The `autocompleteMultiselect` prompt combines the search functionality of autocomplete | ||
| * with the ability to select multiple options. | ||
| * | ||
| * @see https://bomb.sh/docs/clack/packages/prompts/#autocomplete-multiselect | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { autocompleteMultiselect } from '@clack/prompts'; | ||
| * | ||
| * const frameworks = await autocompleteMultiselect({ | ||
| * message: 'Select frameworks', | ||
| * options: [ | ||
| * { value: 'next', label: 'Next.js', hint: 'React framework' }, | ||
| * { value: 'astro', label: 'Astro', hint: 'Content-focused' }, | ||
| * { value: 'svelte', label: 'SvelteKit', hint: 'Compile-time framework' }, | ||
| * { value: 'remix', label: 'Remix', hint: 'Full stack framework' }, | ||
| * { value: 'nuxt', label: 'Nuxt', hint: 'Vue framework' }, | ||
| * ], | ||
| * placeholder: 'Type to search...', | ||
| * maxItems: 5, | ||
| * }); | ||
| * ``` | ||
| */ | ||
| declare const autocompleteMultiselect: <Value>(opts: AutocompleteMultiSelectOptions<Value>) => Promise<Value[] | symbol>; | ||
| /** | ||
| * Alignment for content or titles within the box. | ||
| */ | ||
| type BoxAlignment = 'left' | 'center' | 'right'; | ||
| /** | ||
| * Options for the {@link box} prompt. | ||
| */ | ||
| interface BoxOptions extends CommonOptions { | ||
| /** | ||
| * Alignment of the content (`'left'`, `'center'`, or `'right'`). | ||
| * @default 'left' | ||
| */ | ||
| contentAlign?: BoxAlignment; | ||
| /** | ||
| * Alignment of the title (`'left'`, `'center'`, or `'right'`). | ||
| * @default 'left' | ||
| */ | ||
| titleAlign?: BoxAlignment; | ||
| /** | ||
| * The width of the box, either `'auto'` to fit the content or a number for a fixed width. | ||
| * @default 'auto' | ||
| */ | ||
| width?: number | 'auto'; | ||
| /** | ||
| * Padding around the title. | ||
| * @default 1 | ||
| */ | ||
| titlePadding?: number; | ||
| /** | ||
| * Padding around the content. | ||
| * @default 2 | ||
| */ | ||
| contentPadding?: number; | ||
| /** | ||
| * Use rounded corners when `true`, square corners when `false`. | ||
| * @default true | ||
| */ | ||
| rounded?: boolean; | ||
| /** | ||
| * Custom function to style the border characters. | ||
| */ | ||
| formatBorder?: (text: string) => string; | ||
| } | ||
| /** | ||
| * Renders a customizable box around text content. It's similar to {@link note} but offers | ||
| * more styling options. | ||
| * | ||
| * @see https://bomb.sh/docs/clack/packages/prompts/#box | ||
| * | ||
| * @param message - The content to display inside the box. | ||
| * @param title - The title to display in the top border of the box. | ||
| * @param opts - Optional configuration for the box styling and behavior. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { box } from '@clack/prompts'; | ||
| * | ||
| * box('This is the content of the box', 'Box Title', { | ||
| * contentAlign: 'center', | ||
| * titleAlign: 'center', | ||
| * width: 'auto', | ||
| * rounded: true, | ||
| * }); | ||
| * ``` | ||
| */ | ||
| declare const box: (message?: string, title?: string, opts?: BoxOptions) => void; | ||
| /** | ||
| * Options for the {@link confirm} prompt. | ||
| */ | ||
| interface ConfirmOptions extends CommonOptions { | ||
| /** | ||
| * The message or question shown to the user above the input. | ||
| */ | ||
| message: string; | ||
| /** | ||
| * The label to use for the active (true) option. | ||
| * @default 'Yes' | ||
| */ | ||
| active?: string; | ||
| /** | ||
| * The label to use for the inactive (false) option. | ||
| * @default 'No' | ||
| */ | ||
| inactive?: string; | ||
| /** | ||
| * The initial selected value (true or false). | ||
| * @default true | ||
| */ | ||
| initialValue?: boolean; | ||
| /** | ||
| * Whether to render the options vertically instead of horizontally. | ||
| * @default false | ||
| */ | ||
| vertical?: boolean; | ||
| } | ||
| /** | ||
| * The `confirm` prompt accepts a yes or no choice, returning a boolean value | ||
| * corresponding to the user's selection. | ||
| * | ||
| * @see https://bomb.sh/docs/clack/packages/prompts/#confirmation | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { confirm } from '@clack/prompts'; | ||
| * | ||
| * const shouldProceed = await confirm({ | ||
| * message: 'Do you want to continue?', | ||
| * }); | ||
| * ``` | ||
| */ | ||
| declare const confirm: (opts: ConfirmOptions) => Promise<boolean | symbol>; | ||
@@ -186,3 +336,8 @@ | ||
| maxDate?: Date; | ||
| validate?: (value: Date | undefined) => string | Error | undefined; | ||
| /** | ||
| * A function or a [Standard Schema](https://github.com/standard-schema/standard-schema) | ||
| * that validates user input. If a custom function is given, you should return a `string` or `Error` | ||
| * to show as a validation error, or `undefined` to accept the result. | ||
| */ | ||
| validate?: Validate<Date>; | ||
| } | ||
@@ -194,9 +349,15 @@ declare const date: (opts: DateOptions) => Promise<Date | symbol>; | ||
| } & {}; | ||
| /** | ||
| * The return type of a {@link PromptGroup}. | ||
| * Resolves all prompt results, excluding the cancel symbol. | ||
| */ | ||
| type PromptGroupAwaitedReturn<T> = { | ||
| [P in keyof T]: Exclude<Awaited<T[P]>, symbol>; | ||
| }; | ||
| /** | ||
| * Options for the {@link group} utility. | ||
| */ | ||
| interface PromptGroupOptions<T> { | ||
| /** | ||
| * Control how the group can be canceled | ||
| * if one of the prompts is canceled. | ||
| * Called when any one of the prompts is canceled. | ||
| */ | ||
@@ -207,2 +368,6 @@ onCancel?: (opts: { | ||
| } | ||
| /** | ||
| * A group of prompts to be displayed sequentially, with each prompt receiving | ||
| * the results of all previous prompts in the group. | ||
| */ | ||
| type PromptGroup<T> = { | ||
@@ -214,17 +379,95 @@ [P in keyof T]: (opts: { | ||
| /** | ||
| * Define a group of prompts to be displayed | ||
| * and return a results of objects within the group | ||
| * The `group` utility provides a consistent way to combine a series of prompts, | ||
| * combining each answer into one object. Each prompt receives the results of | ||
| * all previously completed prompts, and are displayed sequentially. | ||
| * | ||
| * @see https://bomb.sh/docs/clack/packages/prompts/#group | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { group, text, password } from '@clack/prompts'; | ||
| * | ||
| * const account = await group({ | ||
| * email: () => text({ | ||
| * message: 'What is your email address?', | ||
| * }), | ||
| * username: ({ results }) => text({ | ||
| * message: 'What is your username?', | ||
| * placeholder: results.email?.replace(/@.+$/, '').toLowerCase() ?? '', | ||
| * }), | ||
| * password: () => password({ | ||
| * message: 'Define your password', | ||
| * }), | ||
| * }); | ||
| * ``` | ||
| */ | ||
| declare const group: <T>(prompts: PromptGroup<T>, opts?: PromptGroupOptions<T>) => Promise<Prettify<PromptGroupAwaitedReturn<T>>>; | ||
| /** | ||
| * Options for the {@link groupMultiselect} prompt. | ||
| */ | ||
| interface GroupMultiSelectOptions<Value> extends CommonOptions { | ||
| /** | ||
| * The message or question shown to the user above the input. | ||
| */ | ||
| message: string; | ||
| /** | ||
| * Grouped options to display. Each key is a group label, and each value is an array of options. | ||
| */ | ||
| options: Record<string, Option<Value>[]>; | ||
| /** | ||
| * The initially selected option(s). | ||
| */ | ||
| initialValues?: Value[]; | ||
| /** | ||
| * The maximum number of items/options to display at once. | ||
| */ | ||
| maxItems?: number; | ||
| /** | ||
| * When `true` at least one option must be selected. | ||
| * @default true | ||
| */ | ||
| required?: boolean; | ||
| /** | ||
| * The value the cursor should be positioned at initially. | ||
| */ | ||
| cursorAt?: Value; | ||
| /** | ||
| * Whether entire groups can be selected at once. | ||
| * @default true | ||
| */ | ||
| selectableGroups?: boolean; | ||
| /** | ||
| * Number of blank lines between groups. | ||
| * @default 0 | ||
| */ | ||
| groupSpacing?: number; | ||
| } | ||
| /** | ||
| * The `groupMultiselect` prompt extends the {@link multiselect} prompt to allow | ||
| * arranging distinct Multi-Selects, whilst keeping all of them interactive. | ||
| * | ||
| * @see https://bomb.sh/docs/clack/packages/prompts/#group-multiselect | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { groupMultiselect } from '@clack/prompts'; | ||
| * | ||
| * const result = await groupMultiselect({ | ||
| * message: 'Define your project', | ||
| * options: { | ||
| * 'Testing': [ | ||
| * { value: 'Jest', hint: 'JavaScript testing framework' }, | ||
| * { value: 'Playwright', hint: 'End-to-end testing' }, | ||
| * ], | ||
| * 'Language': [ | ||
| * { value: 'js', label: 'JavaScript', hint: 'Dynamic typing' }, | ||
| * { value: 'ts', label: 'TypeScript', hint: 'Static typing' }, | ||
| * ], | ||
| * }, | ||
| * }); | ||
| * ``` | ||
| * | ||
| * @param opts The options for the group multiselect prompt | ||
| */ | ||
| declare const groupMultiselect: <Value>(opts: GroupMultiSelectOptions<Value>) => Promise<Value[] | symbol>; | ||
@@ -284,6 +527,7 @@ | ||
| /** | ||
| * A function that validates user input. Return a `string` or `Error` to show as a | ||
| * validation error, or `undefined` to accept the result. | ||
| * A function or a [Standard Schema](https://github.com/standard-schema/standard-schema) | ||
| * that validates user input. If a custom function is given, you should return a `string` or `Error` | ||
| * to show as a validation error, or `undefined` to accept the result. | ||
| */ | ||
| validate?: (value: string | undefined) => string | Error | undefined; | ||
| validate?: Validate<string>; | ||
| } | ||
@@ -372,6 +616,7 @@ /** | ||
| /** | ||
| * A function that validates user input. Return a `string` or `Error` to show as a | ||
| * validation error, or `undefined` to accept the result. | ||
| * A function or a [Standard Schema](https://github.com/standard-schema/standard-schema) | ||
| * that validates user input. If a custom function is given, you should return a `string` or `Error` | ||
| * to show as a validation error, or `undefined` to accept the result. | ||
| */ | ||
| validate?: (value: string | undefined) => string | Error | undefined; | ||
| validate?: Validate<string>; | ||
| /** | ||
@@ -399,9 +644,50 @@ * When enabled it causes the input to be cleared if/when validation fails. | ||
| /** | ||
| * Options for the {@link path} prompt. | ||
| */ | ||
| interface PathOptions extends CommonOptions { | ||
| /** | ||
| * The message or question shown to the user above the input. | ||
| */ | ||
| message: string; | ||
| /** | ||
| * The starting directory for path suggestions (defaults to current working directory). | ||
| */ | ||
| root?: string; | ||
| /** | ||
| * When `true` only **directories** appear in suggestions while you navigate. | ||
| */ | ||
| directory?: boolean; | ||
| /** | ||
| * The starting path shown when the prompt first renders, which users can edit | ||
| * before submitting. If not provided it will fall back to the given `root`, | ||
| * or the current working directory. | ||
| * | ||
| * In `directory` mode, if the initial value points to a directory that exists, | ||
| * pressing enter will submit the input instead of jumping to the first child. | ||
| */ | ||
| initialValue?: string; | ||
| message: string; | ||
| validate?: (value: string | undefined) => string | Error | undefined; | ||
| /** | ||
| * A function or a [Standard Schema](https://github.com/standard-schema/standard-schema) | ||
| * that validates user input. If a custom function is given, you should return a `string` or `Error` | ||
| * to show as a validation error, or `undefined` to accept the result. | ||
| */ | ||
| validate?: Validate<string>; | ||
| } | ||
| /** | ||
| * The `path` prompt extends `autocomplete` to provide file and directory suggestions. | ||
| * | ||
| * @see https://bomb.sh/docs/clack/packages/prompts/#path-selection | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { path } from '@clack/prompts'; | ||
| * | ||
| * const result = await path({ | ||
| * message: 'Select a file:', | ||
| * root: process.cwd(), | ||
| * directory: false, | ||
| * }); | ||
| * ``` | ||
| */ | ||
| declare const path: (opts: PathOptions) => Promise<string | symbol>; | ||
@@ -408,0 +694,0 @@ |
+38
-38
@@ -1,3 +0,3 @@ | ||
| import{getColumns as X,getRows as Lt,AutocompletePrompt as vt,settings as T,ConfirmPrompt as Dt,wrapTextWithPrefix as E,DatePrompt as Wt,isCancel as Ft,GroupMultiSelectPrompt as Ht,MultiLinePrompt as Ut,MultiSelectPrompt as Kt,PasswordPrompt as qt,block as Jt,SelectPrompt as Yt,SelectKeyPrompt as Xt,TextPrompt as zt}from"@clack/core";export{isCancel,settings,updateSettings}from"@clack/core";import{styleText as e,stripVTControlCharacters as nt}from"node:util";import V from"node:process";import{wrapAnsi as J}from"fast-wrap-ansi";import B from"fast-string-width";import{existsSync as Qt,lstatSync as wt,readdirSync as Zt}from"node:fs";import{dirname as bt,join as te}from"node:path";import{cursor as St,erase as Ct}from"sisteransi";function ee(){return V.platform!=="win32"?V.env.TERM!=="linux":!!V.env.CI||!!V.env.WT_SESSION||!!V.env.TERMINUS_SUBLIME||V.env.ConEmuTask==="{cmd::Cmder}"||V.env.TERM_PROGRAM==="Terminus-Sublime"||V.env.TERM_PROGRAM==="vscode"||V.env.TERM==="xterm-256color"||V.env.TERM==="alacritty"||V.env.TERMINAL_EMULATOR==="JetBrains-JediTerm"}const tt=ee(),ot=()=>process.env.CI==="true",It=t=>t.isTTY===!0,w=(t,i)=>tt?t:i,Tt=w("\u25C6","*"),at=w("\u25A0","x"),ut=w("\u25B2","x"),H=w("\u25C7","o"),lt=w("\u250C","T"),$=w("\u2502","|"),x=w("\u2514","\u2014"),_t=w("\u2510","T"),xt=w("\u2518","\u2014"),z=w("\u25CF",">"),U=w("\u25CB"," "),et=w("\u25FB","[\u2022]"),K=w("\u25FC","[+]"),Y=w("\u25FB","[ ]"),Et=w("\u25AA","\u2022"),st=w("\u2500","-"),ct=w("\u256E","+"),Gt=w("\u251C","+"),$t=w("\u256F","+"),dt=w("\u2570","+"),Mt=w("\u256D","+"),ht=w("\u25CF","\u2022"),pt=w("\u25C6","*"),mt=w("\u25B2","!"),gt=w("\u25A0","x"),P=t=>{switch(t){case"initial":case"active":return e("cyan",Tt);case"cancel":return e("red",at);case"error":return e("yellow",ut);case"submit":return e("green",H)}},yt=t=>{switch(t){case"initial":case"active":return e("cyan",$);case"cancel":return e("red",$);case"error":return e("yellow",$);case"submit":return e("green",$)}},Ot=(t,i,s,r,u,n=!1)=>{let a=i,c=0;if(n)for(let o=r-1;o>=s&&(a-=t[o].length,c++,!(a<=u));o--);else for(let o=s;o<r&&(a-=t[o].length,c++,!(a<=u));o++);return{lineCount:a,removals:c}},F=({cursor:t,options:i,style:s,output:r=process.stdout,maxItems:u=Number.POSITIVE_INFINITY,columnPadding:n=0,rowPadding:a=4})=>{const c=X(r)-n,o=Lt(r),l=e("dim","..."),d=Math.max(o-a,0),g=Math.max(Math.min(u,d),5);let p=0;t>=g-3&&(p=Math.max(Math.min(t-g+3,i.length-g),0));let f=g<i.length&&p>0,h=g<i.length&&p+g<i.length;const I=Math.min(p+g,i.length),m=[];let y=0;f&&y++,h&&y++;const v=p+(f?1:0),C=I-(h?1:0);for(let b=v;b<C;b++){const G=J(s(i[b],b===t),c,{hard:!0,trim:!1}).split(` | ||
| `);m.push(G),y+=G.length}if(y>d){let b=0,G=0,M=y;const N=t-v;let O=d;const j=()=>Ot(m,M,0,N,O),k=()=>Ot(m,M,N+1,m.length,O,!0);f?({lineCount:M,removals:b}=j(),M>O&&(h||(O-=1),{lineCount:M,removals:G}=k())):(h||(O-=1),{lineCount:M,removals:G}=k(),M>O&&(O-=1,{lineCount:M,removals:b}=j())),b>0&&(f=!0,m.splice(0,b)),G>0&&(h=!0,m.splice(m.length-G,G))}const S=[];f&&S.push(l);for(const b of m)for(const G of b)S.push(G);return h&&S.push(l),S};function Pt(t){return t.label??String(t.value??"")}function Rt(t,i){if(!t)return!0;const s=(i.label??String(i.value??"")).toLowerCase(),r=(i.hint??"").toLowerCase(),u=String(i.value).toLowerCase(),n=t.toLowerCase();return s.includes(n)||r.includes(n)||u.includes(n)}function se(t,i){const s=[];for(const r of i)t.includes(r.value)&&s.push(r);return s}const At=t=>new vt({options:t.options,initialValue:t.initialValue?[t.initialValue]:void 0,initialUserInput:t.initialUserInput,placeholder:t.placeholder,filter:t.filter??((i,s)=>Rt(i,s)),signal:t.signal,input:t.input,output:t.output,validate:t.validate,render(){const i=t.withGuide??T.withGuide,s=i?[`${e("gray",$)}`,`${P(this.state)} ${t.message}`]:[`${P(this.state)} ${t.message}`],r=this.userInput,u=this.options,n=t.placeholder,a=r===""&&n!==void 0,c=(o,l)=>{const d=Pt(o),g=o.hint&&o.value===this.focusedValue?e("dim",` (${o.hint})`):"";switch(l){case"active":return`${e("green",z)} ${d}${g}`;case"inactive":return`${e("dim",U)} ${e("dim",d)}`;case"disabled":return`${e("gray",U)} ${e(["strikethrough","gray"],d)}`}};switch(this.state){case"submit":{const o=se(this.selectedValues,u),l=o.length>0?` ${e("dim",o.map(Pt).join(", "))}`:"",d=i?e("gray",$):"";return`${s.join(` | ||
| import{getColumns as X,getRows as Dt,AutocompletePrompt as wt,settings as T,ConfirmPrompt as Wt,wrapTextWithPrefix as E,DatePrompt as Ft,runValidation as nt,isCancel as Ht,GroupMultiSelectPrompt as Ut,MultiLinePrompt as Kt,MultiSelectPrompt as qt,PasswordPrompt as Jt,block as Yt,SelectPrompt as Xt,SelectKeyPrompt as zt,TextPrompt as Qt}from"@clack/core";export{isCancel,settings,updateSettings}from"@clack/core";import{styleText as e,stripVTControlCharacters as ot}from"node:util";import V from"node:process";import{wrapAnsi as J}from"fast-wrap-ansi";import B from"fast-string-width";import{existsSync as Zt,lstatSync as bt,readdirSync as te}from"node:fs";import{dirname as St,join as ee}from"node:path";import{cursor as Ct,erase as It}from"sisteransi";function se(){return V.platform!=="win32"?V.env.TERM!=="linux":!!V.env.CI||!!V.env.WT_SESSION||!!V.env.TERMINUS_SUBLIME||V.env.ConEmuTask==="{cmd::Cmder}"||V.env.TERM_PROGRAM==="Terminus-Sublime"||V.env.TERM_PROGRAM==="vscode"||V.env.TERM==="xterm-256color"||V.env.TERM==="alacritty"||V.env.TERMINAL_EMULATOR==="JetBrains-JediTerm"}const tt=se(),at=()=>process.env.CI==="true",Tt=t=>t.isTTY===!0,w=(t,i)=>tt?t:i,_t=w("\u25C6","*"),ut=w("\u25A0","x"),lt=w("\u25B2","x"),H=w("\u25C7","o"),ct=w("\u250C","T"),$=w("\u2502","|"),x=w("\u2514","\u2014"),xt=w("\u2510","T"),Et=w("\u2518","\u2014"),z=w("\u25CF",">"),U=w("\u25CB"," "),et=w("\u25FB","[\u2022]"),K=w("\u25FC","[+]"),Y=w("\u25FB","[ ]"),Gt=w("\u25AA","\u2022"),st=w("\u2500","-"),$t=w("\u256E","+"),Mt=w("\u251C","+"),dt=w("\u256F","+"),ht=w("\u2570","+"),Ot=w("\u256D","+"),pt=w("\u25CF","\u2022"),mt=w("\u25C6","*"),gt=w("\u25B2","!"),yt=w("\u25A0","x"),P=t=>{switch(t){case"initial":case"active":return e("cyan",_t);case"cancel":return e("red",ut);case"error":return e("yellow",lt);case"submit":return e("green",H)}},ft=t=>{switch(t){case"initial":case"active":return e("cyan",$);case"cancel":return e("red",$);case"error":return e("yellow",$);case"submit":return e("green",$)}},Pt=(t,i,s,r,u,n=!1)=>{let a=i,c=0;if(n)for(let o=r-1;o>=s&&(a-=t[o].length,c++,!(a<=u));o--);else for(let o=s;o<r&&(a-=t[o].length,c++,!(a<=u));o++);return{lineCount:a,removals:c}},F=({cursor:t,options:i,style:s,output:r=process.stdout,maxItems:u=Number.POSITIVE_INFINITY,columnPadding:n=0,rowPadding:a=4})=>{const c=X(r)-n,o=Dt(r),l=e("dim","..."),d=Math.max(o-a,0),g=Math.max(Math.min(u,d),5);let p=0;t>=g-3&&(p=Math.max(Math.min(t-g+3,i.length-g),0));let f=g<i.length&&p>0,h=g<i.length&&p+g<i.length;const I=Math.min(p+g,i.length),m=[];let y=0;f&&y++,h&&y++;const v=p+(f?1:0),C=I-(h?1:0);for(let b=v;b<C;b++){const G=J(s(i[b],b===t),c,{hard:!0,trim:!1}).split(` | ||
| `);m.push(G),y+=G.length}if(y>d){let b=0,G=0,M=y;const N=t-v;let O=d;const j=()=>Pt(m,M,0,N,O),k=()=>Pt(m,M,N+1,m.length,O,!0);f?({lineCount:M,removals:b}=j(),M>O&&(h||(O-=1),{lineCount:M,removals:G}=k())):(h||(O-=1),{lineCount:M,removals:G}=k(),M>O&&(O-=1,{lineCount:M,removals:b}=j())),b>0&&(f=!0,m.splice(0,b)),G>0&&(h=!0,m.splice(m.length-G,G))}const S=[];f&&S.push(l);for(const b of m)for(const G of b)S.push(G);return h&&S.push(l),S};function Rt(t){return t.label??String(t.value??"")}function At(t,i){if(!t)return!0;const s=(i.label??String(i.value??"")).toLowerCase(),r=(i.hint??"").toLowerCase(),u=String(i.value).toLowerCase(),n=t.toLowerCase();return s.includes(n)||r.includes(n)||u.includes(n)}function ie(t,i){const s=[];for(const r of i)t.includes(r.value)&&s.push(r);return s}const Vt=t=>new wt({options:t.options,initialValue:t.initialValue?[t.initialValue]:void 0,initialUserInput:t.initialUserInput,placeholder:t.placeholder,filter:t.filter??((i,s)=>At(i,s)),signal:t.signal,input:t.input,output:t.output,validate:t.validate,render(){const i=t.withGuide??T.withGuide,s=i?[`${e("gray",$)}`,`${P(this.state)} ${t.message}`]:[`${P(this.state)} ${t.message}`],r=this.userInput,u=this.options,n=t.placeholder,a=r===""&&n!==void 0,c=(o,l)=>{const d=Rt(o),g=o.hint&&o.value===this.focusedValue?e("dim",` (${o.hint})`):"";switch(l){case"active":return`${e("green",z)} ${d}${g}`;case"inactive":return`${e("dim",U)} ${e("dim",d)}`;case"disabled":return`${e("gray",U)} ${e(["strikethrough","gray"],d)}`}};switch(this.state){case"submit":{const o=ie(this.selectedValues,u),l=o.length>0?` ${e("dim",o.map(Rt).join(", "))}`:"",d=i?e("gray",$):"";return`${s.join(` | ||
| `)} | ||
@@ -7,12 +7,12 @@ ${d}${l}`}case"cancel":{const o=r?` ${e(["strikethrough","dim"],r)}`:"",l=i?e("gray",$):"";return`${s.join(` | ||
| ${l}${o}`}default:{const o=this.state==="error"?"yellow":"cyan",l=i?`${e(o,$)} `:"",d=i?e(o,x):"";let g="";if(this.isNavigating||a){const v=a?n:r;g=v!==""?` ${e("dim",v)}`:""}else g=` ${this.userInputWithCursor}`;const p=this.filteredOptions.length!==u.length?e("dim",` (${this.filteredOptions.length} match${this.filteredOptions.length===1?"":"es"})`):"",f=this.filteredOptions.length===0&&r?[`${l}${e("yellow","No matches found")}`]:[],h=this.state==="error"?[`${l}${e("yellow",this.error)}`]:[];i&&s.push(`${l.trimEnd()}`),s.push(`${l}${e("dim","Search:")}${g}${p}`,...f,...h);const I=[`${e("dim","\u2191/\u2193")} to select`,`${e("dim","Enter:")} confirm`,`${e("dim","Type:")} to search`],m=[`${l}${I.join(" \u2022 ")}`,d],y=this.filteredOptions.length===0?[]:F({cursor:this.cursor,options:this.filteredOptions,columnPadding:i?3:0,rowPadding:s.length+m.length,style:(v,C)=>c(v,v.disabled?"disabled":C?"active":"inactive"),maxItems:t.maxItems,output:t.output});return[...s,...y.map(v=>`${l}${v}`),...m].join(` | ||
| `)}}}}).prompt(),ie=t=>{const i=(r,u,n,a)=>{const c=n.includes(r.value),o=r.label??String(r.value??""),l=r.hint&&a!==void 0&&r.value===a?e("dim",` (${r.hint})`):"",d=c?e("green",K):e("dim",Y);return r.disabled?`${e("gray",Y)} ${e(["strikethrough","gray"],o)}`:u?`${d} ${o}${l}`:`${d} ${e("dim",o)}`},s=new vt({options:t.options,multiple:!0,placeholder:t.placeholder,filter:t.filter??((r,u)=>Rt(r,u)),validate:()=>{if(t.required&&s.selectedValues.length===0)return"Please select at least one item"},initialValue:t.initialValues,signal:t.signal,input:t.input,output:t.output,render(){const r=t.withGuide??T.withGuide,u=`${r?`${e("gray",$)} | ||
| `)}}}}).prompt(),re=t=>{const i=(r,u,n,a)=>{const c=n.includes(r.value),o=r.label??String(r.value??""),l=r.hint&&a!==void 0&&r.value===a?e("dim",` (${r.hint})`):"",d=c?e("green",K):e("dim",Y);return r.disabled?`${e("gray",Y)} ${e(["strikethrough","gray"],o)}`:u?`${d} ${o}${l}`:`${d} ${e("dim",o)}`},s=new wt({options:t.options,multiple:!0,placeholder:t.placeholder,filter:t.filter??((r,u)=>At(r,u)),validate:()=>{if(t.required&&s.selectedValues.length===0)return"Please select at least one item"},initialValue:t.initialValues,signal:t.signal,input:t.input,output:t.output,render(){const r=t.withGuide??T.withGuide,u=`${r?`${e("gray",$)} | ||
| `:""}${P(this.state)} ${t.message} | ||
| `,n=this.userInput,a=t.placeholder,c=n===""&&a!==void 0,o=this.isNavigating||c?e("dim",c?a:n):this.userInputWithCursor,l=this.options,d=this.filteredOptions.length!==l.length?e("dim",` (${this.filteredOptions.length} match${this.filteredOptions.length===1?"":"es"})`):"";switch(this.state){case"submit":return`${u}${r?`${e("gray",$)} `:""}${e("dim",`${this.selectedValues.length} items selected`)}`;case"cancel":return`${u}${r?`${e("gray",$)} `:""}${e(["strikethrough","dim"],n)}`;default:{const g=this.state==="error"?"yellow":"cyan",p=r?`${e(g,$)} `:"",f=r?e(g,x):"",h=[`${e("dim","\u2191/\u2193")} to navigate`,`${e("dim",this.isNavigating?"Space/Tab:":"Tab:")} select`,`${e("dim","Enter:")} confirm`,`${e("dim","Type:")} to search`],I=this.filteredOptions.length===0&&n?[`${p}${e("yellow","No matches found")}`]:[],m=this.state==="error"?[`${p}${e("yellow",this.error)}`]:[],y=[...`${u}${r?e(g,$):""}`.split(` | ||
| `),`${p}${e("dim","Search:")} ${o}${d}`,...I,...m],v=[`${p}${h.join(" \u2022 ")}`,f],C=F({cursor:this.cursor,options:this.filteredOptions,style:(S,b)=>i(S,b,this.selectedValues,this.focusedValue),maxItems:t.maxItems,output:t.output,rowPadding:y.length+v.length});return[...y,...C.map(S=>`${p}${S}`),...v].join(` | ||
| `)}}}});return s.prompt()},re=[Mt,ct,dt,$t],ne=[lt,_t,x,xt];function Vt(t,i,s,r){let u=s,n=s;return r==="center"?u=Math.floor((i-t)/2):r==="right"&&(u=i-t-s),n=i-u-t,[u,n]}const oe=t=>t,ae=(t="",i="",s)=>{const r=s?.output??process.stdout,u=X(r),n=2,a=s?.titlePadding??1,c=s?.contentPadding??2,o=s?.width===void 0||s.width==="auto"?1:Math.min(1,s.width),l=s?.withGuide??T.withGuide?`${$} `:"",d=s?.formatBorder??oe,g=(s?.rounded?re:ne).map(d),p=d(st),f=d($),h=B(l),I=B(i),m=u-h;let y=Math.floor(u*o)-h;if(s?.width==="auto"){const O=t.split(` | ||
| `);let j=I+a*2;for(const rt of O){const W=B(rt)+c*2;W>j&&(j=W)}const k=j+n;k<y&&(y=k)}y%2!==0&&(y<m?y++:y--);const v=y-n,C=v-a*2,S=I>C?`${i.slice(0,C-3)}...`:i,[b,G]=Vt(B(S),v,a,s?.titleAlign),M=J(t,v-c*2,{hard:!0,trim:!1});r.write(`${l}${g[0]}${p.repeat(b)}${S}${p.repeat(G)}${g[1]} | ||
| `)}}}});return s.prompt()},ne=[Ot,$t,ht,dt],oe=[ct,xt,x,Et];function jt(t,i,s,r){let u=s,n=s;return r==="center"?u=Math.floor((i-t)/2):r==="right"&&(u=i-t-s),n=i-u-t,[u,n]}const ae=t=>t,ue=(t="",i="",s)=>{const r=s?.output??process.stdout,u=X(r),n=2,a=s?.titlePadding??1,c=s?.contentPadding??2,o=s?.width===void 0||s.width==="auto"?1:Math.min(1,s.width),l=s?.withGuide??T.withGuide?`${$} `:"",d=s?.formatBorder??ae,g=(s?.rounded?ne:oe).map(d),p=d(st),f=d($),h=B(l),I=B(i),m=u-h;let y=Math.floor(u*o)-h;if(s?.width==="auto"){const O=t.split(` | ||
| `);let j=I+a*2;for(const rt of O){const W=B(rt)+c*2;W>j&&(j=W)}const k=j+n;k<y&&(y=k)}y%2!==0&&(y<m?y++:y--);const v=y-n,C=v-a*2,S=I>C?`${i.slice(0,C-3)}...`:i,[b,G]=jt(B(S),v,a,s?.titleAlign),M=J(t,v-c*2,{hard:!0,trim:!1});r.write(`${l}${g[0]}${p.repeat(b)}${S}${p.repeat(G)}${g[1]} | ||
| `);const N=M.split(` | ||
| `);for(const O of N){const[j,k]=Vt(B(O),v,c,s?.contentAlign);r.write(`${l}${f}${" ".repeat(j)}${O}${" ".repeat(k)}${f} | ||
| `);for(const O of N){const[j,k]=jt(B(O),v,c,s?.contentAlign);r.write(`${l}${f}${" ".repeat(j)}${O}${" ".repeat(k)}${f} | ||
| `)}r.write(`${l}${g[2]}${p.repeat(v)}${g[3]} | ||
| `)},ue=t=>{const i=t.active??"Yes",s=t.inactive??"No";return new Dt({active:i,inactive:s,signal:t.signal,input:t.input,output:t.output,initialValue:t.initialValue??!0,render(){const r=t.withGuide??T.withGuide,u=`${P(this.state)} `,n=r?`${e("gray",$)} `:"",a=E(t.output,t.message,n,u),c=`${r?`${e("gray",$)} | ||
| `)},le=t=>{const i=t.active??"Yes",s=t.inactive??"No";return new Wt({active:i,inactive:s,signal:t.signal,input:t.input,output:t.output,initialValue:t.initialValue??!0,render(){const r=t.withGuide??T.withGuide,u=`${P(this.state)} `,n=r?`${e("gray",$)} `:"",a=E(t.output,t.message,n,u),c=`${r?`${e("gray",$)} | ||
| `:""}${a} | ||
@@ -24,5 +24,5 @@ `,o=this.value?i:s;switch(this.state){case"submit":{const l=r?`${e("gray",$)} `:"";return`${c}${l}${e("dim",o)}`}case"cancel":{const l=r?`${e("gray",$)} `:"";return`${c}${l}${e(["strikethrough","dim"],o)}${r?` | ||
| ${d} | ||
| `}}}}).prompt()},le=t=>{const i=t.validate;return new Wt({...t,validate(s){if(s===void 0)return t.defaultValue!==void 0?void 0:i?i(s):T.date.messages.required;const r=u=>u.toISOString().slice(0,10);if(t.minDate&&r(s)<r(t.minDate))return T.date.messages.afterMin(t.minDate);if(t.maxDate&&r(s)>r(t.maxDate))return T.date.messages.beforeMax(t.maxDate);if(i)return i(s)},render(){const s=(t?.withGuide??T.withGuide)!==!1,r=`${`${s?`${e("gray",$)} | ||
| `}}}}).prompt()},ce=t=>{const i=t.validate;return new Ft({...t,validate(s){if(s===void 0)return t.defaultValue!==void 0?void 0:i?nt(i,s):T.date.messages.required;const r=u=>u.toISOString().slice(0,10);if(t.minDate&&r(s)<r(t.minDate))return T.date.messages.afterMin(t.minDate);if(t.maxDate&&r(s)>r(t.maxDate))return T.date.messages.beforeMax(t.maxDate);if(i)return nt(i,s)},render(){const s=(t?.withGuide??T.withGuide)!==!1,r=`${`${s?`${e("gray",$)} | ||
| `:""}${P(this.state)} `}${t.message} | ||
| `,u=this.state!=="initial"?this.state:"active",n=ce(this,u),a=this.value instanceof Date?this.formattedValue:"";switch(this.state){case"error":{const c=this.error?` ${e("yellow",this.error)}`:"",o=s?`${e("yellow",$)} `:"",l=s?e("yellow",x):"";return`${r.trim()} | ||
| `,u=this.state!=="initial"?this.state:"active",n=$e(this,u),a=this.value instanceof Date?this.formattedValue:"";switch(this.state){case"error":{const c=this.error?` ${e("yellow",this.error)}`:"",o=s?`${e("yellow",$)} `:"",l=s?e("yellow",x):"";return`${r.trim()} | ||
| ${o}${n} | ||
@@ -34,4 +34,4 @@ ${l}${c} | ||
| ${o} | ||
| `}}}}).prompt()};function ce(t,i){const s=t.segmentValues,r=t.segmentCursor;if(i==="submit"||i==="cancel")return t.formattedValue;const u=e("gray",t.separator);return t.segments.map((n,a)=>{const c=a===r.segmentIndex&&!["submit","cancel"].includes(i),o=de[n.type];return $e(s[n.type],{isActive:c,label:o})}).join(u)}function $e(t,i){const s=!t||t.replace(/_/g,"")==="";return i.isActive?e("inverse",s?i.label:t.replace(/_/g," ")):s?e("dim",i.label):t.replace(/_/g,e("dim"," "))}const de={year:"yyyy",month:"mm",day:"dd"},he=async(t,i)=>{const s={},r=Object.keys(t);for(const u of r){const n=t[u],a=await n({results:s})?.catch(c=>{throw c});if(typeof i?.onCancel=="function"&&Ft(a)){s[u]="canceled",i.onCancel({results:s});continue}s[u]=a}return s},pe=t=>{const{selectableGroups:i=!0,groupSpacing:s=0}=t,r=(n,a,c=[])=>{const o=n.label??String(n.value),l=typeof n.group=="string",d=l&&(c[c.indexOf(n)+1]??{group:!0}),g=l&&d&&d.group===!0;let p="",f="";l&&(i?(p=g?`${x} `:`${$} `,f=g?" ":`${$} `):p=" ");let h="";if(s>0&&!l&&(h=` | ||
| `.repeat(s)),a==="active")return E(t.output,`${o}${n.hint?` ${e("dim",`(${n.hint})`)}`:""}`,`${h}${e("dim",p)} `,`${h}${e("dim",p)}${e("cyan",et)} `,`${h}${e("dim",f)} `);if(a==="group-active")return E(t.output,o,`${h}${p} `,`${h}${p}${e("cyan",et)} `,`${h}${f} `,m=>e("dim",m));if(a==="group-active-selected")return E(t.output,o,`${h}${p} `,`${h}${p}${e("green",K)} `,`${h}${f} `,m=>e("dim",m));if(a==="selected"){const m=l||i?e("green",K):"";return E(t.output,`${o}${n.hint?` (${n.hint})`:""}`,`${h}${e("dim",p)} `,`${h}${e("dim",p)}${m} `,`${h}${e("dim",f)} `,y=>e("dim",y))}if(a==="cancelled")return`${e(["strikethrough","dim"],o)}`;if(a==="active-selected")return E(t.output,`${o}${n.hint?` ${e("dim",`(${n.hint})`)}`:""}`,`${h}${e("dim",p)} `,`${h}${e("dim",p)}${e("green",K)} `,`${h}${e("dim",f)} `);if(a==="submitted")return`${e("dim",o)}`;const I=l||i?e("dim",Y):"";return E(t.output,o,`${h}${e("dim",p)} `,`${h}${e("dim",p)}${I} `,`${h}${e("dim",f)} `,m=>e("dim",m))},u=t.required??!0;return new Ht({options:t.options,signal:t.signal,input:t.input,output:t.output,initialValues:t.initialValues,required:u,cursorAt:t.cursorAt,selectableGroups:i,validate(n){if(u&&(n===void 0||n.length===0))return`Please select at least one option. | ||
| `}}}}).prompt()};function $e(t,i){const s=t.segmentValues,r=t.segmentCursor;if(i==="submit"||i==="cancel")return t.formattedValue;const u=e("gray",t.separator);return t.segments.map((n,a)=>{const c=a===r.segmentIndex&&!["submit","cancel"].includes(i),o=he[n.type];return de(s[n.type],{isActive:c,label:o})}).join(u)}function de(t,i){const s=!t||t.replace(/_/g,"")==="";return i.isActive?e("inverse",s?i.label:t.replace(/_/g," ")):s?e("dim",i.label):t.replace(/_/g,e("dim"," "))}const he={year:"yyyy",month:"mm",day:"dd"},pe=async(t,i)=>{const s={},r=Object.keys(t);for(const u of r){const n=t[u],a=await n({results:s})?.catch(c=>{throw c});if(typeof i?.onCancel=="function"&&Ht(a)){s[u]="canceled",i.onCancel({results:s});continue}s[u]=a}return s},me=t=>{const{selectableGroups:i=!0,groupSpacing:s=0}=t,r=(n,a,c=[])=>{const o=n.label??String(n.value),l=typeof n.group=="string",d=l&&(c[c.indexOf(n)+1]??{group:!0}),g=l&&d&&d.group===!0;let p="",f="";l&&(i?(p=g?`${x} `:`${$} `,f=g?" ":`${$} `):p=" ");let h="";if(s>0&&!l&&(h=` | ||
| `.repeat(s)),a==="active")return E(t.output,`${o}${n.hint?` ${e("dim",`(${n.hint})`)}`:""}`,`${h}${e("dim",p)} `,`${h}${e("dim",p)}${e("cyan",et)} `,`${h}${e("dim",f)} `);if(a==="group-active")return E(t.output,o,`${h}${p} `,`${h}${p}${e("cyan",et)} `,`${h}${f} `,m=>e("dim",m));if(a==="group-active-selected")return E(t.output,o,`${h}${p} `,`${h}${p}${e("green",K)} `,`${h}${f} `,m=>e("dim",m));if(a==="selected"){const m=l||i?e("green",K):"";return E(t.output,`${o}${n.hint?` (${n.hint})`:""}`,`${h}${e("dim",p)} `,`${h}${e("dim",p)}${m} `,`${h}${e("dim",f)} `,y=>e("dim",y))}if(a==="cancelled")return`${e(["strikethrough","dim"],o)}`;if(a==="active-selected")return E(t.output,`${o}${n.hint?` ${e("dim",`(${n.hint})`)}`:""}`,`${h}${e("dim",p)} `,`${h}${e("dim",p)}${e("green",K)} `,`${h}${e("dim",f)} `);if(a==="submitted")return`${e("dim",o)}`;const I=l||i?e("dim",Y):"";return E(t.output,o,`${h}${e("dim",p)} `,`${h}${e("dim",p)}${I} `,`${h}${e("dim",f)} `,m=>e("dim",m))},u=t.required??!0;return new Ut({options:t.options,signal:t.signal,input:t.input,output:t.output,initialValues:t.initialValues,required:u,cursorAt:t.cursorAt,selectableGroups:i,validate(n){if(u&&(n===void 0||n.length===0))return`Please select at least one option. | ||
| ${e("reset",e("dim",`Press ${e(["gray","bgWhite","inverse"]," space ")} to select, ${e("gray",e(["bgWhite","inverse"]," enter "))} to submit`))}`},render(){const n=t.withGuide??T.withGuide,a=`${n?`${e("gray",$)} | ||
@@ -54,9 +54,9 @@ `:""}${P(this.state)} ${t.message} | ||
| `)} | ||
| `)},info:(t,i)=>{R.message(t,{...i,symbol:e("blue",ht)})},success:(t,i)=>{R.message(t,{...i,symbol:e("green",pt)})},step:(t,i)=>{R.message(t,{...i,symbol:e("green",H)})},warn:(t,i)=>{R.message(t,{...i,symbol:e("yellow",mt)})},warning:(t,i)=>{R.warn(t,i)},error:(t,i)=>{R.message(t,{...i,symbol:e("red",gt)})}},me=(t="",i)=>{const s=i?.output??process.stdout,r=i?.withGuide??T.withGuide?`${e("gray",x)} `:"";s.write(`${r}${e("red",t)} | ||
| `)},info:(t,i)=>{R.message(t,{...i,symbol:e("blue",pt)})},success:(t,i)=>{R.message(t,{...i,symbol:e("green",mt)})},step:(t,i)=>{R.message(t,{...i,symbol:e("green",H)})},warn:(t,i)=>{R.message(t,{...i,symbol:e("yellow",gt)})},warning:(t,i)=>{R.warn(t,i)},error:(t,i)=>{R.message(t,{...i,symbol:e("red",yt)})}},ge=(t="",i)=>{const s=i?.output??process.stdout,r=i?.withGuide??T.withGuide?`${e("gray",x)} `:"";s.write(`${r}${e("red",t)} | ||
| `)},ge=(t="",i)=>{const s=i?.output??process.stdout,r=i?.withGuide??T.withGuide?`${e("gray",lt)} `:"";s.write(`${r}${t} | ||
| `)},ye=(t="",i)=>{const s=i?.output??process.stdout,r=i?.withGuide??T.withGuide?`${e("gray",$)} | ||
| `)},ye=(t="",i)=>{const s=i?.output??process.stdout,r=i?.withGuide??T.withGuide?`${e("gray",ct)} `:"";s.write(`${r}${t} | ||
| `)},fe=(t="",i)=>{const s=i?.output??process.stdout,r=i?.withGuide??T.withGuide?`${e("gray",$)} | ||
| ${e("gray",x)} `:"";s.write(`${r}${t} | ||
| `)},fe=t=>new Ut({validate:t.validate,placeholder:t.placeholder,defaultValue:t.defaultValue,initialValue:t.initialValue,showSubmit:t.showSubmit,output:t.output,signal:t.signal,input:t.input,render(){const i=t?.withGuide??T.withGuide,s=`${`${i?`${e("gray",$)} | ||
| `)},ve=t=>new Kt({validate:t.validate,placeholder:t.placeholder,defaultValue:t.defaultValue,initialValue:t.initialValue,showSubmit:t.showSubmit,output:t.output,signal:t.signal,input:t.input,render(){const i=t?.withGuide??T.withGuide,s=`${`${i?`${e("gray",$)} | ||
| `:""}${P(this.state)} `}${t.message} | ||
@@ -70,4 +70,4 @@ `,r=t.placeholder?e("inverse",t.placeholder[0])+e("dim",t.placeholder.slice(1)):e(["inverse","hidden"],"_"),u=this.userInput?this.userInputWithCursor:r,n=this.value??"",a=t.showSubmit?` | ||
| `).map(s=>i(s)).join(` | ||
| `),ve=t=>{const i=(r,u)=>{const n=r.label??String(r.value);return u==="disabled"?`${e("gray",Y)} ${Q(n,a=>e(["strikethrough","gray"],a))}${r.hint?` ${e("dim",`(${r.hint??"disabled"})`)}`:""}`:u==="active"?`${e("cyan",et)} ${n}${r.hint?` ${e("dim",`(${r.hint})`)}`:""}`:u==="selected"?`${e("green",K)} ${Q(n,a=>e("dim",a))}${r.hint?` ${e("dim",`(${r.hint})`)}`:""}`:u==="cancelled"?`${Q(n,a=>e(["strikethrough","dim"],a))}`:u==="active-selected"?`${e("green",K)} ${n}${r.hint?` ${e("dim",`(${r.hint})`)}`:""}`:u==="submitted"?`${Q(n,a=>e("dim",a))}`:`${e("dim",Y)} ${Q(n,a=>e("dim",a))}`},s=t.required??!0;return new Kt({options:t.options,signal:t.signal,input:t.input,output:t.output,initialValues:t.initialValues,required:s,cursorAt:t.cursorAt,validate(r){if(s&&(r===void 0||r.length===0))return`Please select at least one option. | ||
| ${e("reset",e("dim",`Press ${e(["gray","bgWhite","inverse"]," space ")} to select, ${e("gray",e("bgWhite",e("inverse"," enter ")))} to submit`))}`},render(){const r=t.withGuide??T.withGuide,u=E(t.output,t.message,r?`${yt(this.state)} `:"",`${P(this.state)} `),n=`${r?`${e("gray",$)} | ||
| `),we=t=>{const i=(r,u)=>{const n=r.label??String(r.value);return u==="disabled"?`${e("gray",Y)} ${Q(n,a=>e(["strikethrough","gray"],a))}${r.hint?` ${e("dim",`(${r.hint??"disabled"})`)}`:""}`:u==="active"?`${e("cyan",et)} ${n}${r.hint?` ${e("dim",`(${r.hint})`)}`:""}`:u==="selected"?`${e("green",K)} ${Q(n,a=>e("dim",a))}${r.hint?` ${e("dim",`(${r.hint})`)}`:""}`:u==="cancelled"?`${Q(n,a=>e(["strikethrough","dim"],a))}`:u==="active-selected"?`${e("green",K)} ${n}${r.hint?` ${e("dim",`(${r.hint})`)}`:""}`:u==="submitted"?`${Q(n,a=>e("dim",a))}`:`${e("dim",Y)} ${Q(n,a=>e("dim",a))}`},s=t.required??!0;return new qt({options:t.options,signal:t.signal,input:t.input,output:t.output,initialValues:t.initialValues,required:s,cursorAt:t.cursorAt,validate(r){if(s&&(r===void 0||r.length===0))return`Please select at least one option. | ||
| ${e("reset",e("dim",`Press ${e(["gray","bgWhite","inverse"]," space ")} to select, ${e("gray",e("bgWhite",e("inverse"," enter ")))} to submit`))}`},render(){const r=t.withGuide??T.withGuide,u=E(t.output,t.message,r?`${ft(this.state)} `:"",`${P(this.state)} `),n=`${r?`${e("gray",$)} | ||
| `:""}${u} | ||
@@ -86,10 +86,10 @@ `,a=this.value??[],c=(o,l)=>{if(o.disabled)return i(o,"disabled");const d=a.includes(o.value);return l&&d?i(o,"active-selected"):d?i(o,"selected"):i(o,l?"active":"inactive")};switch(this.state){case"submit":{const o=this.options.filter(({value:d})=>a.includes(d)).map(d=>i(d,"submitted")).join(e("dim",", "))||e("dim","none"),l=E(t.output,o,r?`${e("gray",$)} `:"");return`${n}${l}`}case"cancel":{const o=this.options.filter(({value:d})=>a.includes(d)).map(d=>i(d,"cancelled")).join(e("dim",", "));if(o.trim()==="")return`${n}${e("gray",$)}`;const l=E(t.output,o,r?`${e("gray",$)} `:"");return`${n}${l}${r?` | ||
| ${r?e("cyan",x):""} | ||
| `}}}}).prompt()},we=t=>e("dim",t),be=(t,i,s)=>{const r={hard:!0,trim:!1},u=J(t,i,r).split(` | ||
| `),n=u.reduce((o,l)=>Math.max(B(l),o),0),a=u.map(s).reduce((o,l)=>Math.max(B(l),o),0),c=i-(a-n);return J(t,c,r)},Se=(t="",i="",s)=>{const r=s?.output??V.stdout,u=s?.withGuide??T.withGuide,n=s?.format??we,a=["",...be(t,X(r)-6,n).split(` | ||
| `}}}}).prompt()},be=t=>e("dim",t),Se=(t,i,s)=>{const r={hard:!0,trim:!1},u=J(t,i,r).split(` | ||
| `),n=u.reduce((o,l)=>Math.max(B(l),o),0),a=u.map(s).reduce((o,l)=>Math.max(B(l),o),0),c=i-(a-n);return J(t,c,r)},Ce=(t="",i="",s)=>{const r=s?.output??V.stdout,u=s?.withGuide??T.withGuide,n=s?.format??be,a=["",...Se(t,X(r)-6,n).split(` | ||
| `).map(n),""],c=B(i),o=Math.max(a.reduce((p,f)=>{const h=B(f);return h>p?h:p},0),c)+2,l=a.map(p=>`${e("gray",$)} ${p}${" ".repeat(o-B(p))}${e("gray",$)}`).join(` | ||
| `),d=u?`${e("gray",$)} | ||
| `:"",g=u?Gt:dt;r.write(`${d}${e("green",H)} ${e("reset",i)} ${e("gray",st.repeat(Math.max(o-c-1,1))+ct)} | ||
| `:"",g=u?Mt:ht;r.write(`${d}${e("green",H)} ${e("reset",i)} ${e("gray",st.repeat(Math.max(o-c-1,1))+$t)} | ||
| ${l} | ||
| ${e("gray",g+st.repeat(o+2)+$t)} | ||
| `)},Ce=t=>new qt({validate:t.validate,mask:t.mask??Et,signal:t.signal,input:t.input,output:t.output,render(){const i=t.withGuide??T.withGuide,s=`${i?`${e("gray",$)} | ||
| ${e("gray",g+st.repeat(o+2)+dt)} | ||
| `)},Ie=t=>new Jt({validate:t.validate,mask:t.mask??Gt,signal:t.signal,input:t.input,output:t.output,render(){const i=t.withGuide??T.withGuide,s=`${i?`${e("gray",$)} | ||
| `:""}${P(this.state)} ${t.message} | ||
@@ -102,11 +102,11 @@ `,r=this.userInputWithCursor,u=this.masked;switch(this.state){case"error":{const n=i?`${e("yellow",$)} `:"",a=i?`${e("yellow",x)} `:"",c=u??"";return t.clearOnError&&this.clear(),`${s.trim()} | ||
| ${a} | ||
| `}}}}).prompt(),Ie=t=>{const i=t.validate;return At({...t,initialUserInput:t.initialValue??t.root??process.cwd(),maxItems:5,validate(s){if(!Array.isArray(s)){if(!s)return"Please select a path";if(i)return i(s)}},options(){const s=this.userInput;if(s==="")return[];try{let r;Qt(s)?wt(s).isDirectory()&&(!t.directory||s.endsWith("/"))?r=s:r=bt(s):r=bt(s);const u=s.length>1&&s.endsWith("/")?s.slice(0,-1):s;return Zt(r).map(n=>{const a=te(r,n),c=wt(a);return{name:n,path:a,isDirectory:c.isDirectory()}}).filter(({path:n,isDirectory:a})=>n.startsWith(u)&&(a||!t.directory)).map(n=>({value:n.path}))}catch{return[]}}})},Te=t=>e("magenta",t),ft=({indicator:t="dots",onCancel:i,output:s=process.stdout,cancelMessage:r,errorMessage:u,frames:n=tt?["\u25D2","\u25D0","\u25D3","\u25D1"]:["\u2022","o","O","0"],delay:a=tt?80:120,signal:c,...o}={})=>{const l=ot();let d,g,p=!1,f=!1,h="",I,m=performance.now();const y=X(s),v=o?.styleFrame??Te,C=_=>{const A=_>1?u??T.messages.error:r??T.messages.cancel;f=_===1,p&&(W(A,_),f&&typeof i=="function"&&i())},S=()=>C(2),b=()=>C(1),G=()=>{process.on("uncaughtExceptionMonitor",S),process.on("unhandledRejection",S),process.on("SIGINT",b),process.on("SIGTERM",b),process.on("exit",C),c&&c.addEventListener("abort",b)},M=()=>{process.removeListener("uncaughtExceptionMonitor",S),process.removeListener("unhandledRejection",S),process.removeListener("SIGINT",b),process.removeListener("SIGTERM",b),process.removeListener("exit",C),c&&c.removeEventListener("abort",b)},N=()=>{if(I===void 0)return;l&&s.write(` | ||
| `}}}}).prompt(),Te=t=>{const i=t.validate;return Vt({...t,initialUserInput:t.initialValue??t.root??process.cwd(),maxItems:5,validate(s){if(!Array.isArray(s)){if(!s)return"Please select a path";if(i)return nt(i,s)}},options(){const s=this.userInput;if(s==="")return[];try{let r;Zt(s)?bt(s).isDirectory()&&(!t.directory||s.endsWith("/"))?r=s:r=St(s):r=St(s);const u=s.length>1&&s.endsWith("/")?s.slice(0,-1):s;return te(r).map(n=>{const a=ee(r,n),c=bt(a);return{name:n,path:a,isDirectory:c.isDirectory()}}).filter(({path:n,isDirectory:a})=>n.startsWith(u)&&(a||!t.directory)).map(n=>({value:n.path}))}catch{return[]}}})},_e=t=>e("magenta",t),vt=({indicator:t="dots",onCancel:i,output:s=process.stdout,cancelMessage:r,errorMessage:u,frames:n=tt?["\u25D2","\u25D0","\u25D3","\u25D1"]:["\u2022","o","O","0"],delay:a=tt?80:120,signal:c,...o}={})=>{const l=at();let d,g,p=!1,f=!1,h="",I,m=performance.now();const y=X(s),v=o?.styleFrame??_e,C=_=>{const A=_>1?u??T.messages.error:r??T.messages.cancel;f=_===1,p&&(W(A,_),f&&typeof i=="function"&&i())},S=()=>C(2),b=()=>C(1),G=()=>{process.on("uncaughtExceptionMonitor",S),process.on("unhandledRejection",S),process.on("SIGINT",b),process.on("SIGTERM",b),process.on("exit",C),c&&c.addEventListener("abort",b)},M=()=>{process.removeListener("uncaughtExceptionMonitor",S),process.removeListener("unhandledRejection",S),process.removeListener("SIGINT",b),process.removeListener("SIGTERM",b),process.removeListener("exit",C),c&&c.removeEventListener("abort",b)},N=()=>{if(I===void 0)return;l&&s.write(` | ||
| `);const _=J(I,y,{hard:!0,trim:!1}).split(` | ||
| `);_.length>1&&s.write(St.up(_.length-1)),s.write(St.to(0)),s.write(Ct.down())},O=_=>_.replace(/\.+$/,""),j=_=>{const A=(performance.now()-_)/1e3,L=Math.floor(A/60),D=Math.floor(A%60);return L>0?`[${L}m ${D}s]`:`[${D}s]`},k=o.withGuide??T.withGuide,rt=(_="")=>{p=!0,d=Jt({output:s}),h=O(_),m=performance.now(),k&&s.write(`${e("gray",$)} | ||
| `);let A=0,L=0;G(),g=setInterval(()=>{if(l&&h===I)return;N(),I=h;const D=v(n[A]);let Z;if(l)Z=`${D} ${h}...`;else if(t==="timer")Z=`${D} ${h} ${j(m)}`;else{const kt=".".repeat(Math.floor(L)).slice(0,3);Z=`${D} ${h}${kt}`}const Bt=J(Z,y,{hard:!0,trim:!1});s.write(Bt),A=A+1<n.length?A+1:0,L=L<4?L+.125:0},a)},W=(_="",A=0,L=!1)=>{if(!p)return;p=!1,clearInterval(g),N();const D=A===0?e("green",H):A===1?e("red",at):e("red",ut);h=_??h,L||(t==="timer"?s.write(`${D} ${h} ${j(m)} | ||
| `);_.length>1&&s.write(Ct.up(_.length-1)),s.write(Ct.to(0)),s.write(It.down())},O=_=>_.replace(/\.+$/,""),j=_=>{const A=(performance.now()-_)/1e3,L=Math.floor(A/60),D=Math.floor(A%60);return L>0?`[${L}m ${D}s]`:`[${D}s]`},k=o.withGuide??T.withGuide,rt=(_="")=>{p=!0,d=Yt({output:s}),h=O(_),m=performance.now(),k&&s.write(`${e("gray",$)} | ||
| `);let A=0,L=0;G(),g=setInterval(()=>{if(l&&h===I)return;N(),I=h;const D=v(n[A]);let Z;if(l)Z=`${D} ${h}...`;else if(t==="timer")Z=`${D} ${h} ${j(m)}`;else{const Lt=".".repeat(Math.floor(L)).slice(0,3);Z=`${D} ${h}${Lt}`}const kt=J(Z,y,{hard:!0,trim:!1});s.write(kt),A=A+1<n.length?A+1:0,L=L<4?L+.125:0},a)},W=(_="",A=0,L=!1)=>{if(!p)return;p=!1,clearInterval(g),N();const D=A===0?e("green",H):A===1?e("red",ut):e("red",lt);h=_??h,L||(t==="timer"?s.write(`${D} ${h} ${j(m)} | ||
| `):s.write(`${D} ${h} | ||
| `)),M(),d()};return{start:rt,stop:(_="")=>W(_,0),message:(_="")=>{h=O(_??h)},cancel:(_="")=>W(_,1),error:(_="")=>W(_,2),clear:()=>W("",0,!0),get isCancelled(){return f}}},jt={light:w("\u2500","-"),heavy:w("\u2501","="),block:w("\u2588","#")};function _e({style:t="heavy",max:i=100,size:s=40,...r}={}){const u=ft(r);let n=0,a="";const c=Math.max(1,i),o=Math.max(1,s),l=f=>{switch(f){case"initial":case"active":return h=>e("magenta",h);case"error":case"cancel":return h=>e("red",h);case"submit":return h=>e("green",h);default:return h=>e("magenta",h)}},d=(f,h)=>{const I=Math.floor(n/c*o);return`${l(f)(jt[t].repeat(I))}${e("dim",jt[t].repeat(o-I))} ${h}`},g=(f="")=>{a=f,u.start(d("initial",f))},p=(f=1,h)=>{n=Math.min(c,f+n),u.message(d("active",h??a)),a=h??a};return{start:g,stop:u.stop,cancel:u.cancel,error:u.error,clear:u.clear,advance:p,isCancelled:u.isCancelled,message:f=>p(0,f)}}const it=(t,i)=>t.includes(` | ||
| `)),M(),d()};return{start:rt,stop:(_="")=>W(_,0),message:(_="")=>{h=O(_??h)},cancel:(_="")=>W(_,1),error:(_="")=>W(_,2),clear:()=>W("",0,!0),get isCancelled(){return f}}},Nt={light:w("\u2500","-"),heavy:w("\u2501","="),block:w("\u2588","#")};function xe({style:t="heavy",max:i=100,size:s=40,...r}={}){const u=vt(r);let n=0,a="";const c=Math.max(1,i),o=Math.max(1,s),l=f=>{switch(f){case"initial":case"active":return h=>e("magenta",h);case"error":case"cancel":return h=>e("red",h);case"submit":return h=>e("green",h);default:return h=>e("magenta",h)}},d=(f,h)=>{const I=Math.floor(n/c*o);return`${l(f)(Nt[t].repeat(I))}${e("dim",Nt[t].repeat(o-I))} ${h}`},g=(f="")=>{a=f,u.start(d("initial",f))},p=(f=1,h)=>{n=Math.min(c,f+n),u.message(d("active",h??a)),a=h??a};return{start:g,stop:u.stop,cancel:u.cancel,error:u.error,clear:u.clear,advance:p,isCancelled:u.isCancelled,message:f=>p(0,f)}}const it=(t,i)=>t.includes(` | ||
| `)?t.split(` | ||
| `).map(s=>i(s)).join(` | ||
| `):i(t),xe=t=>{const i=(s,r)=>{const u=s.label??String(s.value);switch(r){case"disabled":return`${e("gray",U)} ${it(u,n=>e("gray",n))}${s.hint?` ${e("dim",`(${s.hint??"disabled"})`)}`:""}`;case"selected":return`${it(u,n=>e("dim",n))}`;case"active":return`${e("green",z)} ${u}${s.hint?` ${e("dim",`(${s.hint})`)}`:""}`;case"cancelled":return`${it(u,n=>e(["strikethrough","dim"],n))}`;default:return`${e("dim",U)} ${it(u,n=>e("dim",n))}`}};return new Yt({options:t.options,signal:t.signal,input:t.input,output:t.output,initialValue:t.initialValue,render(){const s=t.withGuide??T.withGuide,r=`${P(this.state)} `,u=`${yt(this.state)} `,n=E(t.output,t.message,u,r),a=`${s?`${e("gray",$)} | ||
| `):i(t),Ee=t=>{const i=(s,r)=>{const u=s.label??String(s.value);switch(r){case"disabled":return`${e("gray",U)} ${it(u,n=>e("gray",n))}${s.hint?` ${e("dim",`(${s.hint??"disabled"})`)}`:""}`;case"selected":return`${it(u,n=>e("dim",n))}`;case"active":return`${e("green",z)} ${u}${s.hint?` ${e("dim",`(${s.hint})`)}`:""}`;case"cancelled":return`${it(u,n=>e(["strikethrough","dim"],n))}`;default:return`${e("dim",U)} ${it(u,n=>e("dim",n))}`}};return new Xt({options:t.options,signal:t.signal,input:t.input,output:t.output,initialValue:t.initialValue,render(){const s=t.withGuide??T.withGuide,r=`${P(this.state)} `,u=`${ft(this.state)} `,n=E(t.output,t.message,u,r),a=`${s?`${e("gray",$)} | ||
| `:""}${n} | ||
@@ -118,3 +118,3 @@ `;switch(this.state){case"submit":{const c=s?`${e("gray",$)} `:"",o=E(t.output,i(this.options[this.cursor],"selected"),c);return`${a}${o}`}case"cancel":{const c=s?`${e("gray",$)} `:"",o=E(t.output,i(this.options[this.cursor],"cancelled"),c);return`${a}${o}${s?` | ||
| ${o} | ||
| `}}}}).prompt()},Ee=t=>{const i=(s,r="inactive")=>{const u=s.label??String(s.value);return r==="selected"?`${e("dim",u)}`:r==="cancelled"?`${e(["strikethrough","dim"],u)}`:r==="active"?`${e(["bgCyan","gray"],` ${s.value} `)} ${u}${s.hint?` ${e("dim",`(${s.hint})`)}`:""}`:`${e(["gray","bgWhite","inverse"],` ${s.value} `)} ${u}${s.hint?` ${e("dim",`(${s.hint})`)}`:""}`};return new Xt({options:t.options,signal:t.signal,input:t.input,output:t.output,initialValue:t.initialValue,caseSensitive:t.caseSensitive,render(){const s=t.withGuide??T.withGuide,r=`${s?`${e("gray",$)} | ||
| `}}}}).prompt()},Ge=t=>{const i=(s,r="inactive")=>{const u=s.label??String(s.value);return r==="selected"?`${e("dim",u)}`:r==="cancelled"?`${e(["strikethrough","dim"],u)}`:r==="active"?`${e(["bgCyan","gray"],` ${s.value} `)} ${u}${s.hint?` ${e("dim",`(${s.hint})`)}`:""}`:`${e(["gray","bgWhite","inverse"],` ${s.value} `)} ${u}${s.hint?` ${e("dim",`(${s.hint})`)}`:""}`};return new zt({options:t.options,signal:t.signal,input:t.input,output:t.output,initialValue:t.initialValue,caseSensitive:t.caseSensitive,render(){const s=t.withGuide??T.withGuide,r=`${s?`${e("gray",$)} | ||
| `:""}${P(this.state)} ${t.message} | ||
@@ -125,9 +125,9 @@ `;switch(this.state){case"submit":{const u=s?`${e("gray",$)} `:"",n=this.options.find(c=>c.value===this.value)??t.options[0],a=E(t.output,i(n,"selected"),u);return`${r}${a}`}case"cancel":{const u=s?`${e("gray",$)} `:"",n=E(t.output,i(this.options[0],"cancelled"),u);return`${r}${n}${s?` | ||
| ${n} | ||
| `}}}}).prompt()},Nt=`${e("gray",$)} `,q={message:async(t,{symbol:i=e("gray",$)}={})=>{process.stdout.write(`${e("gray",$)} | ||
| `}}}}).prompt()},Bt=`${e("gray",$)} `,q={message:async(t,{symbol:i=e("gray",$)}={})=>{process.stdout.write(`${e("gray",$)} | ||
| ${i} `);let s=3;for await(let r of t){r=r.replace(/\n/g,` | ||
| ${Nt}`),r.includes(` | ||
| `)&&(s=3+nt(r.slice(r.lastIndexOf(` | ||
| `))).length);const u=nt(r).length;s+u<process.stdout.columns?(s+=u,process.stdout.write(r)):(process.stdout.write(` | ||
| ${Nt}${r.trimStart()}`),s=3+nt(r.trimStart()).length)}process.stdout.write(` | ||
| `)},info:t=>q.message(t,{symbol:e("blue",ht)}),success:t=>q.message(t,{symbol:e("green",pt)}),step:t=>q.message(t,{symbol:e("green",H)}),warn:t=>q.message(t,{symbol:e("yellow",mt)}),warning:t=>q.warn(t),error:t=>q.message(t,{symbol:e("red",gt)})},Ge=async(t,i)=>{for(const s of t){if(s.enabled===!1)continue;const r=ft(i);r.start(s.title);const u=await s.task(r.message);r.stop(u||s.title)}},Me=t=>t.replace(/\x1b\[(?:\d+;)*\d*[ABCDEFGHfJKSTsu]|\x1b\[(s|u)/g,""),Oe=t=>{const i=t.output??process.stdout,s=X(i),r=e("gray",$),u=t.spacing??1,n=3,a=t.retainLog===!0,c=!ot()&&It(i);i.write(`${r} | ||
| ${Bt}`),r.includes(` | ||
| `)&&(s=3+ot(r.slice(r.lastIndexOf(` | ||
| `))).length);const u=ot(r).length;s+u<process.stdout.columns?(s+=u,process.stdout.write(r)):(process.stdout.write(` | ||
| ${Bt}${r.trimStart()}`),s=3+ot(r.trimStart()).length)}process.stdout.write(` | ||
| `)},info:t=>q.message(t,{symbol:e("blue",pt)}),success:t=>q.message(t,{symbol:e("green",mt)}),step:t=>q.message(t,{symbol:e("green",H)}),warn:t=>q.message(t,{symbol:e("yellow",gt)}),warning:t=>q.warn(t),error:t=>q.message(t,{symbol:e("red",yt)})},Me=async(t,i)=>{for(const s of t){if(s.enabled===!1)continue;const r=vt(i);r.start(s.title);const u=await s.task(r.message);r.stop(u||s.title)}},Oe=t=>t.replace(/\x1b\[(?:\d+;)*\d*[ABCDEFGHfJKSTsu]|\x1b\[(s|u)/g,""),Pe=t=>{const i=t.output??process.stdout,s=X(i),r=e("gray",$),u=t.spacing??1,n=3,a=t.retainLog===!0,c=!at()&&Tt(i);i.write(`${r} | ||
| `),i.write(`${e("green",H)} ${t.title} | ||
@@ -137,11 +137,11 @@ `);for(let m=0;m<u;m++)i.write(`${r} | ||
| ${v.header}`);const G=b.split(` | ||
| `).reduce((M,N)=>N===""?M+1:M+Math.ceil((N.length+n)/s),0);y+=G}y>0&&(y+=1,i.write(Ct.lines(y)))},g=(m,y,v)=>{const C=v?`${m.full} | ||
| `).reduce((M,N)=>N===""?M+1:M+Math.ceil((N.length+n)/s),0);y+=G}y>0&&(y+=1,i.write(It.lines(y)))},g=(m,y,v)=>{const C=v?`${m.full} | ||
| ${m.value}`:m.value;m.header!==void 0&&m.header!==""&&R.message(m.header.split(` | ||
| `).map(S=>e("bold",S)),{output:i,secondarySymbol:r,symbol:r,spacing:0}),R.message(C.split(` | ||
| `).map(S=>e("dim",S)),{output:i,secondarySymbol:r,symbol:r,spacing:y??u})},p=()=>{for(const m of o){const{header:y,value:v,full:C}=m;(y===void 0||y.length===0)&&v.length===0||g(m,void 0,a===!0&&C.length>0)}},f=(m,y,v)=>{if(d(!1),(v?.raw!==!0||!l)&&m.value!==""&&(m.value+=` | ||
| `),m.value+=Me(y),l=v?.raw===!0,t.limit!==void 0){const C=m.value.split(` | ||
| `),m.value+=Oe(y),l=v?.raw===!0,t.limit!==void 0){const C=m.value.split(` | ||
| `),S=C.length-t.limit;if(S>0){const b=C.splice(0,S);a&&(m.full+=(m.full===""?"":` | ||
| `)+b.join(` | ||
| `))}m.value=C.join(` | ||
| `)}c&&h()},h=()=>{for(const m of o)m.result?m.result.status==="error"?R.error(m.result.message,{output:i,secondarySymbol:r,spacing:0}):R.success(m.result.message,{output:i,secondarySymbol:r,spacing:0}):m.value!==""&&g(m,0)},I=(m,y)=>{d(!1),m.result=y,c&&h()};return{message(m,y){f(o[0],m,y)},group(m){const y={header:m,value:"",full:""};return o.push(y),{message(v,C){f(y,v,C)},error(v){I(y,{status:"error",message:v})},success(v){I(y,{status:"success",message:v})}}},error(m,y){d(!0),R.error(m,{output:i,secondarySymbol:r,spacing:1}),y?.showLog!==!1&&p(),o.splice(1,o.length-1),o[0].value="",o[0].full=""},success(m,y){d(!0),R.success(m,{output:i,secondarySymbol:r,spacing:1}),y?.showLog===!0&&p(),o.splice(1,o.length-1),o[0].value="",o[0].full=""}}},Pe=t=>new zt({validate:t.validate,placeholder:t.placeholder,defaultValue:t.defaultValue,initialValue:t.initialValue,output:t.output,signal:t.signal,input:t.input,render(){const i=t?.withGuide??T.withGuide,s=`${`${i?`${e("gray",$)} | ||
| `)}c&&h()},h=()=>{for(const m of o)m.result?m.result.status==="error"?R.error(m.result.message,{output:i,secondarySymbol:r,spacing:0}):R.success(m.result.message,{output:i,secondarySymbol:r,spacing:0}):m.value!==""&&g(m,0)},I=(m,y)=>{d(!1),m.result=y,c&&h()};return{message(m,y){f(o[0],m,y)},group(m){const y={header:m,value:"",full:""};return o.push(y),{message(v,C){f(y,v,C)},error(v){I(y,{status:"error",message:v})},success(v){I(y,{status:"success",message:v})}}},error(m,y){d(!0),R.error(m,{output:i,secondarySymbol:r,spacing:1}),y?.showLog!==!1&&p(),o.splice(1,o.length-1),o[0].value="",o[0].full=""},success(m,y){d(!0),R.success(m,{output:i,secondarySymbol:r,spacing:1}),y?.showLog===!0&&p(),o.splice(1,o.length-1),o[0].value="",o[0].full=""}}},Re=t=>new Qt({validate:t.validate,placeholder:t.placeholder,defaultValue:t.defaultValue,initialValue:t.initialValue,output:t.output,signal:t.signal,input:t.input,render(){const i=t?.withGuide??T.withGuide,s=`${`${i?`${e("gray",$)} | ||
| `:""}${P(this.state)} `}${t.message} | ||
@@ -154,3 +154,3 @@ `,r=t.placeholder?e("inverse",t.placeholder[0])+e("dim",t.placeholder.slice(1)):e(["inverse","hidden"],"_"),u=this.userInput?this.userInputWithCursor:r,n=this.value??"";switch(this.state){case"error":{const a=this.error?` ${e("yellow",this.error)}`:"",c=i?`${e("yellow",$)} `:"",o=i?e("yellow",x):"";return`${s.trim()} | ||
| ${c} | ||
| `}}}}).prompt();export{$ as S_BAR,x as S_BAR_END,xt as S_BAR_END_RIGHT,st as S_BAR_H,lt as S_BAR_START,_t as S_BAR_START_RIGHT,et as S_CHECKBOX_ACTIVE,Y as S_CHECKBOX_INACTIVE,K as S_CHECKBOX_SELECTED,Gt as S_CONNECT_LEFT,dt as S_CORNER_BOTTOM_LEFT,$t as S_CORNER_BOTTOM_RIGHT,Mt as S_CORNER_TOP_LEFT,ct as S_CORNER_TOP_RIGHT,gt as S_ERROR,ht as S_INFO,Et as S_PASSWORD_MASK,z as S_RADIO_ACTIVE,U as S_RADIO_INACTIVE,Tt as S_STEP_ACTIVE,at as S_STEP_CANCEL,ut as S_STEP_ERROR,H as S_STEP_SUBMIT,pt as S_SUCCESS,mt as S_WARN,At as autocomplete,ie as autocompleteMultiselect,ae as box,me as cancel,ue as confirm,le as date,he as group,pe as groupMultiselect,ge as intro,ot as isCI,It as isTTY,F as limitOptions,R as log,fe as multiline,ve as multiselect,Se as note,ye as outro,Ce as password,Ie as path,_e as progress,xe as select,Ee as selectKey,ft as spinner,q as stream,P as symbol,yt as symbolBar,Oe as taskLog,Ge as tasks,Pe as text,tt as unicode,w as unicodeOr}; | ||
| `}}}}).prompt();export{$ as S_BAR,x as S_BAR_END,Et as S_BAR_END_RIGHT,st as S_BAR_H,ct as S_BAR_START,xt as S_BAR_START_RIGHT,et as S_CHECKBOX_ACTIVE,Y as S_CHECKBOX_INACTIVE,K as S_CHECKBOX_SELECTED,Mt as S_CONNECT_LEFT,ht as S_CORNER_BOTTOM_LEFT,dt as S_CORNER_BOTTOM_RIGHT,Ot as S_CORNER_TOP_LEFT,$t as S_CORNER_TOP_RIGHT,yt as S_ERROR,pt as S_INFO,Gt as S_PASSWORD_MASK,z as S_RADIO_ACTIVE,U as S_RADIO_INACTIVE,_t as S_STEP_ACTIVE,ut as S_STEP_CANCEL,lt as S_STEP_ERROR,H as S_STEP_SUBMIT,mt as S_SUCCESS,gt as S_WARN,Vt as autocomplete,re as autocompleteMultiselect,ue as box,ge as cancel,le as confirm,ce as date,pe as group,me as groupMultiselect,ye as intro,at as isCI,Tt as isTTY,F as limitOptions,R as log,ve as multiline,we as multiselect,Ce as note,fe as outro,Ie as password,Te as path,xe as progress,Ee as select,Ge as selectKey,vt as spinner,q as stream,P as symbol,ft as symbolBar,Pe as taskLog,Me as tasks,Re as text,tt as unicode,w as unicodeOr}; | ||
| //# sourceMappingURL=index.mjs.map |
+2
-2
| { | ||
| "name": "@clack/prompts", | ||
| "version": "1.4.0", | ||
| "version": "1.5.0", | ||
| "type": "module", | ||
@@ -56,3 +56,3 @@ "main": "./dist/index.mjs", | ||
| "sisteransi": "^1.0.5", | ||
| "@clack/core": "1.3.1" | ||
| "@clack/core": "1.4.0" | ||
| }, | ||
@@ -59,0 +59,0 @@ "devDependencies": { |
+24
-3
@@ -84,3 +84,3 @@ # `@clack/prompts` | ||
| The confirm component accepts a yes or no answer. The result is a boolean value of `true` or `false`. | ||
| The `confirm` prompt accepts a yes or no choice, returning a boolean value corresponding to the user's selection. | ||
@@ -129,3 +129,3 @@ ```js | ||
| The autocomplete component lets a user filter a list by typing, then choose one option from the matching results. By default, matching uses each option's `label`, `hint`, and `value`. The result is the selected option's `value`. | ||
| The `autocomplete` prompt combines text input with a searchable list of options. It's perfect for when you have a large list of options and want to help users find what they're looking for quickly. | ||
@@ -147,2 +147,23 @@ ```js | ||
| ### Autocomplete Multi-Select | ||
| The `autocompleteMultiselect` prompt combines the search functionality of [autocomplete](#autocomplete) with the ability to select multiple options. | ||
| ```js | ||
| import { autocomplete } from '@clack/prompts'; | ||
| const framework = await autocomplete({ | ||
| message: 'Search for a framework', | ||
| options: [ | ||
| { value: 'next', label: 'Next.js', hint: 'React framework' }, | ||
| { value: 'astro', label: 'Astro', hint: 'Content-focused' }, | ||
| { value: 'svelte', label: 'SvelteKit', hint: 'Compile-time framework' }, | ||
| { value: 'remix', label: 'Remix', hint: 'Full stack framework' }, | ||
| { value: 'nuxt', label: 'Nuxt', hint: 'Vue framework' }, | ||
| ], | ||
| placeholder: 'Type to search...', | ||
| maxItems: 5, | ||
| }); | ||
| ``` | ||
| ### Select Key | ||
@@ -232,3 +253,3 @@ | ||
| The path component offers filesystem path suggestions and returns the selected path as a string. When `directory: true` is set, only directories can be selected. | ||
| The `path` prompt extends [`autocomplete`](#autocomplete) to provide file and directory suggestions. | ||
@@ -235,0 +256,0 @@ ```js |
Sorry, the diff of this file is too big to display
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
248547
9.13%217
0.46%397
5.59%0
-100%+ Added
- Removed
Updated