push neon reactor
This commit is contained in:
+80
@@ -0,0 +1,80 @@
|
||||
"use strict";const core=require("@clack/core"),process$1=require("node:process"),color=require("picocolors"),sisteransi=require("sisteransi");function isUnicodeSupported(){return process$1.platform!=="win32"?process$1.env.TERM!=="linux":Boolean(process$1.env.CI)||Boolean(process$1.env.WT_SESSION)||Boolean(process$1.env.TERMINUS_SUBLIME)||process$1.env.ConEmuTask==="{cmd::Cmder}"||process$1.env.TERM_PROGRAM==="Terminus-Sublime"||process$1.env.TERM_PROGRAM==="vscode"||process$1.env.TERM==="xterm-256color"||process$1.env.TERM==="alacritty"||process$1.env.TERMINAL_EMULATOR==="JetBrains-JediTerm"}const unicode=isUnicodeSupported(),s=(t,n)=>unicode?t:n,S_STEP_ACTIVE=s("\u25C6","*"),S_STEP_CANCEL=s("\u25A0","x"),S_STEP_ERROR=s("\u25B2","x"),S_STEP_SUBMIT=s("\u25C7","o"),S_BAR_START=s("\u250C","T"),S_BAR=s("\u2502","|"),S_BAR_END=s("\u2514","\u2014"),S_RADIO_ACTIVE=s("\u25CF",">"),S_RADIO_INACTIVE=s("\u25CB"," "),S_CHECKBOX_ACTIVE=s("\u25FB","[\u2022]"),S_CHECKBOX_SELECTED=s("\u25FC","[+]"),S_CHECKBOX_INACTIVE=s("\u25FB","[ ]"),S_PASSWORD_MASK=s("\u25AA","\u2022"),S_BAR_H=s("\u2500","-"),S_CORNER_TOP_RIGHT=s("\u256E","+"),S_CONNECT_LEFT=s("\u251C","+"),S_CORNER_BOTTOM_RIGHT=s("\u256F","+"),S_INFO=s("\u25CF","\u2022"),S_SUCCESS=s("\u25C6","*"),S_WARN=s("\u25B2","!"),S_ERROR=s("\u25A0","x"),symbol=t=>{switch(t){case"initial":case"active":return color.cyan(S_STEP_ACTIVE);case"cancel":return color.red(S_STEP_CANCEL);case"error":return color.yellow(S_STEP_ERROR);case"submit":return color.green(S_STEP_SUBMIT)}},text=t=>new core.TextPrompt({validate:t.validate,placeholder:t.placeholder,defaultValue:t.defaultValue,initialValue:t.initialValue,render(){const n=`${color.gray(S_BAR)}
|
||||
${symbol(this.state)} ${t.message}
|
||||
`,r=t.placeholder?color.inverse(t.placeholder[0])+color.dim(t.placeholder.slice(1)):color.inverse(color.hidden("_")),e=this.value?this.valueWithCursor:r;switch(this.state){case"error":return`${n.trim()}
|
||||
${color.yellow(S_BAR)} ${e}
|
||||
${color.yellow(S_BAR_END)} ${color.yellow(this.error)}
|
||||
`;case"submit":return`${n}${color.gray(S_BAR)} ${color.dim(this.value||t.placeholder)}`;case"cancel":return`${n}${color.gray(S_BAR)} ${color.strikethrough(color.dim(this.value??""))}${this.value?.trim()?`
|
||||
`+color.gray(S_BAR):""}`;default:return`${n}${color.cyan(S_BAR)} ${e}
|
||||
${color.cyan(S_BAR_END)}
|
||||
`}}}).prompt(),password=t=>new core.PasswordPrompt({validate:t.validate,mask:t.mask??S_PASSWORD_MASK,render(){const n=`${color.gray(S_BAR)}
|
||||
${symbol(this.state)} ${t.message}
|
||||
`,r=this.valueWithCursor,e=this.masked;switch(this.state){case"error":return`${n.trim()}
|
||||
${color.yellow(S_BAR)} ${e}
|
||||
${color.yellow(S_BAR_END)} ${color.yellow(this.error)}
|
||||
`;case"submit":return`${n}${color.gray(S_BAR)} ${color.dim(e)}`;case"cancel":return`${n}${color.gray(S_BAR)} ${color.strikethrough(color.dim(e??""))}${e?`
|
||||
`+color.gray(S_BAR):""}`;default:return`${n}${color.cyan(S_BAR)} ${r}
|
||||
${color.cyan(S_BAR_END)}
|
||||
`}}}).prompt(),confirm=t=>{const n=t.active??"Yes",r=t.inactive??"No";return new core.ConfirmPrompt({active:n,inactive:r,initialValue:t.initialValue??!0,render(){const e=`${color.gray(S_BAR)}
|
||||
${symbol(this.state)} ${t.message}
|
||||
`,i=this.value?n:r;switch(this.state){case"submit":return`${e}${color.gray(S_BAR)} ${color.dim(i)}`;case"cancel":return`${e}${color.gray(S_BAR)} ${color.strikethrough(color.dim(i))}
|
||||
${color.gray(S_BAR)}`;default:return`${e}${color.cyan(S_BAR)} ${this.value?`${color.green(S_RADIO_ACTIVE)} ${n}`:`${color.dim(S_RADIO_INACTIVE)} ${color.dim(n)}`} ${color.dim("/")} ${this.value?`${color.dim(S_RADIO_INACTIVE)} ${color.dim(r)}`:`${color.green(S_RADIO_ACTIVE)} ${r}`}
|
||||
${color.cyan(S_BAR_END)}
|
||||
`}}}).prompt()},select=t=>{const n=(r,e)=>{const i=r.label??String(r.value);return e==="active"?`${color.green(S_RADIO_ACTIVE)} ${i} ${r.hint?color.dim(`(${r.hint})`):""}`:e==="selected"?`${color.dim(i)}`:e==="cancelled"?`${color.strikethrough(color.dim(i))}`:`${color.dim(S_RADIO_INACTIVE)} ${color.dim(i)}`};return new core.SelectPrompt({options:t.options,initialValue:t.initialValue,render(){const r=`${color.gray(S_BAR)}
|
||||
${symbol(this.state)} ${t.message}
|
||||
`;switch(this.state){case"submit":return`${r}${color.gray(S_BAR)} ${n(this.options[this.cursor],"selected")}`;case"cancel":return`${r}${color.gray(S_BAR)} ${n(this.options[this.cursor],"cancelled")}
|
||||
${color.gray(S_BAR)}`;default:return`${r}${color.cyan(S_BAR)} ${this.options.map((e,i)=>n(e,i===this.cursor?"active":"inactive")).join(`
|
||||
${color.cyan(S_BAR)} `)}
|
||||
${color.cyan(S_BAR_END)}
|
||||
`}}}).prompt()},selectKey=t=>{const n=(r,e="inactive")=>{const i=r.label??String(r.value);return e==="selected"?`${color.dim(i)}`:e==="cancelled"?`${color.strikethrough(color.dim(i))}`:e==="active"?`${color.bgCyan(color.gray(` ${r.value} `))} ${i} ${r.hint?color.dim(`(${r.hint})`):""}`:`${color.gray(color.bgWhite(color.inverse(` ${r.value} `)))} ${i} ${r.hint?color.dim(`(${r.hint})`):""}`};return new core.SelectKeyPrompt({options:t.options,initialValue:t.initialValue,render(){const r=`${color.gray(S_BAR)}
|
||||
${symbol(this.state)} ${t.message}
|
||||
`;switch(this.state){case"submit":return`${r}${color.gray(S_BAR)} ${n(this.options.find(e=>e.value===this.value),"selected")}`;case"cancel":return`${r}${color.gray(S_BAR)} ${n(this.options[0],"cancelled")}
|
||||
${color.gray(S_BAR)}`;default:return`${r}${color.cyan(S_BAR)} ${this.options.map((e,i)=>n(e,i===this.cursor?"active":"inactive")).join(`
|
||||
${color.cyan(S_BAR)} `)}
|
||||
${color.cyan(S_BAR_END)}
|
||||
`}}}).prompt()},multiselect=t=>{const n=(r,e)=>{const i=r.label??String(r.value);return e==="active"?`${color.cyan(S_CHECKBOX_ACTIVE)} ${i} ${r.hint?color.dim(`(${r.hint})`):""}`:e==="selected"?`${color.green(S_CHECKBOX_SELECTED)} ${color.dim(i)}`:e==="cancelled"?`${color.strikethrough(color.dim(i))}`:e==="active-selected"?`${color.green(S_CHECKBOX_SELECTED)} ${i} ${r.hint?color.dim(`(${r.hint})`):""}`:e==="submitted"?`${color.dim(i)}`:`${color.dim(S_CHECKBOX_INACTIVE)} ${color.dim(i)}`};return new core.MultiSelectPrompt({options:t.options,initialValues:t.initialValues,required:t.required??!0,cursorAt:t.cursorAt,validate(r){if(this.required&&r.length===0)return`Please select at least one option.
|
||||
${color.reset(color.dim(`Press ${color.gray(color.bgWhite(color.inverse(" space ")))} to select, ${color.gray(color.bgWhite(color.inverse(" enter ")))} to submit`))}`},render(){let r=`${color.gray(S_BAR)}
|
||||
${symbol(this.state)} ${t.message}
|
||||
`;switch(this.state){case"submit":return`${r}${color.gray(S_BAR)} ${this.options.filter(({value:e})=>this.value.includes(e)).map(e=>n(e,"submitted")).join(color.dim(", "))||color.dim("none")}`;case"cancel":{const e=this.options.filter(({value:i})=>this.value.includes(i)).map(i=>n(i,"cancelled")).join(color.dim(", "));return`${r}${color.gray(S_BAR)} ${e.trim()?`${e}
|
||||
${color.gray(S_BAR)}`:""}`}case"error":{const e=this.error.split(`
|
||||
`).map((i,c)=>c===0?`${color.yellow(S_BAR_END)} ${color.yellow(i)}`:` ${i}`).join(`
|
||||
`);return r+color.yellow(S_BAR)+" "+this.options.map((i,c)=>{const a=this.value.includes(i.value),l=c===this.cursor;return l&&a?n(i,"active-selected"):a?n(i,"selected"):n(i,l?"active":"inactive")}).join(`
|
||||
${color.yellow(S_BAR)} `)+`
|
||||
`+e+`
|
||||
`}default:return`${r}${color.cyan(S_BAR)} ${this.options.map((e,i)=>{const c=this.value.includes(e.value),a=i===this.cursor;return a&&c?n(e,"active-selected"):c?n(e,"selected"):n(e,a?"active":"inactive")}).join(`
|
||||
${color.cyan(S_BAR)} `)}
|
||||
${color.cyan(S_BAR_END)}
|
||||
`}}}).prompt()},groupMultiselect=t=>{const n=(r,e,i=[])=>{const c=r.label??String(r.value),a=typeof r.group=="string",l=a&&(i[i.indexOf(r)+1]??{group:!0}),o=a&&l.group===!0,u=a?`${o?S_BAR_END:S_BAR} `:"";return e==="active"?`${color.dim(u)}${color.cyan(S_CHECKBOX_ACTIVE)} ${c} ${r.hint?color.dim(`(${r.hint})`):""}`:e==="group-active"?`${u}${color.cyan(S_CHECKBOX_ACTIVE)} ${color.dim(c)}`:e==="group-active-selected"?`${u}${color.green(S_CHECKBOX_SELECTED)} ${color.dim(c)}`:e==="selected"?`${color.dim(u)}${color.green(S_CHECKBOX_SELECTED)} ${color.dim(c)}`:e==="cancelled"?`${color.strikethrough(color.dim(c))}`:e==="active-selected"?`${color.dim(u)}${color.green(S_CHECKBOX_SELECTED)} ${c} ${r.hint?color.dim(`(${r.hint})`):""}`:e==="submitted"?`${color.dim(c)}`:`${color.dim(u)}${color.dim(S_CHECKBOX_INACTIVE)} ${color.dim(c)}`};return new core.GroupMultiSelectPrompt({options:t.options,initialValues:t.initialValues,required:t.required??!0,cursorAt:t.cursorAt,validate(r){if(this.required&&r.length===0)return`Please select at least one option.
|
||||
${color.reset(color.dim(`Press ${color.gray(color.bgWhite(color.inverse(" space ")))} to select, ${color.gray(color.bgWhite(color.inverse(" enter ")))} to submit`))}`},render(){let r=`${color.gray(S_BAR)}
|
||||
${symbol(this.state)} ${t.message}
|
||||
`;switch(this.state){case"submit":return`${r}${color.gray(S_BAR)} ${this.options.filter(({value:e})=>this.value.includes(e)).map(e=>n(e,"submitted")).join(color.dim(", "))}`;case"cancel":{const e=this.options.filter(({value:i})=>this.value.includes(i)).map(i=>n(i,"cancelled")).join(color.dim(", "));return`${r}${color.gray(S_BAR)} ${e.trim()?`${e}
|
||||
${color.gray(S_BAR)}`:""}`}case"error":{const e=this.error.split(`
|
||||
`).map((i,c)=>c===0?`${color.yellow(S_BAR_END)} ${color.yellow(i)}`:` ${i}`).join(`
|
||||
`);return`${r}${color.yellow(S_BAR)} ${this.options.map((i,c,a)=>{const l=this.value.includes(i.value)||i.group===!0&&this.isGroupSelected(`${i.value}`),o=c===this.cursor;return!o&&typeof i.group=="string"&&this.options[this.cursor].value===i.group?n(i,l?"group-active-selected":"group-active",a):o&&l?n(i,"active-selected",a):l?n(i,"selected",a):n(i,o?"active":"inactive",a)}).join(`
|
||||
${color.yellow(S_BAR)} `)}
|
||||
${e}
|
||||
`}default:return`${r}${color.cyan(S_BAR)} ${this.options.map((e,i,c)=>{const a=this.value.includes(e.value)||e.group===!0&&this.isGroupSelected(`${e.value}`),l=i===this.cursor;return!l&&typeof e.group=="string"&&this.options[this.cursor].value===e.group?n(e,a?"group-active-selected":"group-active",c):l&&a?n(e,"active-selected",c):a?n(e,"selected",c):n(e,l?"active":"inactive",c)}).join(`
|
||||
${color.cyan(S_BAR)} `)}
|
||||
${color.cyan(S_BAR_END)}
|
||||
`}}}).prompt()},strip=t=>t.replace(ansiRegex(),""),note=(t="",n="")=>{const r=`
|
||||
${t}
|
||||
`.split(`
|
||||
`),e=Math.max(r.reduce((c,a)=>(a=strip(a),a.length>c?a.length:c),0),strip(n).length)+2,i=r.map(c=>`${color.gray(S_BAR)} ${color.dim(c)}${" ".repeat(e-strip(c).length)}${color.gray(S_BAR)}`).join(`
|
||||
`);process.stdout.write(`${color.gray(S_BAR)}
|
||||
${color.green(S_STEP_SUBMIT)} ${color.reset(n)} ${color.gray(S_BAR_H.repeat(Math.max(e-n.length-1,1))+S_CORNER_TOP_RIGHT)}
|
||||
${i}
|
||||
${color.gray(S_CONNECT_LEFT+S_BAR_H.repeat(e+2)+S_CORNER_BOTTOM_RIGHT)}
|
||||
`)},cancel=(t="")=>{process.stdout.write(`${color.gray(S_BAR_END)} ${color.red(t)}
|
||||
|
||||
`)},intro=(t="")=>{process.stdout.write(`${color.gray(S_BAR_START)} ${t}
|
||||
`)},outro=(t="")=>{process.stdout.write(`${color.gray(S_BAR)}
|
||||
${color.gray(S_BAR_END)} ${t}
|
||||
|
||||
`)},log={message:(t="",{symbol:n=color.gray(S_BAR)}={})=>{const r=[`${color.gray(S_BAR)}`];if(t){const[e,...i]=t.split(`
|
||||
`);r.push(`${n} ${e}`,...i.map(c=>`${color.gray(S_BAR)} ${c}`))}process.stdout.write(`${r.join(`
|
||||
`)}
|
||||
`)},info:t=>{log.message(t,{symbol:color.blue(S_INFO)})},success:t=>{log.message(t,{symbol:color.green(S_SUCCESS)})},step:t=>{log.message(t,{symbol:color.green(S_STEP_SUBMIT)})},warn:t=>{log.message(t,{symbol:color.yellow(S_WARN)})},warning:t=>{log.warn(t)},error:t=>{log.message(t,{symbol:color.red(S_ERROR)})}},frames=unicode?["\u25D2","\u25D0","\u25D3","\u25D1"]:["\u2022","o","O","0"],spinner=()=>{let t,n;const r=unicode?80:120;return{start(e=""){e=e.replace(/\.?\.?\.$/,""),t=core.block(),process.stdout.write(`${color.gray(S_BAR)}
|
||||
${color.magenta("\u25CB")} ${e}
|
||||
`);let i=0,c=0;n=setInterval(()=>{let a=frames[i];process.stdout.write(sisteransi.cursor.move(-999,-1)),process.stdout.write(`${color.magenta(a)} ${e}${Math.floor(c)>=1?".".repeat(Math.floor(c)).slice(0,3):""}
|
||||
`),i=i===frames.length-1?0:i+1,c=c===frames.length?0:c+.125},r)},stop(e=""){process.stdout.write(sisteransi.cursor.move(-999,-2)),process.stdout.write(sisteransi.erase.down(2)),clearInterval(n),process.stdout.write(`${color.gray(S_BAR)}
|
||||
${color.green(S_STEP_SUBMIT)} ${e}
|
||||
`),t()}}};function ansiRegex(){const t=["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)","(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))"].join("|");return new RegExp(t,"g")}const group=async(t,n)=>{const r={},e=Object.keys(t);for(const i of e){const c=t[i],a=await c({results:r})?.catch(l=>{throw l});if(typeof n?.onCancel=="function"&&core.isCancel(a)){r[i]="canceled",n.onCancel({results:r});continue}r[i]=a}return r};exports.isCancel=core.isCancel,exports.cancel=cancel,exports.confirm=confirm,exports.group=group,exports.groupMultiselect=groupMultiselect,exports.intro=intro,exports.log=log,exports.multiselect=multiselect,exports.note=note,exports.outro=outro,exports.password=password,exports.select=select,exports.selectKey=selectKey,exports.spinner=spinner,exports.text=text;
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
export { isCancel } from '@clack/core';
|
||||
|
||||
interface TextOptions {
|
||||
message: string;
|
||||
placeholder?: string;
|
||||
defaultValue?: string;
|
||||
initialValue?: string;
|
||||
validate?: (value: string) => string | void;
|
||||
}
|
||||
declare const text: (opts: TextOptions) => Promise<string | symbol>;
|
||||
interface PasswordOptions {
|
||||
message: string;
|
||||
mask?: string;
|
||||
validate?: (value: string) => string | void;
|
||||
}
|
||||
declare const password: (opts: PasswordOptions) => Promise<string | symbol>;
|
||||
interface ConfirmOptions {
|
||||
message: string;
|
||||
active?: string;
|
||||
inactive?: string;
|
||||
initialValue?: boolean;
|
||||
}
|
||||
declare const confirm: (opts: ConfirmOptions) => Promise<boolean | symbol>;
|
||||
type Primitive = Readonly<string | boolean | number>;
|
||||
type Option<Value> = Value extends Primitive ? {
|
||||
value: Value;
|
||||
label?: string;
|
||||
hint?: string;
|
||||
} : {
|
||||
value: Value;
|
||||
label: string;
|
||||
hint?: string;
|
||||
};
|
||||
interface SelectOptions<Options extends Option<Value>[], Value> {
|
||||
message: string;
|
||||
options: Options;
|
||||
initialValue?: Value;
|
||||
}
|
||||
declare const select: <Options extends Option<Value>[], Value>(opts: SelectOptions<Options, Value>) => Promise<symbol | Value>;
|
||||
declare const selectKey: <Options extends Option<Value>[], Value extends string>(opts: SelectOptions<Options, Value>) => Promise<symbol | Value>;
|
||||
interface MultiSelectOptions<Options extends Option<Value>[], Value> {
|
||||
message: string;
|
||||
options: Options;
|
||||
initialValues?: Value[];
|
||||
required?: boolean;
|
||||
cursorAt?: Value;
|
||||
}
|
||||
declare const multiselect: <Options extends Option<Value>[], Value>(opts: MultiSelectOptions<Options, Value>) => Promise<symbol | Value[]>;
|
||||
interface GroupMultiSelectOptions<Options extends Option<Value>[], Value> {
|
||||
message: string;
|
||||
options: Record<string, Options>;
|
||||
initialValues?: Value[];
|
||||
required?: boolean;
|
||||
cursorAt?: Value;
|
||||
}
|
||||
declare const groupMultiselect: <Options extends Option<Value>[], Value>(opts: GroupMultiSelectOptions<Options, Value>) => Promise<symbol | Value[]>;
|
||||
declare const note: (message?: string, title?: string) => void;
|
||||
declare const cancel: (message?: string) => void;
|
||||
declare const intro: (title?: string) => void;
|
||||
declare const outro: (message?: string) => void;
|
||||
type LogMessageOptions = {
|
||||
symbol?: string;
|
||||
};
|
||||
declare const log: {
|
||||
message: (message?: string, { symbol }?: LogMessageOptions) => void;
|
||||
info: (message: string) => void;
|
||||
success: (message: string) => void;
|
||||
step: (message: string) => void;
|
||||
warn: (message: string) => void;
|
||||
/** alias for `log.warn()`. */
|
||||
warning: (message: string) => void;
|
||||
error: (message: string) => void;
|
||||
};
|
||||
declare const spinner: () => {
|
||||
start(message?: string): void;
|
||||
stop(message?: string): void;
|
||||
};
|
||||
type PromptGroupAwaitedReturn<T> = {
|
||||
[P in keyof T]: Exclude<Awaited<T[P]>, symbol>;
|
||||
};
|
||||
interface PromptGroupOptions<T> {
|
||||
/**
|
||||
* Control how the group can be canceld
|
||||
* if one of the prompts is canceld.
|
||||
*/
|
||||
onCancel?: (opts: {
|
||||
results: Partial<PromptGroupAwaitedReturn<T>>;
|
||||
}) => void;
|
||||
}
|
||||
type PromptGroup<T> = {
|
||||
[P in keyof T]: (opts: {
|
||||
results: Partial<PromptGroupAwaitedReturn<T>>;
|
||||
}) => void | Promise<T[P] | void>;
|
||||
};
|
||||
/**
|
||||
* Define a group of prompts to be displayed
|
||||
* and return a results of objects within the group
|
||||
*/
|
||||
declare const group: <T>(prompts: PromptGroup<T>, opts?: PromptGroupOptions<T> | undefined) => Promise<PromptGroupAwaitedReturn<T>>;
|
||||
|
||||
export { ConfirmOptions, GroupMultiSelectOptions, LogMessageOptions, MultiSelectOptions, PasswordOptions, PromptGroup, PromptGroupAwaitedReturn, PromptGroupOptions, SelectOptions, TextOptions, cancel, confirm, group, groupMultiselect, intro, log, multiselect, note, outro, password, select, selectKey, spinner, text };
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
import{TextPrompt as T,PasswordPrompt as B,ConfirmPrompt as O,SelectPrompt as I,SelectKeyPrompt as M,MultiSelectPrompt as P,GroupMultiSelectPrompt as V,block as j,isCancel as x}from"@clack/core";export{isCancel}from"@clack/core";import d from"node:process";import e from"picocolors";import{cursor as E,erase as k}from"sisteransi";function N(){return d.platform!=="win32"?d.env.TERM!=="linux":Boolean(d.env.CI)||Boolean(d.env.WT_SESSION)||Boolean(d.env.TERMINUS_SUBLIME)||d.env.ConEmuTask==="{cmd::Cmder}"||d.env.TERM_PROGRAM==="Terminus-Sublime"||d.env.TERM_PROGRAM==="vscode"||d.env.TERM==="xterm-256color"||d.env.TERM==="alacritty"||d.env.TERMINAL_EMULATOR==="JetBrains-JediTerm"}const p=N(),u=(r,n)=>p?r:n,W=u("\u25C6","*"),D=u("\u25A0","x"),F=u("\u25B2","x"),f=u("\u25C7","o"),L=u("\u250C","T"),a=u("\u2502","|"),o=u("\u2514","\u2014"),w=u("\u25CF",">"),S=u("\u25CB"," "),_=u("\u25FB","[\u2022]"),y=u("\u25FC","[+]"),A=u("\u25FB","[ ]"),q=u("\u25AA","\u2022"),R=u("\u2500","-"),G=u("\u256E","+"),H=u("\u251C","+"),K=u("\u256F","+"),U=u("\u25CF","\u2022"),Z=u("\u25C6","*"),z=u("\u25B2","!"),X=u("\u25A0","x"),h=r=>{switch(r){case"initial":case"active":return e.cyan(W);case"cancel":return e.red(D);case"error":return e.yellow(F);case"submit":return e.green(f)}},J=r=>new T({validate:r.validate,placeholder:r.placeholder,defaultValue:r.defaultValue,initialValue:r.initialValue,render(){const n=`${e.gray(a)}
|
||||
${h(this.state)} ${r.message}
|
||||
`,s=r.placeholder?e.inverse(r.placeholder[0])+e.dim(r.placeholder.slice(1)):e.inverse(e.hidden("_")),t=this.value?this.valueWithCursor:s;switch(this.state){case"error":return`${n.trim()}
|
||||
${e.yellow(a)} ${t}
|
||||
${e.yellow(o)} ${e.yellow(this.error)}
|
||||
`;case"submit":return`${n}${e.gray(a)} ${e.dim(this.value||r.placeholder)}`;case"cancel":return`${n}${e.gray(a)} ${e.strikethrough(e.dim(this.value??""))}${this.value?.trim()?`
|
||||
`+e.gray(a):""}`;default:return`${n}${e.cyan(a)} ${t}
|
||||
${e.cyan(o)}
|
||||
`}}}).prompt(),Y=r=>new B({validate:r.validate,mask:r.mask??q,render(){const n=`${e.gray(a)}
|
||||
${h(this.state)} ${r.message}
|
||||
`,s=this.valueWithCursor,t=this.masked;switch(this.state){case"error":return`${n.trim()}
|
||||
${e.yellow(a)} ${t}
|
||||
${e.yellow(o)} ${e.yellow(this.error)}
|
||||
`;case"submit":return`${n}${e.gray(a)} ${e.dim(t)}`;case"cancel":return`${n}${e.gray(a)} ${e.strikethrough(e.dim(t??""))}${t?`
|
||||
`+e.gray(a):""}`;default:return`${n}${e.cyan(a)} ${s}
|
||||
${e.cyan(o)}
|
||||
`}}}).prompt(),Q=r=>{const n=r.active??"Yes",s=r.inactive??"No";return new O({active:n,inactive:s,initialValue:r.initialValue??!0,render(){const t=`${e.gray(a)}
|
||||
${h(this.state)} ${r.message}
|
||||
`,i=this.value?n:s;switch(this.state){case"submit":return`${t}${e.gray(a)} ${e.dim(i)}`;case"cancel":return`${t}${e.gray(a)} ${e.strikethrough(e.dim(i))}
|
||||
${e.gray(a)}`;default:return`${t}${e.cyan(a)} ${this.value?`${e.green(w)} ${n}`:`${e.dim(S)} ${e.dim(n)}`} ${e.dim("/")} ${this.value?`${e.dim(S)} ${e.dim(s)}`:`${e.green(w)} ${s}`}
|
||||
${e.cyan(o)}
|
||||
`}}}).prompt()},ee=r=>{const n=(s,t)=>{const i=s.label??String(s.value);return t==="active"?`${e.green(w)} ${i} ${s.hint?e.dim(`(${s.hint})`):""}`:t==="selected"?`${e.dim(i)}`:t==="cancelled"?`${e.strikethrough(e.dim(i))}`:`${e.dim(S)} ${e.dim(i)}`};return new I({options:r.options,initialValue:r.initialValue,render(){const s=`${e.gray(a)}
|
||||
${h(this.state)} ${r.message}
|
||||
`;switch(this.state){case"submit":return`${s}${e.gray(a)} ${n(this.options[this.cursor],"selected")}`;case"cancel":return`${s}${e.gray(a)} ${n(this.options[this.cursor],"cancelled")}
|
||||
${e.gray(a)}`;default:return`${s}${e.cyan(a)} ${this.options.map((t,i)=>n(t,i===this.cursor?"active":"inactive")).join(`
|
||||
${e.cyan(a)} `)}
|
||||
${e.cyan(o)}
|
||||
`}}}).prompt()},te=r=>{const n=(s,t="inactive")=>{const i=s.label??String(s.value);return t==="selected"?`${e.dim(i)}`:t==="cancelled"?`${e.strikethrough(e.dim(i))}`:t==="active"?`${e.bgCyan(e.gray(` ${s.value} `))} ${i} ${s.hint?e.dim(`(${s.hint})`):""}`:`${e.gray(e.bgWhite(e.inverse(` ${s.value} `)))} ${i} ${s.hint?e.dim(`(${s.hint})`):""}`};return new M({options:r.options,initialValue:r.initialValue,render(){const s=`${e.gray(a)}
|
||||
${h(this.state)} ${r.message}
|
||||
`;switch(this.state){case"submit":return`${s}${e.gray(a)} ${n(this.options.find(t=>t.value===this.value),"selected")}`;case"cancel":return`${s}${e.gray(a)} ${n(this.options[0],"cancelled")}
|
||||
${e.gray(a)}`;default:return`${s}${e.cyan(a)} ${this.options.map((t,i)=>n(t,i===this.cursor?"active":"inactive")).join(`
|
||||
${e.cyan(a)} `)}
|
||||
${e.cyan(o)}
|
||||
`}}}).prompt()},re=r=>{const n=(s,t)=>{const i=s.label??String(s.value);return t==="active"?`${e.cyan(_)} ${i} ${s.hint?e.dim(`(${s.hint})`):""}`:t==="selected"?`${e.green(y)} ${e.dim(i)}`:t==="cancelled"?`${e.strikethrough(e.dim(i))}`:t==="active-selected"?`${e.green(y)} ${i} ${s.hint?e.dim(`(${s.hint})`):""}`:t==="submitted"?`${e.dim(i)}`:`${e.dim(A)} ${e.dim(i)}`};return new P({options:r.options,initialValues:r.initialValues,required:r.required??!0,cursorAt:r.cursorAt,validate(s){if(this.required&&s.length===0)return`Please select at least one option.
|
||||
${e.reset(e.dim(`Press ${e.gray(e.bgWhite(e.inverse(" space ")))} to select, ${e.gray(e.bgWhite(e.inverse(" enter ")))} to submit`))}`},render(){let s=`${e.gray(a)}
|
||||
${h(this.state)} ${r.message}
|
||||
`;switch(this.state){case"submit":return`${s}${e.gray(a)} ${this.options.filter(({value:t})=>this.value.includes(t)).map(t=>n(t,"submitted")).join(e.dim(", "))||e.dim("none")}`;case"cancel":{const t=this.options.filter(({value:i})=>this.value.includes(i)).map(i=>n(i,"cancelled")).join(e.dim(", "));return`${s}${e.gray(a)} ${t.trim()?`${t}
|
||||
${e.gray(a)}`:""}`}case"error":{const t=this.error.split(`
|
||||
`).map((i,c)=>c===0?`${e.yellow(o)} ${e.yellow(i)}`:` ${i}`).join(`
|
||||
`);return s+e.yellow(a)+" "+this.options.map((i,c)=>{const l=this.value.includes(i.value),$=c===this.cursor;return $&&l?n(i,"active-selected"):l?n(i,"selected"):n(i,$?"active":"inactive")}).join(`
|
||||
${e.yellow(a)} `)+`
|
||||
`+t+`
|
||||
`}default:return`${s}${e.cyan(a)} ${this.options.map((t,i)=>{const c=this.value.includes(t.value),l=i===this.cursor;return l&&c?n(t,"active-selected"):c?n(t,"selected"):n(t,l?"active":"inactive")}).join(`
|
||||
${e.cyan(a)} `)}
|
||||
${e.cyan(o)}
|
||||
`}}}).prompt()},se=r=>{const n=(s,t,i=[])=>{const c=s.label??String(s.value),l=typeof s.group=="string",$=l&&(i[i.indexOf(s)+1]??{group:!0}),v=l&&$.group===!0,m=l?`${v?o:a} `:"";return t==="active"?`${e.dim(m)}${e.cyan(_)} ${c} ${s.hint?e.dim(`(${s.hint})`):""}`:t==="group-active"?`${m}${e.cyan(_)} ${e.dim(c)}`:t==="group-active-selected"?`${m}${e.green(y)} ${e.dim(c)}`:t==="selected"?`${e.dim(m)}${e.green(y)} ${e.dim(c)}`:t==="cancelled"?`${e.strikethrough(e.dim(c))}`:t==="active-selected"?`${e.dim(m)}${e.green(y)} ${c} ${s.hint?e.dim(`(${s.hint})`):""}`:t==="submitted"?`${e.dim(c)}`:`${e.dim(m)}${e.dim(A)} ${e.dim(c)}`};return new V({options:r.options,initialValues:r.initialValues,required:r.required??!0,cursorAt:r.cursorAt,validate(s){if(this.required&&s.length===0)return`Please select at least one option.
|
||||
${e.reset(e.dim(`Press ${e.gray(e.bgWhite(e.inverse(" space ")))} to select, ${e.gray(e.bgWhite(e.inverse(" enter ")))} to submit`))}`},render(){let s=`${e.gray(a)}
|
||||
${h(this.state)} ${r.message}
|
||||
`;switch(this.state){case"submit":return`${s}${e.gray(a)} ${this.options.filter(({value:t})=>this.value.includes(t)).map(t=>n(t,"submitted")).join(e.dim(", "))}`;case"cancel":{const t=this.options.filter(({value:i})=>this.value.includes(i)).map(i=>n(i,"cancelled")).join(e.dim(", "));return`${s}${e.gray(a)} ${t.trim()?`${t}
|
||||
${e.gray(a)}`:""}`}case"error":{const t=this.error.split(`
|
||||
`).map((i,c)=>c===0?`${e.yellow(o)} ${e.yellow(i)}`:` ${i}`).join(`
|
||||
`);return`${s}${e.yellow(a)} ${this.options.map((i,c,l)=>{const $=this.value.includes(i.value)||i.group===!0&&this.isGroupSelected(`${i.value}`),v=c===this.cursor;return!v&&typeof i.group=="string"&&this.options[this.cursor].value===i.group?n(i,$?"group-active-selected":"group-active",l):v&&$?n(i,"active-selected",l):$?n(i,"selected",l):n(i,v?"active":"inactive",l)}).join(`
|
||||
${e.yellow(a)} `)}
|
||||
${t}
|
||||
`}default:return`${s}${e.cyan(a)} ${this.options.map((t,i,c)=>{const l=this.value.includes(t.value)||t.group===!0&&this.isGroupSelected(`${t.value}`),$=i===this.cursor;return!$&&typeof t.group=="string"&&this.options[this.cursor].value===t.group?n(t,l?"group-active-selected":"group-active",c):$&&l?n(t,"active-selected",c):l?n(t,"selected",c):n(t,$?"active":"inactive",c)}).join(`
|
||||
${e.cyan(a)} `)}
|
||||
${e.cyan(o)}
|
||||
`}}}).prompt()},b=r=>r.replace(ue(),""),ie=(r="",n="")=>{const s=`
|
||||
${r}
|
||||
`.split(`
|
||||
`),t=Math.max(s.reduce((c,l)=>(l=b(l),l.length>c?l.length:c),0),b(n).length)+2,i=s.map(c=>`${e.gray(a)} ${e.dim(c)}${" ".repeat(t-b(c).length)}${e.gray(a)}`).join(`
|
||||
`);process.stdout.write(`${e.gray(a)}
|
||||
${e.green(f)} ${e.reset(n)} ${e.gray(R.repeat(Math.max(t-n.length-1,1))+G)}
|
||||
${i}
|
||||
${e.gray(H+R.repeat(t+2)+K)}
|
||||
`)},ne=(r="")=>{process.stdout.write(`${e.gray(o)} ${e.red(r)}
|
||||
|
||||
`)},ae=(r="")=>{process.stdout.write(`${e.gray(L)} ${r}
|
||||
`)},ce=(r="")=>{process.stdout.write(`${e.gray(a)}
|
||||
${e.gray(o)} ${r}
|
||||
|
||||
`)},g={message:(r="",{symbol:n=e.gray(a)}={})=>{const s=[`${e.gray(a)}`];if(r){const[t,...i]=r.split(`
|
||||
`);s.push(`${n} ${t}`,...i.map(c=>`${e.gray(a)} ${c}`))}process.stdout.write(`${s.join(`
|
||||
`)}
|
||||
`)},info:r=>{g.message(r,{symbol:e.blue(U)})},success:r=>{g.message(r,{symbol:e.green(Z)})},step:r=>{g.message(r,{symbol:e.green(f)})},warn:r=>{g.message(r,{symbol:e.yellow(z)})},warning:r=>{g.warn(r)},error:r=>{g.message(r,{symbol:e.red(X)})}},C=p?["\u25D2","\u25D0","\u25D3","\u25D1"]:["\u2022","o","O","0"],le=()=>{let r,n;const s=p?80:120;return{start(t=""){t=t.replace(/\.?\.?\.$/,""),r=j(),process.stdout.write(`${e.gray(a)}
|
||||
${e.magenta("\u25CB")} ${t}
|
||||
`);let i=0,c=0;n=setInterval(()=>{let l=C[i];process.stdout.write(E.move(-999,-1)),process.stdout.write(`${e.magenta(l)} ${t}${Math.floor(c)>=1?".".repeat(Math.floor(c)).slice(0,3):""}
|
||||
`),i=i===C.length-1?0:i+1,c=c===C.length?0:c+.125},s)},stop(t=""){process.stdout.write(E.move(-999,-2)),process.stdout.write(k.down(2)),clearInterval(n),process.stdout.write(`${e.gray(a)}
|
||||
${e.green(f)} ${t}
|
||||
`),r()}}};function ue(){const r=["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)","(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))"].join("|");return new RegExp(r,"g")}const $e=async(r,n)=>{const s={},t=Object.keys(r);for(const i of t){const c=r[i],l=await c({results:s})?.catch($=>{throw $});if(typeof n?.onCancel=="function"&&x(l)){s[i]="canceled",n.onCancel({results:s});continue}s[i]=l}return s};export{ne as cancel,Q as confirm,$e as group,se as groupMultiselect,ae as intro,g as log,re as multiselect,ie as note,ce as outro,Y as password,ee as select,te as selectKey,le as spinner,J as text};
|
||||
Reference in New Issue
Block a user