🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@clack/prompts

Package Overview
Dependencies
Maintainers
5
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@clack/prompts - npm Package Compare versions

Comparing version
1.5.0
to
1.5.1
+11
-0
CHANGELOG.md
# @clack/prompts
## 1.5.1
### Patch Changes
- [#548](https://github.com/bombshell-dev/clack/pull/548) [`2356e97`](https://github.com/bombshell-dev/clack/commit/2356e97c1f46007ead55133c3a26910404ef1cfb) Thanks [@43081j](https://github.com/43081j)! - Remove sourcemaps and enable pretty-ish build output.
- [#546](https://github.com/bombshell-dev/clack/pull/546) [`56e9d67`](https://github.com/bombshell-dev/clack/commit/56e9d6707715bc858d9c2dbc444230b02813e809) Thanks [@ghostdevv](https://github.com/ghostdevv)! - docs: add jsdoc for `date`, `limit-options`, and `messages`
- Updated dependencies [[`2356e97`](https://github.com/bombshell-dev/clack/commit/2356e97c1f46007ead55133c3a26910404ef1cfb)]:
- @clack/core@1.4.1
## 1.5.0

@@ -4,0 +15,0 @@

@@ -325,9 +325,37 @@ import { State, AutocompletePrompt, Validate, DateFormat } from '@clack/core';

/**
* Options for the {@link date} prompt.
*/
interface DateOptions extends CommonOptions {
/**
* The message or question shown to the user above the input.
*/
message: string;
/**
* The date format for the input segments.
* @deafult based on locale
*/
format?: DateFormat;
/**
* The BCP 47 language tag to use for formatting
* @see https://developer.mozilla.org/en-US/docs/Glossary/BCP_47_language_tag
* @example "en-GB"
*/
locale?: string;
/**
* The default value returned when the user doesn't select a date.
*/
defaultValue?: Date;
/**
* The starting date shown when the prompt first renders.
* Users can edit this value before submitting.
*/
initialValue?: Date;
/**
* The minimum allowed date for validation.
*/
minDate?: Date;
/**
* The maximum allowed date for validation.
*/
maxDate?: Date;

@@ -341,2 +369,21 @@ /**

}
/**
* The `date` prompt provides an interactive date picker, allowing users
* to navigate between year, month, and day segments and
* increment/decrement values using keyboard controls.
*
* @see https://bomb.sh/docs/clack/packages/prompts/#date-input
*
* @example
* ```ts
* import { date } from '@clack/prompts';
*
* const birthday = await date({
* message: 'Pick your birthday',
* minDate: new Date('1900-01-01'),
* initialValue: new Date(),
* maxDate: new Date(),
* });
* ```
*/
declare const date: (opts: DateOptions) => Promise<Date | symbol>;

@@ -470,10 +517,60 @@

/**
* Options for the {@link limitOptions} function.
*/
interface LimitOptionsParams<TOption> extends CommonOptions {
/**
* The list of options to display.
*/
options: TOption[];
/**
* The index of the currently active/selected option.
*/
cursor: number;
/**
* A function that styles the given option string.
*
* @param option - The option string to style.
* @param active - Whether the option is currently selected.
*/
style: (option: TOption, active: boolean) => string;
/**
* Maximum number of options to display at once.
* @default Infinity
*/
maxItems?: number;
/**
* Number of columns to reserve for padding.
* @default 0
*/
columnPadding?: number;
/**
* Number of rows to reserve for padding.
* @default 4
*/
rowPadding?: number;
}
/**
* Trims an option list to what fits the terminal, while keeping the active
* option (cursor) visible using a Clack style sliding window.
*
* @returns The lines to render.
*
* @see https://bomb.sh/docs/clack/packages/prompts/#limitoptions
*
* @example
* ```ts
* import { limitOptions } from '@clack/prompts';
* import { styleText } from 'node:util';
*
* const options = ['apple', 'banana', 'cherry', 'date'];
* const lines = limitOptions({
* options,
* cursor: 2,
* maxItems: 8,
* style: (opt, active) =>
* active ? styleText('cyan', opt) : styleText('dim', opt),
* });
* ```
*/
declare const limitOptions: <TOption>({ cursor, options, style, output, maxItems, columnPadding, rowPadding, }: LimitOptionsParams<TOption>) => string[];

@@ -497,4 +594,52 @@

/**
* The `cancel` function defines an interruption of an interaction
* and therefore its end.
*
* @param title Optional closing message to be displayed.
* @param opts Additional configuration options.
*
* @see https://bomb.sh/docs/clack/packages/prompts/#cancel
*
* @example
* ```ts
* import { cancel } from '@clack/prompts';
* import process from 'node:process';
*
* cancel('Installation canceled');
* process.exit(1);
* ```
*/
declare const cancel: (message?: string, opts?: CommonOptions) => void;
/**
* The `intro` function defines the beginning of an interaction.
*
* @param title Optional title to be displayed.
* @param opts Additional configuration options.
*
* @see https://bomb.sh/docs/clack/packages/prompts/#intro
*
* @example
* ```ts
* import { intro } from '@clack/prompts';
*
* intro('Welcome to clack');
* ```
*/
declare const intro: (title?: string, opts?: CommonOptions) => void;
/**
* The `outro` function defines the end of an interaction.
*
* @param title Optional closing message to be displayed.
* @param opts Additional configuration options.
*
* @see https://bomb.sh/docs/clack/packages/prompts/#outro
*
* @example
* ```ts
* import { outro } from '@clack/prompts';
*
* outro('All operations are finished');
* ```
*/
declare const outro: (message?: string, opts?: CommonOptions) => void;

@@ -501,0 +646,0 @@

+1376
-139

@@ -1,145 +0,1382 @@

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(`
import { getColumns, getRows, AutocompletePrompt, settings, ConfirmPrompt, wrapTextWithPrefix, DatePrompt, runValidation, isCancel, GroupMultiSelectPrompt, MultiLinePrompt, MultiSelectPrompt, PasswordPrompt, block, SelectPrompt, SelectKeyPrompt, TextPrompt } from '@clack/core';
export { isCancel, settings, updateSettings } from '@clack/core';
import { styleText, stripVTControlCharacters } from 'node:util';
import process$1 from 'node:process';
import { wrapAnsi } from 'fast-wrap-ansi';
import l from 'fast-string-width';
import { existsSync, lstatSync, readdirSync } from 'node:fs';
import { dirname, join } from 'node:path';
import { cursor, erase } from 'sisteransi';
function isUnicodeSupported() {
if (process$1.platform !== 'win32') {
return process$1.env.TERM !== 'linux'; // Linux console (kernel)
}
return Boolean(process$1.env.CI)
|| Boolean(process$1.env.WT_SESSION) // Windows Terminal
|| Boolean(process$1.env.TERMINUS_SUBLIME) // Terminus (<0.2.27)
|| process$1.env.ConEmuTask === '{cmd::Cmder}' // ConEmu and 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(), isCI = () => process.env.CI === "true", isTTY = (e) => e.isTTY === true, unicodeOr = (e, o) => unicode ? e : o, S_STEP_ACTIVE = unicodeOr("\u25C6", "*"), S_STEP_CANCEL = unicodeOr("\u25A0", "x"), S_STEP_ERROR = unicodeOr("\u25B2", "x"), S_STEP_SUBMIT = unicodeOr("\u25C7", "o"), S_BAR_START = unicodeOr("\u250C", "T"), S_BAR = unicodeOr("\u2502", "|"), S_BAR_END = unicodeOr("\u2514", "\u2014"), S_BAR_START_RIGHT = unicodeOr("\u2510", "T"), S_BAR_END_RIGHT = unicodeOr("\u2518", "\u2014"), S_RADIO_ACTIVE = unicodeOr("\u25CF", ">"), S_RADIO_INACTIVE = unicodeOr("\u25CB", " "), S_CHECKBOX_ACTIVE = unicodeOr("\u25FB", "[\u2022]"), S_CHECKBOX_SELECTED = unicodeOr("\u25FC", "[+]"), S_CHECKBOX_INACTIVE = unicodeOr("\u25FB", "[ ]"), S_PASSWORD_MASK = unicodeOr("\u25AA", "\u2022"), S_BAR_H = unicodeOr("\u2500", "-"), S_CORNER_TOP_RIGHT = unicodeOr("\u256E", "+"), S_CONNECT_LEFT = unicodeOr("\u251C", "+"), S_CORNER_BOTTOM_RIGHT = unicodeOr("\u256F", "+"), S_CORNER_BOTTOM_LEFT = unicodeOr("\u2570", "+"), S_CORNER_TOP_LEFT = unicodeOr("\u256D", "+"), S_INFO = unicodeOr("\u25CF", "\u2022"), S_SUCCESS = unicodeOr("\u25C6", "*"), S_WARN = unicodeOr("\u25B2", "!"), S_ERROR = unicodeOr("\u25A0", "x"), symbol = (e) => {
switch (e) {
case "initial":
case "active":
return styleText("cyan", S_STEP_ACTIVE);
case "cancel":
return styleText("red", S_STEP_CANCEL);
case "error":
return styleText("yellow", S_STEP_ERROR);
case "submit":
return styleText("green", S_STEP_SUBMIT);
}
}, symbolBar = (e) => {
switch (e) {
case "initial":
case "active":
return styleText("cyan", S_BAR);
case "cancel":
return styleText("red", S_BAR);
case "error":
return styleText("yellow", S_BAR);
case "submit":
return styleText("green", S_BAR);
}
};
const E$1 = (l, o, g, c, h, O = false) => {
let r = o, w = 0;
if (O)
for (let i = c - 1; i >= g && (r -= l[i].length, w++, !(r <= h)); i--)
;
else
for (let i = g; i < c && (r -= l[i].length, w++, !(r <= h)); i++)
;
return { lineCount: r, removals: w };
};
const limitOptions = ({
cursor: l,
options: o,
style: g,
output: c = process.stdout,
maxItems: h = Number.POSITIVE_INFINITY,
columnPadding: O = 0,
rowPadding: r = 4
}) => {
const i = getColumns(c) - O, I = getRows(c), C = styleText("dim", "..."), x = Math.max(I - r, 0), m = Math.max(Math.min(h, x), 5);
let p = 0;
l >= m - 3 && (p = Math.max(
Math.min(l - m + 3, o.length - m),
0
));
let f = m < o.length && p > 0, u = m < o.length && p + m < o.length;
const W = Math.min(
p + m,
o.length
), e = [];
let d = 0;
f && d++, u && d++;
const v = p + (f ? 1 : 0), P = W - (u ? 1 : 0);
for (let t = v; t < P; t++) {
const n = wrapAnsi(g(o[t], t === l), i, {
hard: true,
trim: false
}).split(`
`);
e.push(n), d += n.length;
}
if (d > x) {
let t = 0, n = 0, s = d;
const M = l - v;
let a = x;
const T = () => E$1(e, s, 0, M, a), L = () => E$1(
e,
s,
M + 1,
e.length,
a,
true
);
f ? ({ lineCount: s, removals: t } = T(), s > a && (u || (a -= 1), { lineCount: s, removals: n } = L())) : (u || (a -= 1), { lineCount: s, removals: n } = L(), s > a && (a -= 1, { lineCount: s, removals: t } = T())), t > 0 && (f = true, e.splice(0, t)), n > 0 && (u = true, e.splice(e.length - n, n));
}
const b = [];
f && b.push(C);
for (const t of e)
for (const n of t)
b.push(n);
return u && b.push(C), b;
};
function P(t) {
return t.label ?? String(t.value ?? "");
}
function E(t, c) {
if (!t)
return true;
const n = (c.label ?? String(c.value ?? "")).toLowerCase(), i = (c.hint ?? "").toLowerCase(), l = String(c.value).toLowerCase(), o = t.toLowerCase();
return n.includes(o) || i.includes(o) || l.includes(o);
}
function N(t, c) {
const n = [];
for (const i of c)
t.includes(i.value) && n.push(i);
return n;
}
const autocomplete = (t) => new AutocompletePrompt({
options: t.options,
initialValue: t.initialValue ? [t.initialValue] : void 0,
initialUserInput: t.initialUserInput,
placeholder: t.placeholder,
filter: t.filter ?? ((n, i) => E(n, i)),
signal: t.signal,
input: t.input,
output: t.output,
validate: t.validate,
render() {
const n = t.withGuide ?? settings.withGuide, i = n ? [`${styleText("gray", S_BAR)}`, `${symbol(this.state)} ${t.message}`] : [`${symbol(this.state)} ${t.message}`], l = this.userInput, o = this.options, m = t.placeholder, p = l === "" && m !== void 0, $ = (r, s) => {
const a = P(r), u = r.hint && r.value === this.focusedValue ? styleText("dim", ` (${r.hint})`) : "";
switch (s) {
case "active":
return `${styleText("green", S_RADIO_ACTIVE)} ${a}${u}`;
case "inactive":
return `${styleText("dim", S_RADIO_INACTIVE)} ${styleText("dim", a)}`;
case "disabled":
return `${styleText("gray", S_RADIO_INACTIVE)} ${styleText(["strikethrough", "gray"], a)}`;
}
};
switch (this.state) {
case "submit": {
const r = N(this.selectedValues, o), s = r.length > 0 ? ` ${styleText("dim", r.map(P).join(", "))}` : "", a = n ? styleText("gray", S_BAR) : "";
return `${i.join(`
`)}
${d}${l}`}case"cancel":{const o=r?` ${e(["strikethrough","dim"],r)}`:"",l=i?e("gray",$):"";return`${s.join(`
${a}${s}`;
}
case "cancel": {
const r = l ? ` ${styleText(["strikethrough", "dim"], l)}` : "", s = n ? styleText("gray", S_BAR) : "";
return `${i.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(),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()},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]=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]}
`)},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}
`,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?`
${e("gray",$)}`:""}`}default:{const l=r?`${e("cyan",$)} `:"",d=r?e("cyan",x):"";return`${c}${l}${this.value?`${e("green",z)} ${i}`:`${e("dim",U)} ${e("dim",i)}`}${t.vertical?r?`
${e("cyan",$)} `:`
`:` ${e("dim","/")} `}${this.value?`${e("dim",U)} ${e("dim",s)}`:`${e("green",z)} ${s}`}
${d}
`}}}}).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=$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}
${l}${c}
`}case"submit":{const c=a?` ${e("dim",a)}`:"",o=s?e("gray",$):"";return`${r}${o}${c}`}case"cancel":{const c=a?` ${e(["strikethrough","dim"],a)}`:"",o=s?e("gray",$):"";return`${r}${o}${c}${a.trim()?`
${o}`:""}`}default:{const c=s?`${e("cyan",$)} `:"",o=s?e("cyan",x):"",l=s?`${e("cyan",$)} `:"",d=this.inlineError?`
${l}${e("yellow",this.inlineError)}`:"";return`${r}${c}${n}${d}
${o}
`}}}}).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",$)}
`:""}${P(this.state)} ${t.message}
`,c=this.value??[],o=(l,d)=>{const g=this.options,p=c.includes(l.value)||l.group===!0&&this.isGroupSelected(`${l.value}`);return!d&&typeof l.group=="string"&&this.options[this.cursor].value===l.group?r(l,p?"group-active-selected":"group-active",g):d&&p?r(l,"active-selected",g):p?r(l,"selected",g):r(l,d?"active":"inactive",g)};switch(this.state){case"submit":{const l=this.options.filter(({value:g})=>c.includes(g)).map(g=>r(g,"submitted")),d=l.length===0?"":` ${l.join(e("dim",", "))}`;return`${a}${n?e("gray",$):""}${d}`}case"cancel":{const l=this.options.filter(({value:d})=>c.includes(d)).map(d=>r(d,"cancelled")).join(e("dim",", "));return`${a}${n?`${e("gray",$)} `:""}${l.trim()?`${l}${n?`
${e("gray",$)}`:""}`:""}`}case"error":{const l=n?`${e("yellow",$)} `:"",d=this.error.split(`
`).map((h,I)=>I===0?`${n?`${e("yellow",x)} `:""}${e("yellow",h)}`:` ${h}`).join(`
`),g=a.split(`
`).length,p=d.split(`
`).length+1,f=F({output:t.output,options:this.options,cursor:this.cursor,maxItems:t.maxItems,columnPadding:l.length,rowPadding:g+p,style:o}).join(`
${l}`);return`${a}${l}${f}
${d}
`}default:{const l=n?`${e("cyan",$)} `:"",d=a.split(`
`).length,g=(n?1:0)+1,p=F({output:t.output,options:this.options,cursor:this.cursor,maxItems:t.maxItems,columnPadding:l.length,rowPadding:d+g,style:o}).join(`
${l}`);return`${a}${l}${p}
${n?e("cyan",x):""}
`}}}}).prompt()},R={message:(t=[],{symbol:i=e("gray",$),secondarySymbol:s=e("gray",$),output:r=process.stdout,spacing:u=1,withGuide:n}={})=>{const a=[],c=n??T.withGuide,o=c?s:"",l=c?`${i} `:"",d=c?`${s} `:"";for(let p=0;p<u;p++)a.push(o);const g=Array.isArray(t)?t:t.split(`
`);if(g.length>0){const[p,...f]=g;p.length>0?a.push(`${l}${p}`):a.push(c?i:"");for(const h of f)h.length>0?a.push(`${d}${h}`):a.push(c?s:"")}r.write(`${a.join(`
${s}${r}`;
}
default: {
const r = this.state === "error" ? "yellow" : "cyan", s = n ? `${styleText(r, S_BAR)} ` : "", a = n ? styleText(r, S_BAR_END) : "";
let u = "";
if (this.isNavigating || p) {
const d = p ? m : l;
u = d !== "" ? ` ${styleText("dim", d)}` : "";
} else
u = ` ${this.userInputWithCursor}`;
const V = this.filteredOptions.length !== o.length ? styleText(
"dim",
` (${this.filteredOptions.length} match${this.filteredOptions.length === 1 ? "" : "es"})`
) : "", y = this.filteredOptions.length === 0 && l ? [`${s}${styleText("yellow", "No matches found")}`] : [], b = this.state === "error" ? [`${s}${styleText("yellow", this.error)}`] : [];
n && i.push(`${s.trimEnd()}`), i.push(
`${s}${styleText("dim", "Search:")}${u}${V}`,
...y,
...b
);
const v = [
`${styleText("dim", "\u2191/\u2193")} to select`,
`${styleText("dim", "Enter:")} confirm`,
`${styleText("dim", "Type:")} to search`
], g = [`${s}${v.join(" \u2022 ")}`, a], O = this.filteredOptions.length === 0 ? [] : limitOptions({
cursor: this.cursor,
options: this.filteredOptions,
columnPadding: n ? 3 : 0,
// for `| ` when guide is shown
rowPadding: i.length + g.length,
style: (d, f) => $(
d,
d.disabled ? "disabled" : f ? "active" : "inactive"
),
maxItems: t.maxItems,
output: t.output
});
return [
...i,
...O.map((d) => `${s}${d}`),
...g
].join(`
`);
}
}
}
}).prompt(), autocompleteMultiselect = (t) => {
const c = (i, l, o, m) => {
const p = o.includes(i.value), $ = i.label ?? String(i.value ?? ""), r = i.hint && m !== void 0 && i.value === m ? styleText("dim", ` (${i.hint})`) : "", s = p ? styleText("green", S_CHECKBOX_SELECTED) : styleText("dim", S_CHECKBOX_INACTIVE);
return i.disabled ? `${styleText("gray", S_CHECKBOX_INACTIVE)} ${styleText(["strikethrough", "gray"], $)}` : l ? `${s} ${$}${r}` : `${s} ${styleText("dim", $)}`;
}, n = new AutocompletePrompt({
options: t.options,
multiple: true,
placeholder: t.placeholder,
filter: t.filter ?? ((i, l) => E(i, l)),
validate: () => {
if (t.required && n.selectedValues.length === 0)
return "Please select at least one item";
},
initialValue: t.initialValues,
signal: t.signal,
input: t.input,
output: t.output,
render() {
const i = t.withGuide ?? settings.withGuide, l = `${i ? `${styleText("gray", S_BAR)}
` : ""}${symbol(this.state)} ${t.message}
`, o = this.userInput, m = t.placeholder, p = o === "" && m !== void 0, $ = this.isNavigating || p ? styleText("dim", p ? m : o) : this.userInputWithCursor, r = this.options, s = this.filteredOptions.length !== r.length ? styleText(
"dim",
` (${this.filteredOptions.length} match${this.filteredOptions.length === 1 ? "" : "es"})`
) : "";
switch (this.state) {
case "submit":
return `${l}${i ? `${styleText("gray", S_BAR)} ` : ""}${styleText(
"dim",
`${this.selectedValues.length} items selected`
)}`;
case "cancel":
return `${l}${i ? `${styleText("gray", S_BAR)} ` : ""}${styleText(
["strikethrough", "dim"],
o
)}`;
default: {
const a = this.state === "error" ? "yellow" : "cyan", u = i ? `${styleText(a, S_BAR)} ` : "", V = i ? styleText(a, S_BAR_END) : "", y = [
`${styleText("dim", "\u2191/\u2193")} to navigate`,
`${styleText("dim", this.isNavigating ? "Space/Tab:" : "Tab:")} select`,
`${styleText("dim", "Enter:")} confirm`,
`${styleText("dim", "Type:")} to search`
], b = this.filteredOptions.length === 0 && o ? [`${u}${styleText("yellow", "No matches found")}`] : [], v = this.state === "error" ? [`${u}${styleText("yellow", this.error)}`] : [], g = [
...`${l}${i ? styleText(a, S_BAR) : ""}`.split(`
`),
`${u}${styleText("dim", "Search:")} ${$}${s}`,
...b,
...v
], O = [`${u}${y.join(" \u2022 ")}`, V], d = limitOptions({
cursor: this.cursor,
options: this.filteredOptions,
style: (f, _) => c(f, _, this.selectedValues, this.focusedValue),
maxItems: t.maxItems,
output: t.output,
rowPadding: g.length + O.length
});
return [
...g,
...d.map((f) => `${u}${f}`),
...O
].join(`
`);
}
}
}
});
return n.prompt();
};
const J = [
S_CORNER_TOP_LEFT,
S_CORNER_TOP_RIGHT,
S_CORNER_BOTTOM_LEFT,
S_CORNER_BOTTOM_RIGHT
], K = [S_BAR_START, S_BAR_START_RIGHT, S_BAR_END, S_BAR_END_RIGHT];
function A$1(n, e, t, o) {
let i = t, f = t;
return o === "center" ? i = Math.floor((e - n) / 2) : o === "right" && (i = e - n - t), f = e - i - n, [i, f];
}
const Q = (n) => n;
const box = (n = "", e = "", t) => {
const o = t?.output ?? process.stdout, i = getColumns(o), R = 1 * 2, u = t?.titlePadding ?? 1, h = t?.contentPadding ?? 2, w = t?.width === void 0 || t.width === "auto" ? 1 : Math.min(1, t.width), m = t?.withGuide ?? settings.withGuide ? `${S_BAR} ` : "", b = t?.formatBorder ?? Q, a = (t?.rounded ? J : K).map(b), _ = b(S_BAR_H), B = b(S_BAR), p = l(m), x = l(e), O = i - p;
let r = Math.floor(i * w) - p;
if (t?.width === "auto") {
const c = n.split(`
`);
let s = x + u * 2;
for (const G of c) {
const P = l(G) + h * 2;
P > s && (s = P);
}
const g = s + R;
g < r && (r = g);
}
r % 2 !== 0 && (r < O ? r++ : r--);
const d = r - R, S = d - u * 2, T = x > S ? `${e.slice(0, S - 3)}...` : e, [y, W] = A$1(
l(T),
d,
u,
t?.titleAlign
), L = wrapAnsi(n, d - h * 2, {
hard: true,
trim: false
});
o.write(
`${m}${a[0]}${_.repeat(y)}${T}${_.repeat(W)}${a[1]}
`
);
const E = L.split(`
`);
for (const c of E) {
const [s, g] = A$1(
l(c),
d,
h,
t?.contentAlign
);
o.write(
`${m}${B}${" ".repeat(s)}${c}${" ".repeat(g)}${B}
`
);
}
o.write(`${m}${a[2]}${_.repeat(d)}${a[3]}
`);
};
const confirm = (i) => {
const a = i.active ?? "Yes", s = i.inactive ?? "No";
return new ConfirmPrompt({
active: a,
inactive: s,
signal: i.signal,
input: i.input,
output: i.output,
initialValue: i.initialValue ?? true,
render() {
const e = i.withGuide ?? settings.withGuide, u = `${symbol(this.state)} `, l = e ? `${styleText("gray", S_BAR)} ` : "", f = wrapTextWithPrefix(
i.output,
i.message,
l,
u
), o = `${e ? `${styleText("gray", S_BAR)}
` : ""}${f}
`, c = this.value ? a : s;
switch (this.state) {
case "submit": {
const r = e ? `${styleText("gray", S_BAR)} ` : "";
return `${o}${r}${styleText("dim", c)}`;
}
case "cancel": {
const r = e ? `${styleText("gray", S_BAR)} ` : "";
return `${o}${r}${styleText(["strikethrough", "dim"], c)}${e ? `
${styleText("gray", S_BAR)}` : ""}`;
}
default: {
const r = e ? `${styleText("cyan", S_BAR)} ` : "", g = e ? styleText("cyan", S_BAR_END) : "";
return `${o}${r}${this.value ? `${styleText("green", S_RADIO_ACTIVE)} ${a}` : `${styleText("dim", S_RADIO_INACTIVE)} ${styleText("dim", a)}`}${i.vertical ? e ? `
${styleText("cyan", S_BAR)} ` : `
` : ` ${styleText("dim", "/")} `}${this.value ? `${styleText("dim", S_RADIO_INACTIVE)} ${styleText("dim", s)}` : `${styleText("green", S_RADIO_ACTIVE)} ${s}`}
${g}
`;
}
}
}
}).prompt();
};
const date = (e) => {
const r = e.validate;
return new DatePrompt({
...e,
validate(t) {
if (t === void 0)
return e.defaultValue !== void 0 ? void 0 : r ? runValidation(r, t) : settings.date.messages.required;
const o = (i) => i.toISOString().slice(0, 10);
if (e.minDate && o(t) < o(e.minDate))
return settings.date.messages.afterMin(e.minDate);
if (e.maxDate && o(t) > o(e.maxDate))
return settings.date.messages.beforeMax(e.maxDate);
if (r) return runValidation(r, t);
},
render() {
const t = (e?.withGuide ?? settings.withGuide) !== false, i = `${`${t ? `${styleText("gray", S_BAR)}
` : ""}${symbol(this.state)} `}${e.message}
`, l = this.state !== "initial" ? this.state : "active", d = b(this, l), c = this.value instanceof Date ? this.formattedValue : "";
switch (this.state) {
case "error": {
const a = this.error ? ` ${styleText("yellow", this.error)}` : "", s = t ? `${styleText("yellow", S_BAR)} ` : "", f = t ? styleText("yellow", S_BAR_END) : "";
return `${i.trim()}
${s}${d}
${f}${a}
`;
}
case "submit": {
const a = c ? ` ${styleText("dim", c)}` : "", s = t ? styleText("gray", S_BAR) : "";
return `${i}${s}${a}`;
}
case "cancel": {
const a = c ? ` ${styleText(["strikethrough", "dim"], c)}` : "", s = t ? styleText("gray", S_BAR) : "";
return `${i}${s}${a}${c.trim() ? `
${s}` : ""}`;
}
default: {
const a = t ? `${styleText("cyan", S_BAR)} ` : "", s = t ? styleText("cyan", S_BAR_END) : "", f = t ? `${styleText("cyan", S_BAR)} ` : "", g = this.inlineError ? `
${f}${styleText("yellow", this.inlineError)}` : "";
return `${i}${a}${d}${g}
${s}
`;
}
}
}
}).prompt();
};
function b(e, r) {
const t = e.segmentValues, o = e.segmentCursor;
if (r === "submit" || r === "cancel")
return e.formattedValue;
const i = styleText("gray", e.separator);
return e.segments.map((l, d) => {
const c = d === o.segmentIndex && !["submit", "cancel"].includes(r), a = p[l.type];
return x(t[l.type], { isActive: c, label: a });
}).join(i);
}
function x(e, r) {
const t = !e || e.replace(/_/g, "") === "";
return r.isActive ? styleText("inverse", t ? r.label : e.replace(/_/g, " ")) : t ? styleText("dim", r.label) : e.replace(/_/g, styleText("dim", " "));
}
const p = {
year: "yyyy",
month: "mm",
day: "dd"
};
const group = async (o, r) => {
const t = {}, p = Object.keys(o);
for (const e of p) {
const i = o[e], n = await i({ results: t })?.catch((a) => {
throw a;
});
if (typeof r?.onCancel == "function" && isCancel(n)) {
t[e] = "canceled", r.onCancel({ results: t });
continue;
}
t[e] = n;
}
return t;
};
const groupMultiselect = (u) => {
const { selectableGroups: h = true, groupSpacing: x = 0 } = u, m = (i, l, g = []) => {
const c = i.label ?? String(i.value), t = typeof i.group == "string", s = t && (g[g.indexOf(i) + 1] ?? { group: true }), o = t && s && s.group === true;
let n = "", a = "";
t && (h ? (n = o ? `${S_BAR_END} ` : `${S_BAR} `, a = o ? " " : `${S_BAR} `) : n = " ");
let r = "";
if (x > 0 && !t && (r = `
`.repeat(x)), l === "active")
return wrapTextWithPrefix(
u.output,
`${c}${i.hint ? ` ${styleText("dim", `(${i.hint})`)}` : ""}`,
`${r}${styleText("dim", n)} `,
`${r}${styleText("dim", n)}${styleText("cyan", S_CHECKBOX_ACTIVE)} `,
`${r}${styleText("dim", a)} `
);
if (l === "group-active")
return wrapTextWithPrefix(
u.output,
c,
`${r}${n} `,
`${r}${n}${styleText("cyan", S_CHECKBOX_ACTIVE)} `,
`${r}${a} `,
(d) => styleText("dim", d)
);
if (l === "group-active-selected")
return wrapTextWithPrefix(
u.output,
c,
`${r}${n} `,
`${r}${n}${styleText("green", S_CHECKBOX_SELECTED)} `,
`${r}${a} `,
(d) => styleText("dim", d)
);
if (l === "selected") {
const d = t || h ? styleText("green", S_CHECKBOX_SELECTED) : "";
return wrapTextWithPrefix(
u.output,
`${c}${i.hint ? ` (${i.hint})` : ""}`,
`${r}${styleText("dim", n)} `,
`${r}${styleText("dim", n)}${d} `,
`${r}${styleText("dim", a)} `,
(V) => styleText("dim", V)
);
}
if (l === "cancelled")
return `${styleText(["strikethrough", "dim"], c)}`;
if (l === "active-selected")
return wrapTextWithPrefix(
u.output,
`${c}${i.hint ? ` ${styleText("dim", `(${i.hint})`)}` : ""}`,
`${r}${styleText("dim", n)} `,
`${r}${styleText("dim", n)}${styleText("green", S_CHECKBOX_SELECTED)} `,
`${r}${styleText("dim", a)} `
);
if (l === "submitted")
return `${styleText("dim", c)}`;
const f = t || h ? styleText("dim", S_CHECKBOX_INACTIVE) : "";
return wrapTextWithPrefix(
u.output,
c,
`${r}${styleText("dim", n)} `,
`${r}${styleText("dim", n)}${f} `,
`${r}${styleText("dim", a)} `,
(d) => styleText("dim", d)
);
}, y = u.required ?? true;
return new GroupMultiSelectPrompt({
options: u.options,
signal: u.signal,
input: u.input,
output: u.output,
initialValues: u.initialValues,
required: y,
cursorAt: u.cursorAt,
selectableGroups: h,
validate(i) {
if (y && (i === void 0 || i.length === 0))
return `Please select at least one option.
${styleText(
"reset",
styleText(
"dim",
`Press ${styleText(["gray", "bgWhite", "inverse"], " space ")} to select, ${styleText(
"gray",
styleText(["bgWhite", "inverse"], " enter ")
)} to submit`
)
)}`;
},
render() {
const i = u.withGuide ?? settings.withGuide, l = `${i ? `${styleText("gray", S_BAR)}
` : ""}${symbol(this.state)} ${u.message}
`, g = this.value ?? [], c = (t, s) => {
const o = this.options, n = g.includes(t.value) || t.group === true && this.isGroupSelected(`${t.value}`);
return !s && typeof t.group == "string" && this.options[this.cursor].value === t.group ? m(t, n ? "group-active-selected" : "group-active", o) : s && n ? m(t, "active-selected", o) : n ? m(t, "selected", o) : m(t, s ? "active" : "inactive", o);
};
switch (this.state) {
case "submit": {
const t = this.options.filter(({ value: o }) => g.includes(o)).map((o) => m(o, "submitted")), s = t.length === 0 ? "" : ` ${t.join(styleText("dim", ", "))}`;
return `${l}${i ? styleText("gray", S_BAR) : ""}${s}`;
}
case "cancel": {
const t = this.options.filter(({ value: s }) => g.includes(s)).map((s) => m(s, "cancelled")).join(styleText("dim", ", "));
return `${l}${i ? `${styleText("gray", S_BAR)} ` : ""}${t.trim() ? `${t}${i ? `
${styleText("gray", S_BAR)}` : ""}` : ""}`;
}
case "error": {
const t = i ? `${styleText("yellow", S_BAR)} ` : "", s = this.error.split(`
`).map(
(r, f) => f === 0 ? `${i ? `${styleText("yellow", S_BAR_END)} ` : ""}${styleText("yellow", r)}` : ` ${r}`
).join(`
`), o = l.split(`
`).length, n = s.split(`
`).length + 1, a = limitOptions({
output: u.output,
options: this.options,
cursor: this.cursor,
maxItems: u.maxItems,
columnPadding: t.length,
rowPadding: o + n,
style: c
}).join(`
${t}`);
return `${l}${t}${a}
${s}
`;
}
default: {
const t = i ? `${styleText("cyan", S_BAR)} ` : "", s = l.split(`
`).length, o = (i ? 1 : 0) + 1, n = limitOptions({
output: u.output,
options: this.options,
cursor: this.cursor,
maxItems: u.maxItems,
columnPadding: t.length,
rowPadding: s + o,
style: c
}).join(`
${t}`);
return `${l}${t}${n}
${i ? styleText("cyan", S_BAR_END) : ""}
`;
}
}
}
}).prompt();
};
const log = {
message: (s = [], {
symbol: e = styleText("gray", S_BAR),
secondarySymbol: r = styleText("gray", S_BAR),
output: m = process.stdout,
spacing: l = 1,
withGuide: c
} = {}) => {
const t = [], o = c ?? settings.withGuide, f = o ? r : "", O = o ? `${e} ` : "", u = o ? `${r} ` : "";
for (let i = 0; i < l; i++)
t.push(f);
const g = Array.isArray(s) ? s : s.split(`
`);
if (g.length > 0) {
const [i, ...y] = g;
i.length > 0 ? t.push(`${O}${i}`) : t.push(o ? e : "");
for (const p of y)
p.length > 0 ? t.push(`${u}${p}`) : t.push(o ? r : "");
}
m.write(`${t.join(`
`)}
`)},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)}
`);
},
info: (s, e) => {
log.message(s, { ...e, symbol: styleText("blue", S_INFO) });
},
success: (s, e) => {
log.message(s, { ...e, symbol: styleText("green", S_SUCCESS) });
},
step: (s, e) => {
log.message(s, { ...e, symbol: styleText("green", S_STEP_SUBMIT) });
},
warn: (s, e) => {
log.message(s, { ...e, symbol: styleText("yellow", S_WARN) });
},
/** alias for `log.warn()`. */
warning: (s, e) => {
log.warn(s, e);
},
error: (s, e) => {
log.message(s, { ...e, symbol: styleText("red", S_ERROR) });
}
};
`)},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}
const cancel = (o = "", t) => {
const i = t?.output ?? process.stdout, e = t?.withGuide ?? settings.withGuide ? `${styleText("gray", S_BAR_END)} ` : "";
i.write(`${e}${styleText("red", o)}
`)},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}
`,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?`
${e(this.focused==="submit"?"cyan":"dim","[ submit ]")}`:"";switch(this.state){case"error":{const c=`${e("yellow",$)} `,o=i?E(t.output,u,c,void 0):u,l=e("yellow",x);return`${s}${o}
${l} ${e("yellow",this.error)}${a}
`}case"submit":{const c=`${e("gray",$)} `,o=i?E(t.output,n,c,void 0,void 0,l=>e("dim",l)):n?e("dim",n):"";return`${s}${o}`}case"cancel":{const c=`${e("gray",$)} `,o=i?E(t.output,n,c,void 0,void 0,l=>e(["strikethrough","dim"],l)):n?e(["strikethrough","dim"],n):"";return`${s}${o}`}default:{const c=i?`${e("cyan",$)} `:"",o=i?e("cyan",x):"",l=i?E(t.output,u,c):u;return`${s}${l}
${o}${a}
`}}}}).prompt(),Q=(t,i)=>t.split(`
`).map(s=>i(s)).join(`
`),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}
`,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?`
${e("gray",$)}`:""}`}case"error":{const o=r?`${e("yellow",$)} `:"",l=this.error.split(`
`).map((p,f)=>f===0?`${r?`${e("yellow",x)} `:""}${e("yellow",p)}`:` ${p}`).join(`
`),d=n.split(`
`).length,g=l.split(`
`).length+1;return`${n}${o}${F({output:t.output,options:this.options,cursor:this.cursor,maxItems:t.maxItems,columnPadding:o.length,rowPadding:d+g,style:c}).join(`
${o}`)}
`);
}, intro = (o = "", t) => {
const i = t?.output ?? process.stdout, e = t?.withGuide ?? settings.withGuide ? `${styleText("gray", S_BAR_START)} ` : "";
i.write(`${e}${o}
`);
}, outro = (o = "", t) => {
const i = t?.output ?? process.stdout, e = t?.withGuide ?? settings.withGuide ? `${styleText("gray", S_BAR)}
${styleText("gray", S_BAR_END)} ` : "";
i.write(`${e}${o}
`);
};
const multiline = (e) => new MultiLinePrompt({
validate: e.validate,
placeholder: e.placeholder,
defaultValue: e.defaultValue,
initialValue: e.initialValue,
showSubmit: e.showSubmit,
output: e.output,
signal: e.signal,
input: e.input,
render() {
const i = e?.withGuide ?? settings.withGuide, o = `${`${i ? `${styleText("gray", S_BAR)}
` : ""}${symbol(this.state)} `}${e.message}
`, h = e.placeholder ? styleText("inverse", e.placeholder[0]) + styleText("dim", e.placeholder.slice(1)) : styleText(["inverse", "hidden"], "_"), a = this.userInput ? this.userInputWithCursor : h, s = this.value ?? "", c = e.showSubmit ? `
${styleText(this.focused === "submit" ? "cyan" : "dim", "[ submit ]")}` : "";
switch (this.state) {
case "error": {
const n = `${styleText("yellow", S_BAR)} `, r = i ? wrapTextWithPrefix(e.output, a, n, void 0) : a, u = styleText("yellow", S_BAR_END);
return `${o}${r}
${u} ${styleText("yellow", this.error)}${c}
`;
}
case "submit": {
const n = `${styleText("gray", S_BAR)} `, r = i ? wrapTextWithPrefix(
e.output,
s,
n,
void 0,
void 0,
(u) => styleText("dim", u)
) : s ? styleText("dim", s) : "";
return `${o}${r}`;
}
case "cancel": {
const n = `${styleText("gray", S_BAR)} `, r = i ? wrapTextWithPrefix(
e.output,
s,
n,
void 0,
void 0,
(u) => styleText(["strikethrough", "dim"], u)
) : s ? styleText(["strikethrough", "dim"], s) : "";
return `${o}${r}`;
}
default: {
const n = i ? `${styleText("cyan", S_BAR)} ` : "", r = i ? styleText("cyan", S_BAR_END) : "", u = i ? wrapTextWithPrefix(e.output, a, n) : a;
return `${o}${u}
${r}${c}
`;
}
}
}
}).prompt();
const d = (n, a) => n.split(`
`).map((m) => a(m)).join(`
`);
const multiselect = (n) => {
const a = (t, o) => {
const r = t.label ?? String(t.value);
return o === "disabled" ? `${styleText("gray", S_CHECKBOX_INACTIVE)} ${d(r, (l) => styleText(["strikethrough", "gray"], l))}${t.hint ? ` ${styleText("dim", `(${t.hint ?? "disabled"})`)}` : ""}` : o === "active" ? `${styleText("cyan", S_CHECKBOX_ACTIVE)} ${r}${t.hint ? ` ${styleText("dim", `(${t.hint})`)}` : ""}` : o === "selected" ? `${styleText("green", S_CHECKBOX_SELECTED)} ${d(r, (l) => styleText("dim", l))}${t.hint ? ` ${styleText("dim", `(${t.hint})`)}` : ""}` : o === "cancelled" ? `${d(r, (l) => styleText(["strikethrough", "dim"], l))}` : o === "active-selected" ? `${styleText("green", S_CHECKBOX_SELECTED)} ${r}${t.hint ? ` ${styleText("dim", `(${t.hint})`)}` : ""}` : o === "submitted" ? `${d(r, (l) => styleText("dim", l))}` : `${styleText("dim", S_CHECKBOX_INACTIVE)} ${d(r, (l) => styleText("dim", l))}`;
}, m = n.required ?? true;
return new MultiSelectPrompt({
options: n.options,
signal: n.signal,
input: n.input,
output: n.output,
initialValues: n.initialValues,
required: m,
cursorAt: n.cursorAt,
validate(t) {
if (m && (t === void 0 || t.length === 0))
return `Please select at least one option.
${styleText(
"reset",
styleText(
"dim",
`Press ${styleText(["gray", "bgWhite", "inverse"], " space ")} to select, ${styleText(
"gray",
styleText("bgWhite", styleText("inverse", " enter "))
)} to submit`
)
)}`;
},
render() {
const t = n.withGuide ?? settings.withGuide, o = wrapTextWithPrefix(
n.output,
n.message,
t ? `${symbolBar(this.state)} ` : "",
`${symbol(this.state)} `
), r = `${t ? `${styleText("gray", S_BAR)}
` : ""}${o}
`, l = this.value ?? [], g = (i, u) => {
if (i.disabled)
return a(i, "disabled");
const s = l.includes(i.value);
return u && s ? a(i, "active-selected") : s ? a(i, "selected") : a(i, u ? "active" : "inactive");
};
switch (this.state) {
case "submit": {
const i = this.options.filter(({ value: s }) => l.includes(s)).map((s) => a(s, "submitted")).join(styleText("dim", ", ")) || styleText("dim", "none"), u = wrapTextWithPrefix(
n.output,
i,
t ? `${styleText("gray", S_BAR)} ` : ""
);
return `${r}${u}`;
}
case "cancel": {
const i = this.options.filter(({ value: s }) => l.includes(s)).map((s) => a(s, "cancelled")).join(styleText("dim", ", "));
if (i.trim() === "")
return `${r}${styleText("gray", S_BAR)}`;
const u = wrapTextWithPrefix(
n.output,
i,
t ? `${styleText("gray", S_BAR)} ` : ""
);
return `${r}${u}${t ? `
${styleText("gray", S_BAR)}` : ""}`;
}
case "error": {
const i = t ? `${styleText("yellow", S_BAR)} ` : "", u = this.error.split(`
`).map(
(h, x) => x === 0 ? `${t ? `${styleText("yellow", S_BAR_END)} ` : ""}${styleText("yellow", h)}` : ` ${h}`
).join(`
`), s = r.split(`
`).length, v = u.split(`
`).length + 1;
return `${r}${i}${limitOptions({
output: n.output,
options: this.options,
cursor: this.cursor,
maxItems: n.maxItems,
columnPadding: i.length,
rowPadding: s + v,
style: g
}).join(`
${i}`)}
${u}
`;
}
default: {
const i = t ? `${styleText("cyan", S_BAR)} ` : "", u = r.split(`
`).length, s = t ? 2 : 1;
return `${r}${i}${limitOptions({
output: n.output,
options: this.options,
cursor: this.cursor,
maxItems: n.maxItems,
columnPadding: i.length,
rowPadding: u + s,
style: g
}).join(`
${i}`)}
${t ? styleText("cyan", S_BAR_END) : ""}
`;
}
}
}
}).prompt();
};
const W$1 = (o) => styleText("dim", o), C = (o, e, s) => {
const a = {
hard: true,
trim: false
}, i = wrapAnsi(o, e, a).split(`
`), c = i.reduce((n, r) => Math.max(l(r), n), 0), u = i.map(s).reduce((n, r) => Math.max(l(r), n), 0), g = e - (u - c);
return wrapAnsi(o, g, a);
};
const note = (o = "", e = "", s) => {
const a = s?.output ?? process$1.stdout, i = s?.withGuide ?? settings.withGuide, c = s?.format ?? W$1, g = ["", ...C(o, getColumns(a) - 6, c).split(`
`).map(c), ""], n = l(e), r = Math.max(
g.reduce((m, F) => {
const O = l(F);
return O > m ? O : m;
}, 0),
n
) + 2, h = g.map(
(m) => `${styleText("gray", S_BAR)} ${m}${" ".repeat(r - l(m))}${styleText("gray", S_BAR)}`
).join(`
`), T = i ? `${styleText("gray", S_BAR)}
` : "", l$1 = i ? S_CONNECT_LEFT : S_CORNER_BOTTOM_LEFT;
a.write(
`${T}${styleText("green", S_STEP_SUBMIT)} ${styleText("reset", e)} ${styleText(
"gray",
S_BAR_H.repeat(Math.max(r - n - 1, 1)) + S_CORNER_TOP_RIGHT
)}
${h}
${styleText("gray", l$1 + S_BAR_H.repeat(r + 2) + S_CORNER_BOTTOM_RIGHT)}
`
);
};
const password = (r) => new PasswordPrompt({
validate: r.validate,
mask: r.mask ?? S_PASSWORD_MASK,
signal: r.signal,
input: r.input,
output: r.output,
render() {
const e = r.withGuide ?? settings.withGuide, o = `${e ? `${styleText("gray", S_BAR)}
` : ""}${symbol(this.state)} ${r.message}
`, c = this.userInputWithCursor, i = this.masked;
switch (this.state) {
case "error": {
const s = e ? `${styleText("yellow", S_BAR)} ` : "", n = e ? `${styleText("yellow", S_BAR_END)} ` : "", l = i ?? "";
return r.clearOnError && this.clear(), `${o.trim()}
${s}${l}
${n}${styleText("yellow", this.error)}
`;
}
case "submit": {
const s = e ? `${styleText("gray", S_BAR)} ` : "", n = i ? styleText("dim", i) : "";
return `${o}${s}${n}`;
}
case "cancel": {
const s = e ? `${styleText("gray", S_BAR)} ` : "", n = i ? styleText(["strikethrough", "dim"], i) : "";
return `${o}${s}${n}${i && e ? `
${styleText("gray", S_BAR)}` : ""}`;
}
default: {
const s = e ? `${styleText("cyan", S_BAR)} ` : "", n = e ? styleText("cyan", S_BAR_END) : "";
return `${o}${s}${c}
${n}
`;
}
}
}
}).prompt();
const path = (e) => {
const a = e.validate;
return autocomplete({
...e,
initialUserInput: e.initialValue ?? e.root ?? process.cwd(),
maxItems: 5,
validate(t) {
if (!Array.isArray(t)) {
if (!t)
return "Please select a path";
if (a)
return runValidation(a, t);
}
},
options() {
const t = this.userInput;
if (t === "")
return [];
try {
let i;
existsSync(t) ? lstatSync(t).isDirectory() && (!e.directory || t.endsWith("/")) ? i = t : i = dirname(t) : i = dirname(t);
const c = t.length > 1 && t.endsWith("/") ? t.slice(0, -1) : t;
return readdirSync(i).map((r) => {
const n = join(i, r), m = lstatSync(n);
return {
name: r,
path: n,
isDirectory: m.isDirectory()
};
}).filter(
({ path: r, isDirectory: n }) => r.startsWith(c) && (n || !e.directory)
).map((r) => ({
value: r.path
}));
} catch {
return [];
}
}
});
};
const W = (l) => styleText("magenta", l);
const spinner = ({
indicator: l = "dots",
onCancel: h,
output: n = process.stdout,
cancelMessage: G,
errorMessage: O,
frames: E = unicode ? ["\u25D2", "\u25D0", "\u25D3", "\u25D1"] : ["\u2022", "o", "O", "0"],
delay: F = unicode ? 80 : 120,
signal: m,
...I
} = {}) => {
const u = isCI();
let M, T, d = false, S = false, s = "", p, w = performance.now();
const x = getColumns(n), k = I?.styleFrame ?? W, g = (e) => {
const r = e > 1 ? O ?? settings.messages.error : G ?? settings.messages.cancel;
S = e === 1, d && (a(r, e), S && typeof h == "function" && h());
}, f = () => g(2), i = () => g(1), A = () => {
process.on("uncaughtExceptionMonitor", f), process.on("unhandledRejection", f), process.on("SIGINT", i), process.on("SIGTERM", i), process.on("exit", g), m && m.addEventListener("abort", i);
}, H = () => {
process.removeListener("uncaughtExceptionMonitor", f), process.removeListener("unhandledRejection", f), process.removeListener("SIGINT", i), process.removeListener("SIGTERM", i), process.removeListener("exit", g), m && m.removeEventListener("abort", i);
}, y = () => {
if (p === void 0) return;
u && n.write(`
`);
const r = wrapAnsi(p, x, {
hard: true,
trim: false
}).split(`
`);
r.length > 1 && n.write(cursor.up(r.length - 1)), n.write(cursor.to(0)), n.write(erase.down());
}, C = (e) => e.replace(/\.+$/, ""), _ = (e) => {
const r = (performance.now() - e) / 1e3, t = Math.floor(r / 60), o = Math.floor(r % 60);
return t > 0 ? `[${t}m ${o}s]` : `[${o}s]`;
}, N = I.withGuide ?? settings.withGuide, P = (e = "") => {
d = true, M = block({ output: n }), s = C(e), w = performance.now(), N && n.write(`${styleText("gray", S_BAR)}
`);
let r = 0, t = 0;
A(), T = setInterval(() => {
if (u && s === p)
return;
y(), p = s;
const o = k(E[r]);
let v;
if (u)
v = `${o} ${s}...`;
else if (l === "timer")
v = `${o} ${s} ${_(w)}`;
else {
const B = ".".repeat(Math.floor(t)).slice(0, 3);
v = `${o} ${s}${B}`;
}
const j = wrapAnsi(v, x, {
hard: true,
trim: false
});
n.write(j), r = r + 1 < E.length ? r + 1 : 0, t = t < 4 ? t + 0.125 : 0;
}, F);
}, a = (e = "", r = 0, t = false) => {
if (!d) return;
d = false, clearInterval(T), y();
const o = r === 0 ? styleText("green", S_STEP_SUBMIT) : r === 1 ? styleText("red", S_STEP_CANCEL) : styleText("red", S_STEP_ERROR);
s = e ?? s, t || (l === "timer" ? n.write(`${o} ${s} ${_(w)}
`) : n.write(`${o} ${s}
`)), H(), M();
};
return {
start: P,
stop: (e = "") => a(e, 0),
message: (e = "") => {
s = C(e ?? s);
},
cancel: (e = "") => a(e, 1),
error: (e = "") => a(e, 2),
clear: () => a("", 0, true),
get isCancelled() {
return S;
}
};
};
const u = {
light: unicodeOr("\u2500", "-"),
heavy: unicodeOr("\u2501", "="),
block: unicodeOr("\u2588", "#")
};
function progress({
style: o = "heavy",
max: d = 100,
size: v = 40,
...x
} = {}) {
const r = spinner(x);
let a = 0, n = "";
const c = Math.max(1, d), l = Math.max(1, v), S = (t) => {
switch (t) {
case "initial":
case "active":
return (e) => styleText("magenta", e);
case "error":
case "cancel":
return (e) => styleText("red", e);
case "submit":
return (e) => styleText("green", e);
default:
return (e) => styleText("magenta", e);
}
}, p = (t, e) => {
const m = Math.floor(a / c * l);
return `${S(t)(u[o].repeat(m))}${styleText("dim", u[o].repeat(l - m))} ${e}`;
}, h = (t = "") => {
n = t, r.start(p("initial", t));
}, g = (t = 1, e) => {
a = Math.min(c, t + a), r.message(p("active", e ?? n)), n = e ?? n;
};
return {
start: h,
stop: r.stop,
cancel: r.cancel,
error: r.error,
clear: r.clear,
advance: g,
isCancelled: r.isCancelled,
message: (t) => g(0, t)
};
}
const c = (e, a) => e.includes(`
`) ? e.split(`
`).map((t) => a(t)).join(`
`) : a(e);
const select = (e) => {
const a = (t, d) => {
const s = t.label ?? String(t.value);
switch (d) {
case "disabled":
return `${styleText("gray", S_RADIO_INACTIVE)} ${c(s, (n) => styleText("gray", n))}${t.hint ? ` ${styleText("dim", `(${t.hint ?? "disabled"})`)}` : ""}`;
case "selected":
return `${c(s, (n) => styleText("dim", n))}`;
case "active":
return `${styleText("green", S_RADIO_ACTIVE)} ${s}${t.hint ? ` ${styleText("dim", `(${t.hint})`)}` : ""}`;
case "cancelled":
return `${c(s, (n) => styleText(["strikethrough", "dim"], n))}`;
default:
return `${styleText("dim", S_RADIO_INACTIVE)} ${c(s, (n) => styleText("dim", n))}`;
}
};
return new SelectPrompt({
options: e.options,
signal: e.signal,
input: e.input,
output: e.output,
initialValue: e.initialValue,
render() {
const t = e.withGuide ?? settings.withGuide, d = `${symbol(this.state)} `, s = `${symbolBar(this.state)} `, n = wrapTextWithPrefix(
e.output,
e.message,
s,
d
), u = `${t ? `${styleText("gray", S_BAR)}
` : ""}${n}
`;
switch (this.state) {
case "submit": {
const r = t ? `${styleText("gray", S_BAR)} ` : "", l = wrapTextWithPrefix(
e.output,
a(this.options[this.cursor], "selected"),
r
);
return `${u}${l}`;
}
case "cancel": {
const r = t ? `${styleText("gray", S_BAR)} ` : "", l = wrapTextWithPrefix(
e.output,
a(this.options[this.cursor], "cancelled"),
r
);
return `${u}${l}${t ? `
${styleText("gray", S_BAR)}` : ""}`;
}
default: {
const r = t ? `${styleText("cyan", S_BAR)} ` : "", l = t ? styleText("cyan", S_BAR_END) : "", g = u.split(`
`).length, h = t ? 2 : 1;
return `${u}${r}${limitOptions({
output: e.output,
cursor: this.cursor,
options: this.options,
maxItems: e.maxItems,
columnPadding: r.length,
rowPadding: g + h,
style: (p, b) => a(p, p.disabled ? "disabled" : b ? "active" : "inactive")
}).join(`
${r}`)}
${l}
`}default:{const o=r?`${e("cyan",$)} `:"",l=n.split(`
`).length,d=r?2:1;return`${n}${o}${F({output:t.output,options:this.options,cursor:this.cursor,maxItems:t.maxItems,columnPadding:o.length,rowPadding:l+d,style:c}).join(`
${o}`)}
${r?e("cyan",x):""}
`}}}}).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?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)+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}
`,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()}
${n}${c}
${a}${e("yellow",this.error)}
`}case"submit":{const n=i?`${e("gray",$)} `:"",a=u?e("dim",u):"";return`${s}${n}${a}`}case"cancel":{const n=i?`${e("gray",$)} `:"",a=u?e(["strikethrough","dim"],u):"";return`${s}${n}${a}${u&&i?`
${e("gray",$)}`:""}`}default:{const n=i?`${e("cyan",$)} `:"",a=i?e("cyan",x):"";return`${s}${n}${r}
${a}
`}}}}).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(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}}},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),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}
`;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?`
${e("gray",$)}`:""}`}default:{const c=s?`${e("cyan",$)} `:"",o=s?e("cyan",x):"",l=a.split(`
`).length,d=s?2:1;return`${a}${c}${F({output:t.output,cursor:this.cursor,options:this.options,maxItems:t.maxItems,columnPadding:c.length,rowPadding:l+d,style:(g,p)=>i(g,g.disabled?"disabled":p?"active":"inactive")}).join(`
${c}`)}
${o}
`}}}}).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}
`;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?`
${e("gray",$)}`:""}`}default:{const u=s?`${e("cyan",$)} `:"",n=s?e("cyan",x):"",a=this.options.map((c,o)=>E(t.output,i(c,o===this.cursor?"active":"inactive"),u)).join(`
`);return`${r}${a}
${n}
`}}}}).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,`
${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}
`);for(let m=0;m<u;m++)i.write(`${r}
`);const o=[{value:"",full:""}];let l=!1;const d=m=>{if(o.length===0)return;let y=0;m&&(y+=u+2);for(const v of o){const{value:C,result:S}=v;let b=S?.message??C;if(b.length===0)continue;S===void 0&&v.header!==void 0&&v.header!==""&&(b+=`
${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(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+=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=""}}},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}
`,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}${u}
${o}${a}
`}case"submit":{const a=n?` ${e("dim",n)}`:"",c=i?e("gray",$):"";return`${s}${c}${a}`}case"cancel":{const a=n?` ${e(["strikethrough","dim"],n)}`:"",c=i?e("gray",$):"";return`${s}${c}${a}${n.trim()?`
${c}`:""}`}default:{const a=i?`${e("cyan",$)} `:"",c=i?e("cyan",x):"";return`${s}${a}${u}
${c}
`}}}}).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
`;
}
}
}
}).prompt();
};
const selectKey = (t) => {
const l = (e, a = "inactive") => {
const n = e.label ?? String(e.value);
return a === "selected" ? `${styleText("dim", n)}` : a === "cancelled" ? `${styleText(["strikethrough", "dim"], n)}` : a === "active" ? `${styleText(["bgCyan", "gray"], ` ${e.value} `)} ${n}${e.hint ? ` ${styleText("dim", `(${e.hint})`)}` : ""}` : `${styleText(["gray", "bgWhite", "inverse"], ` ${e.value} `)} ${n}${e.hint ? ` ${styleText("dim", `(${e.hint})`)}` : ""}`;
};
return new SelectKeyPrompt({
options: t.options,
signal: t.signal,
input: t.input,
output: t.output,
initialValue: t.initialValue,
caseSensitive: t.caseSensitive,
render() {
const e = t.withGuide ?? settings.withGuide, a = `${e ? `${styleText("gray", S_BAR)}
` : ""}${symbol(this.state)} ${t.message}
`;
switch (this.state) {
case "submit": {
const n = e ? `${styleText("gray", S_BAR)} ` : "", s = this.options.find((u) => u.value === this.value) ?? t.options[0], c = wrapTextWithPrefix(
t.output,
l(s, "selected"),
n
);
return `${a}${c}`;
}
case "cancel": {
const n = e ? `${styleText("gray", S_BAR)} ` : "", s = wrapTextWithPrefix(
t.output,
l(this.options[0], "cancelled"),
n
);
return `${a}${s}${e ? `
${styleText("gray", S_BAR)}` : ""}`;
}
default: {
const n = e ? `${styleText("cyan", S_BAR)} ` : "", s = e ? styleText("cyan", S_BAR_END) : "", c = this.options.map(
(u, $) => wrapTextWithPrefix(
t.output,
l(u, $ === this.cursor ? "active" : "inactive"),
n
)
).join(`
`);
return `${a}${c}
${s}
`;
}
}
}
}).prompt();
};
const i = `${styleText("gray", S_BAR)} `;
const stream = {
message: async (e, { symbol: l = styleText("gray", S_BAR) } = {}) => {
process.stdout.write(`${styleText("gray", S_BAR)}
${l} `);
let s = 3;
for await (let r of e) {
r = r.replace(/\n/g, `
${i}`), r.includes(`
`) && (s = 3 + stripVTControlCharacters(r.slice(r.lastIndexOf(`
`))).length);
const o = stripVTControlCharacters(r).length;
s + o < process.stdout.columns ? (s += o, process.stdout.write(r)) : (process.stdout.write(`
${i}${r.trimStart()}`), s = 3 + stripVTControlCharacters(r.trimStart()).length);
}
process.stdout.write(`
`);
},
info: (e) => stream.message(e, { symbol: styleText("blue", S_INFO) }),
success: (e) => stream.message(e, { symbol: styleText("green", S_SUCCESS) }),
step: (e) => stream.message(e, { symbol: styleText("green", S_STEP_SUBMIT) }),
warn: (e) => stream.message(e, { symbol: styleText("yellow", S_WARN) }),
/** alias for `log.warn()`. */
warning: (e) => stream.warn(e),
error: (e) => stream.message(e, { symbol: styleText("red", S_ERROR) })
};
const tasks = async (o, e) => {
for (const t of o) {
if (t.enabled === false) continue;
const s = spinner(e);
s.start(t.title);
const n = await t.task(s.message);
s.stop(n || t.title);
}
};
const A = (l) => l.replace(/\x1b\[(?:\d+;)*\d*[ABCDEFGHfJKSTsu]|\x1b\[(s|u)/g, "");
const taskLog = (l) => {
const r = l.output ?? process.stdout, O = getColumns(r), i = styleText("gray", S_BAR), p = l.spacing ?? 1, k = 3, m = l.retainLog === true, d = !isCI() && isTTY(r);
r.write(`${i}
`), r.write(`${styleText("green", S_STEP_SUBMIT)} ${l.title}
`);
for (let e = 0; e < p; e++)
r.write(`${i}
`);
const n = [
{
value: "",
full: ""
}
];
let v = false;
const f = (e) => {
if (n.length === 0)
return;
let s = 0;
e && (s += p + 2);
for (const t of n) {
const { value: o, result: a } = t;
let g = a?.message ?? o;
if (g.length === 0)
continue;
a === void 0 && t.header !== void 0 && t.header !== "" && (g += `
${t.header}`);
const x = g.split(`
`).reduce((b, w) => w === "" ? b + 1 : b + Math.ceil((w.length + k) / O), 0);
s += x;
}
s > 0 && (s += 1, r.write(erase.lines(s)));
}, h = (e, s, t) => {
const o = t ? `${e.full}
${e.value}` : e.value;
e.header !== void 0 && e.header !== "" && log.message(
e.header.split(`
`).map((a) => styleText("bold", a)),
{
output: r,
secondarySymbol: i,
symbol: i,
spacing: 0
}
), log.message(
o.split(`
`).map((a) => styleText("dim", a)),
{
output: r,
secondarySymbol: i,
symbol: i,
spacing: s ?? p
}
);
}, T = () => {
for (const e of n) {
const { header: s, value: t, full: o } = e;
(s === void 0 || s.length === 0) && t.length === 0 || h(e, void 0, m === true && o.length > 0);
}
}, L = (e, s, t) => {
if (f(false), (t?.raw !== true || !v) && e.value !== "" && (e.value += `
`), e.value += A(s), v = t?.raw === true, l.limit !== void 0) {
const o = e.value.split(`
`), a = o.length - l.limit;
if (a > 0) {
const g = o.splice(0, a);
m && (e.full += (e.full === "" ? "" : `
`) + g.join(`
`));
}
e.value = o.join(`
`);
}
d && y();
}, y = () => {
for (const e of n)
e.result ? e.result.status === "error" ? log.error(e.result.message, { output: r, secondarySymbol: i, spacing: 0 }) : log.success(e.result.message, { output: r, secondarySymbol: i, spacing: 0 }) : e.value !== "" && h(e, 0);
}, B = (e, s) => {
f(false), e.result = s, d && y();
};
return {
message(e, s) {
L(n[0], e, s);
},
group(e) {
const s = {
header: e,
value: "",
full: ""
};
return n.push(s), {
message(t, o) {
L(s, t, o);
},
error(t) {
B(s, {
status: "error",
message: t
});
},
success(t) {
B(s, {
status: "success",
message: t
});
}
};
},
error(e, s) {
f(true), log.error(e, { output: r, secondarySymbol: i, spacing: 1 }), s?.showLog !== false && T(), n.splice(1, n.length - 1), n[0].value = "", n[0].full = "";
},
success(e, s) {
f(true), log.success(e, { output: r, secondarySymbol: i, spacing: 1 }), s?.showLog === true && T(), n.splice(1, n.length - 1), n[0].value = "", n[0].full = "";
}
};
};
const text = (t) => new TextPrompt({
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 ?? settings.withGuide, s = `${`${i ? `${styleText("gray", S_BAR)}
` : ""}${symbol(this.state)} `}${t.message}
`, c = t.placeholder ? styleText("inverse", t.placeholder[0]) + styleText("dim", t.placeholder.slice(1)) : styleText(["inverse", "hidden"], "_"), o = this.userInput ? this.userInputWithCursor : c, a = this.value ?? "";
switch (this.state) {
case "error": {
const n = this.error ? ` ${styleText("yellow", this.error)}` : "", r = i ? `${styleText("yellow", S_BAR)} ` : "", d = i ? styleText("yellow", S_BAR_END) : "";
return `${s.trim()}
${r}${o}
${d}${n}
`;
}
case "submit": {
const n = a ? ` ${styleText("dim", a)}` : "", r = i ? styleText("gray", S_BAR) : "";
return `${s}${r}${n}`;
}
case "cancel": {
const n = a ? ` ${styleText(["strikethrough", "dim"], a)}` : "", r = i ? styleText("gray", S_BAR) : "";
return `${s}${r}${n}${a.trim() ? `
${r}` : ""}`;
}
default: {
const n = i ? `${styleText("cyan", S_BAR)} ` : "", r = i ? styleText("cyan", S_BAR_END) : "";
return `${s}${n}${o}
${r}
`;
}
}
}
}).prompt();
export { S_BAR, S_BAR_END, S_BAR_END_RIGHT, S_BAR_H, S_BAR_START, S_BAR_START_RIGHT, S_CHECKBOX_ACTIVE, S_CHECKBOX_INACTIVE, S_CHECKBOX_SELECTED, S_CONNECT_LEFT, S_CORNER_BOTTOM_LEFT, S_CORNER_BOTTOM_RIGHT, S_CORNER_TOP_LEFT, S_CORNER_TOP_RIGHT, S_ERROR, S_INFO, S_PASSWORD_MASK, S_RADIO_ACTIVE, S_RADIO_INACTIVE, S_STEP_ACTIVE, S_STEP_CANCEL, S_STEP_ERROR, S_STEP_SUBMIT, S_SUCCESS, S_WARN, autocomplete, autocompleteMultiselect, box, cancel, confirm, date, group, groupMultiselect, intro, isCI, isTTY, limitOptions, log, multiline, multiselect, note, outro, password, path, progress, select, selectKey, spinner, stream, symbol, symbolBar, taskLog, tasks, text, unicode, unicodeOr };
+2
-2
{
"name": "@clack/prompts",
"version": "1.5.0",
"version": "1.5.1",
"type": "module",

@@ -56,3 +56,3 @@ "main": "./dist/index.mjs",

"sisteransi": "^1.0.5",
"@clack/core": "1.4.0"
"@clack/core": "1.4.1"
},

@@ -59,0 +59,0 @@ "devDependencies": {

@@ -96,3 +96,3 @@ # `@clack/prompts`

The date component accepts a calendar date and returns a `Date` value.
The `date` prompt provides an interactive date picker, allowing users to navigate between year, month, and day segments and increment/decrement values using keyboard controls.

@@ -102,7 +102,7 @@ ```js

const dueDate = await date({
message: 'Pick a due date.',
format: 'YMD',
minDate: new Date(Date.UTC(2026, 0, 1)),
maxDate: new Date(Date.UTC(2026, 11, 31)),
const birthday = await date({
message: 'Pick your birthday',
minDate: new Date('1900-01-01'),
initialValue: new Date(),
maxDate: new Date(),
});

@@ -109,0 +109,0 @@ ```

Sorry, the diff of this file is too big to display