145 lines
30 KiB
JavaScript
145 lines
30 KiB
JavaScript
import{getColumns as X,getRows as Bt,AutocompletePrompt as vt,settings as _,ConfirmPrompt as Lt,wrapTextWithPrefix as O,DatePrompt as Dt,isCancel as Wt,GroupMultiSelectPrompt as Ft,MultiLinePrompt as Ht,MultiSelectPrompt as Ut,PasswordPrompt as Kt,block as qt,SelectPrompt as Jt,SelectKeyPrompt as Yt,TextPrompt as Xt}from"@clack/core";export{isCancel,settings,updateSettings}from"@clack/core";import{styleText as e,stripVTControlCharacters as nt}from"node:util";import j from"node:process";import{wrapAnsi as q}from"fast-wrap-ansi";import k from"fast-string-width";import{existsSync as zt,lstatSync as wt,readdirSync as Qt}from"node:fs";import{dirname as bt,join as Zt}from"node:path";import{cursor as St,erase as Ct}from"sisteransi";function te(){return j.platform!=="win32"?j.env.TERM!=="linux":!!j.env.CI||!!j.env.WT_SESSION||!!j.env.TERMINUS_SUBLIME||j.env.ConEmuTask==="{cmd::Cmder}"||j.env.TERM_PROGRAM==="Terminus-Sublime"||j.env.TERM_PROGRAM==="vscode"||j.env.TERM==="xterm-256color"||j.env.TERM==="alacritty"||j.env.TERMINAL_EMULATOR==="JetBrains-JediTerm"}const tt=te(),at=()=>process.env.CI==="true",Tt=t=>t.isTTY===!0,w=(t,r)=>tt?t:r,_t=w("\u25C6","*"),ot=w("\u25A0","x"),ut=w("\u25B2","x"),F=w("\u25C7","o"),lt=w("\u250C","T"),$=w("\u2502","|"),E=w("\u2514","\u2014"),It=w("\u2510","T"),Et=w("\u2518","\u2014"),z=w("\u25CF",">"),H=w("\u25CB"," "),et=w("\u25FB","[\u2022]"),U=w("\u25FC","[+]"),J=w("\u25FB","[ ]"),Gt=w("\u25AA","\u2022"),st=w("\u2500","-"),ct=w("\u256E","+"),xt=w("\u251C","+"),$t=w("\u256F","+"),dt=w("\u2570","+"),Ot=w("\u256D","+"),ht=w("\u25CF","\u2022"),pt=w("\u25C6","*"),mt=w("\u25B2","!"),gt=w("\u25A0","x"),M=t=>{switch(t){case"initial":case"active":return e("cyan",_t);case"cancel":return e("red",ot);case"error":return e("yellow",ut);case"submit":return e("green",F)}},yt=t=>{switch(t){case"initial":case"active":return e("cyan",$);case"cancel":return e("red",$);case"error":return e("yellow",$);case"submit":return e("green",$)}},ee=(t,r,s,i,u)=>{let n=r,o=0;for(let c=s;c<i;c++){const a=t[c];if(n=n-a.length,o++,n<=u)break}return{lineCount:n,removals:o}},Y=({cursor:t,options:r,style:s,output:i=process.stdout,maxItems:u=Number.POSITIVE_INFINITY,columnPadding:n=0,rowPadding:o=4})=>{const c=X(i)-n,a=Bt(i),l=e("dim","..."),d=Math.max(a-o,0),y=Math.max(Math.min(u,d),5);let p=0;t>=y-3&&(p=Math.max(Math.min(t-y+3,r.length-y),0));let m=y<r.length&&p>0,g=y<r.length&&p+y<r.length;const S=Math.min(p+y,r.length),h=[];let f=0;m&&f++,g&&f++;const v=p+(m?1:0),T=S-(g?1:0);for(let b=v;b<T;b++){const G=q(s(r[b],b===t),c,{hard:!0,trim:!1}).split(`
|
|
`);h.push(G),f+=G.length}if(f>d){let b=0,G=0,x=f;const A=t-v,P=(N,D)=>ee(h,x,N,D,d);m?({lineCount:x,removals:b}=P(0,A),x>d&&({lineCount:x,removals:G}=P(A+1,h.length))):({lineCount:x,removals:G}=P(A+1,h.length),x>d&&({lineCount:x,removals:b}=P(0,A))),b>0&&(m=!0,h.splice(0,b)),G>0&&(g=!0,h.splice(h.length-G,G))}const C=[];m&&C.push(l);for(const b of h)for(const G of b)C.push(G);return g&&C.push(l),C};function Mt(t){return t.label??String(t.value??"")}function Rt(t,r){if(!t)return!0;const s=(r.label??String(r.value??"")).toLowerCase(),i=(r.hint??"").toLowerCase(),u=String(r.value).toLowerCase(),n=t.toLowerCase();return s.includes(n)||i.includes(n)||u.includes(n)}function se(t,r){const s=[];for(const i of r)t.includes(i.value)&&s.push(i);return s}const At=t=>new vt({options:t.options,initialValue:t.initialValue?[t.initialValue]:void 0,initialUserInput:t.initialUserInput,placeholder:t.placeholder,filter:t.filter??((r,s)=>Rt(r,s)),signal:t.signal,input:t.input,output:t.output,validate:t.validate,render(){const r=t.withGuide??_.withGuide,s=r?[`${e("gray",$)}`,`${M(this.state)} ${t.message}`]:[`${M(this.state)} ${t.message}`],i=this.userInput,u=this.options,n=t.placeholder,o=i===""&&n!==void 0,c=(a,l)=>{const d=Mt(a),y=a.hint&&a.value===this.focusedValue?e("dim",` (${a.hint})`):"";switch(l){case"active":return`${e("green",z)} ${d}${y}`;case"inactive":return`${e("dim",H)} ${e("dim",d)}`;case"disabled":return`${e("gray",H)} ${e(["strikethrough","gray"],d)}`}};switch(this.state){case"submit":{const a=se(this.selectedValues,u),l=a.length>0?` ${e("dim",a.map(Mt).join(", "))}`:"",d=r?e("gray",$):"";return`${s.join(`
|
|
`)}
|
|
${d}${l}`}case"cancel":{const a=i?` ${e(["strikethrough","dim"],i)}`:"",l=r?e("gray",$):"";return`${s.join(`
|
|
`)}
|
|
${l}${a}`}default:{const a=this.state==="error"?"yellow":"cyan",l=r?`${e(a,$)} `:"",d=r?e(a,E):"";let y="";if(this.isNavigating||o){const v=o?n:i;y=v!==""?` ${e("dim",v)}`:""}else y=` ${this.userInputWithCursor}`;const p=this.filteredOptions.length!==u.length?e("dim",` (${this.filteredOptions.length} match${this.filteredOptions.length===1?"":"es"})`):"",m=this.filteredOptions.length===0&&i?[`${l}${e("yellow","No matches found")}`]:[],g=this.state==="error"?[`${l}${e("yellow",this.error)}`]:[];r&&s.push(`${l.trimEnd()}`),s.push(`${l}${e("dim","Search:")}${y}${p}`,...m,...g);const S=[`${e("dim","\u2191/\u2193")} to select`,`${e("dim","Enter:")} confirm`,`${e("dim","Type:")} to search`],h=[`${l}${S.join(" \u2022 ")}`,d],f=this.filteredOptions.length===0?[]:Y({cursor:this.cursor,options:this.filteredOptions,columnPadding:r?3:0,rowPadding:s.length+h.length,style:(v,T)=>c(v,v.disabled?"disabled":T?"active":"inactive"),maxItems:t.maxItems,output:t.output});return[...s,...f.map(v=>`${l}${v}`),...h].join(`
|
|
`)}}}}).prompt(),ie=t=>{const r=(i,u,n,o)=>{const c=n.includes(i.value),a=i.label??String(i.value??""),l=i.hint&&o!==void 0&&i.value===o?e("dim",` (${i.hint})`):"",d=c?e("green",U):e("dim",J);return i.disabled?`${e("gray",J)} ${e(["strikethrough","gray"],a)}`:u?`${d} ${a}${l}`:`${d} ${e("dim",a)}`},s=new vt({options:t.options,multiple:!0,placeholder:t.placeholder,filter:t.filter??((i,u)=>Rt(i,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 i=t.withGuide??_.withGuide,u=`${i?`${e("gray",$)}
|
|
`:""}${M(this.state)} ${t.message}
|
|
`,n=this.userInput,o=t.placeholder,c=n===""&&o!==void 0,a=this.isNavigating||c?e("dim",c?o: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}${i?`${e("gray",$)} `:""}${e("dim",`${this.selectedValues.length} items selected`)}`;case"cancel":return`${u}${i?`${e("gray",$)} `:""}${e(["strikethrough","dim"],n)}`;default:{const y=this.state==="error"?"yellow":"cyan",p=i?`${e(y,$)} `:"",m=i?e(y,E):"",g=[`${e("dim","\u2191/\u2193")} to navigate`,`${e("dim",this.isNavigating?"Space/Tab:":"Tab:")} select`,`${e("dim","Enter:")} confirm`,`${e("dim","Type:")} to search`],S=this.filteredOptions.length===0&&n?[`${p}${e("yellow","No matches found")}`]:[],h=this.state==="error"?[`${p}${e("yellow",this.error)}`]:[],f=[...`${u}${i?e(y,$):""}`.split(`
|
|
`),`${p}${e("dim","Search:")} ${a}${d}`,...S,...h],v=[`${p}${g.join(" \u2022 ")}`,m],T=Y({cursor:this.cursor,options:this.filteredOptions,style:(C,b)=>r(C,b,this.selectedValues,this.focusedValue),maxItems:t.maxItems,output:t.output,rowPadding:f.length+v.length});return[...f,...T.map(C=>`${p}${C}`),...v].join(`
|
|
`)}}}});return s.prompt()},re=[Ot,ct,dt,$t],ne=[lt,It,E,Et];function Pt(t,r,s,i){let u=s,n=s;return i==="center"?u=Math.floor((r-t)/2):i==="right"&&(u=r-t-s),n=r-u-t,[u,n]}const ae=t=>t,oe=(t="",r="",s)=>{const i=s?.output??process.stdout,u=X(i),n=2,o=s?.titlePadding??1,c=s?.contentPadding??2,a=s?.width===void 0||s.width==="auto"?1:Math.min(1,s.width),l=s?.withGuide??_.withGuide?`${$} `:"",d=s?.formatBorder??ae,y=(s?.rounded?re:ne).map(d),p=d(st),m=d($),g=k(l),S=k(r),h=u-g;let f=Math.floor(u*a)-g;if(s?.width==="auto"){const P=t.split(`
|
|
`);let N=S+o*2;for(const rt of P){const W=k(rt)+c*2;W>N&&(N=W)}const D=N+n;D<f&&(f=D)}f%2!==0&&(f<h?f++:f--);const v=f-n,T=v-o*2,C=S>T?`${r.slice(0,T-3)}...`:r,[b,G]=Pt(k(C),v,o,s?.titleAlign),x=q(t,v-c*2,{hard:!0,trim:!1});i.write(`${l}${y[0]}${p.repeat(b)}${C}${p.repeat(G)}${y[1]}
|
|
`);const A=x.split(`
|
|
`);for(const P of A){const[N,D]=Pt(k(P),v,c,s?.contentAlign);i.write(`${l}${m}${" ".repeat(N)}${P}${" ".repeat(D)}${m}
|
|
`)}i.write(`${l}${y[2]}${p.repeat(v)}${y[3]}
|
|
`)},ue=t=>{const r=t.active??"Yes",s=t.inactive??"No";return new Lt({active:r,inactive:s,signal:t.signal,input:t.input,output:t.output,initialValue:t.initialValue??!0,render(){const i=t.withGuide??_.withGuide,u=`${M(this.state)} `,n=i?`${e("gray",$)} `:"",o=O(t.output,t.message,n,u),c=`${i?`${e("gray",$)}
|
|
`:""}${o}
|
|
`,a=this.value?r:s;switch(this.state){case"submit":{const l=i?`${e("gray",$)} `:"";return`${c}${l}${e("dim",a)}`}case"cancel":{const l=i?`${e("gray",$)} `:"";return`${c}${l}${e(["strikethrough","dim"],a)}${i?`
|
|
${e("gray",$)}`:""}`}default:{const l=i?`${e("cyan",$)} `:"",d=i?e("cyan",E):"";return`${c}${l}${this.value?`${e("green",z)} ${r}`:`${e("dim",H)} ${e("dim",r)}`}${t.vertical?i?`
|
|
${e("cyan",$)} `:`
|
|
`:` ${e("dim","/")} `}${this.value?`${e("dim",H)} ${e("dim",s)}`:`${e("green",z)} ${s}`}
|
|
${d}
|
|
`}}}}).prompt()},le=t=>{const r=t.validate;return new Dt({...t,validate(s){if(s===void 0)return t.defaultValue!==void 0?void 0:r?r(s):_.date.messages.required;const i=u=>u.toISOString().slice(0,10);if(t.minDate&&i(s)<i(t.minDate))return _.date.messages.afterMin(t.minDate);if(t.maxDate&&i(s)>i(t.maxDate))return _.date.messages.beforeMax(t.maxDate);if(r)return r(s)},render(){const s=(t?.withGuide??_.withGuide)!==!1,i=`${`${s?`${e("gray",$)}
|
|
`:""}${M(this.state)} `}${t.message}
|
|
`,u=this.state!=="initial"?this.state:"active",n=ce(this,u),o=this.value instanceof Date?this.formattedValue:"";switch(this.state){case"error":{const c=this.error?` ${e("yellow",this.error)}`:"",a=s?`${e("yellow",$)} `:"",l=s?e("yellow",E):"";return`${i.trim()}
|
|
${a}${n}
|
|
${l}${c}
|
|
`}case"submit":{const c=o?` ${e("dim",o)}`:"",a=s?e("gray",$):"";return`${i}${a}${c}`}case"cancel":{const c=o?` ${e(["strikethrough","dim"],o)}`:"",a=s?e("gray",$):"";return`${i}${a}${c}${o.trim()?`
|
|
${a}`:""}`}default:{const c=s?`${e("cyan",$)} `:"",a=s?e("cyan",E):"",l=s?`${e("cyan",$)} `:"",d=this.inlineError?`
|
|
${l}${e("yellow",this.inlineError)}`:"";return`${i}${c}${n}${d}
|
|
${a}
|
|
`}}}}).prompt()};function ce(t,r){const s=t.segmentValues,i=t.segmentCursor;if(r==="submit"||r==="cancel")return t.formattedValue;const u=e("gray",t.separator);return t.segments.map((n,o)=>{const c=o===i.segmentIndex&&!["submit","cancel"].includes(r),a=de[n.type];return $e(s[n.type],{isActive:c,label:a})}).join(u)}function $e(t,r){const s=!t||t.replace(/_/g,"")==="";return r.isActive?e("inverse",s?r.label:t.replace(/_/g," ")):s?e("dim",r.label):t.replace(/_/g,e("dim"," "))}const de={year:"yyyy",month:"mm",day:"dd"},he=async(t,r)=>{const s={},i=Object.keys(t);for(const u of i){const n=t[u],o=await n({results:s})?.catch(c=>{throw c});if(typeof r?.onCancel=="function"&&Wt(o)){s[u]="canceled",r.onCancel({results:s});continue}s[u]=o}return s},pe=t=>{const{selectableGroups:r=!0,groupSpacing:s=0}=t,i=(n,o,c=[])=>{const a=n.label??String(n.value),l=typeof n.group=="string",d=l&&(c[c.indexOf(n)+1]??{group:!0}),y=l&&d&&d.group===!0,p=l?r?`${y?E:$} `:" ":"";let m="";if(s>0&&!l){const S=`
|
|
${e("cyan",$)}`;m=`${S.repeat(s-1)}${S} `}if(o==="active")return`${m}${e("dim",p)}${e("cyan",et)} ${a}${n.hint?` ${e("dim",`(${n.hint})`)}`:""}`;if(o==="group-active")return`${m}${p}${e("cyan",et)} ${e("dim",a)}`;if(o==="group-active-selected")return`${m}${p}${e("green",U)} ${e("dim",a)}`;if(o==="selected"){const S=l||r?e("green",U):"";return`${m}${e("dim",p)}${S} ${e("dim",a)}${n.hint?` ${e("dim",`(${n.hint})`)}`:""}`}if(o==="cancelled")return`${e(["strikethrough","dim"],a)}`;if(o==="active-selected")return`${m}${e("dim",p)}${e("green",U)} ${a}${n.hint?` ${e("dim",`(${n.hint})`)}`:""}`;if(o==="submitted")return`${e("dim",a)}`;const g=l||r?e("dim",J):"";return`${m}${e("dim",p)}${g} ${e("dim",a)}`},u=t.required??!0;return new Ft({options:t.options,signal:t.signal,input:t.input,output:t.output,initialValues:t.initialValues,required:u,cursorAt:t.cursorAt,selectableGroups:r,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??_.withGuide,o=`${n?`${e("gray",$)}
|
|
`:""}${M(this.state)} ${t.message}
|
|
`,c=this.value??[];switch(this.state){case"submit":{const a=this.options.filter(({value:d})=>c.includes(d)).map(d=>i(d,"submitted")),l=a.length===0?"":` ${a.join(e("dim",", "))}`;return`${o}${n?e("gray",$):""}${l}`}case"cancel":{const a=this.options.filter(({value:l})=>c.includes(l)).map(l=>i(l,"cancelled")).join(e("dim",", "));return`${o}${n?`${e("gray",$)} `:""}${a.trim()?`${a}${n?`
|
|
${e("gray",$)}`:""}`:""}`}case"error":{const a=this.error.split(`
|
|
`).map((l,d)=>d===0?`${n?`${e("yellow",E)} `:""}${e("yellow",l)}`:` ${l}`).join(`
|
|
`);return`${o}${n?`${e("yellow",$)} `:""}${this.options.map((l,d,y)=>{const p=c.includes(l.value)||l.group===!0&&this.isGroupSelected(`${l.value}`),m=d===this.cursor;return!m&&typeof l.group=="string"&&this.options[this.cursor].value===l.group?i(l,p?"group-active-selected":"group-active",y):m&&p?i(l,"active-selected",y):p?i(l,"selected",y):i(l,m?"active":"inactive",y)}).join(`
|
|
${n?`${e("yellow",$)} `:""}`)}
|
|
${a}
|
|
`}default:{const a=this.options.map((d,y,p)=>{const m=c.includes(d.value)||d.group===!0&&this.isGroupSelected(`${d.value}`),g=y===this.cursor,S=!g&&typeof d.group=="string"&&this.options[this.cursor].value===d.group;let h="";return S?h=i(d,m?"group-active-selected":"group-active",p):g&&m?h=i(d,"active-selected",p):m?h=i(d,"selected",p):h=i(d,g?"active":"inactive",p),`${y!==0&&!h.startsWith(`
|
|
`)?" ":""}${h}`}).join(`
|
|
${n?e("cyan",$):""}`),l=a.startsWith(`
|
|
`)?"":" ";return`${o}${n?e("cyan",$):""}${l}${a}
|
|
${n?e("cyan",E):""}
|
|
`}}}}).prompt()},R={message:(t=[],{symbol:r=e("gray",$),secondarySymbol:s=e("gray",$),output:i=process.stdout,spacing:u=1,withGuide:n}={})=>{const o=[],c=n??_.withGuide,a=c?s:"",l=c?`${r} `:"",d=c?`${s} `:"";for(let p=0;p<u;p++)o.push(a);const y=Array.isArray(t)?t:t.split(`
|
|
`);if(y.length>0){const[p,...m]=y;p.length>0?o.push(`${l}${p}`):o.push(c?r:"");for(const g of m)g.length>0?o.push(`${d}${g}`):o.push(c?s:"")}i.write(`${o.join(`
|
|
`)}
|
|
`)},info:(t,r)=>{R.message(t,{...r,symbol:e("blue",ht)})},success:(t,r)=>{R.message(t,{...r,symbol:e("green",pt)})},step:(t,r)=>{R.message(t,{...r,symbol:e("green",F)})},warn:(t,r)=>{R.message(t,{...r,symbol:e("yellow",mt)})},warning:(t,r)=>{R.warn(t,r)},error:(t,r)=>{R.message(t,{...r,symbol:e("red",gt)})}},me=(t="",r)=>{const s=r?.output??process.stdout,i=r?.withGuide??_.withGuide?`${e("gray",E)} `:"";s.write(`${i}${e("red",t)}
|
|
|
|
`)},ge=(t="",r)=>{const s=r?.output??process.stdout,i=r?.withGuide??_.withGuide?`${e("gray",lt)} `:"";s.write(`${i}${t}
|
|
`)},ye=(t="",r)=>{const s=r?.output??process.stdout,i=r?.withGuide??_.withGuide?`${e("gray",$)}
|
|
${e("gray",E)} `:"";s.write(`${i}${t}
|
|
|
|
`)},fe=t=>new Ht({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 r=t?.withGuide??_.withGuide,s=`${`${r?`${e("gray",$)}
|
|
`:""}${M(this.state)} `}${t.message}
|
|
`,i=t.placeholder?e("inverse",t.placeholder[0])+e("dim",t.placeholder.slice(1)):e(["inverse","hidden"],"_"),u=this.userInput?this.userInputWithCursor:i,n=this.value??"",o=t.showSubmit?`
|
|
${e(this.focused==="submit"?"cyan":"dim","[ submit ]")}`:"";switch(this.state){case"error":{const c=`${e("yellow",$)} `,a=r?O(t.output,u,c,void 0):u,l=e("yellow",E);return`${s}${a}
|
|
${l} ${e("yellow",this.error)}${o}
|
|
`}case"submit":{const c=`${e("gray",$)} `,a=r?O(t.output,n,c,void 0,l=>e("dim",l)):n?e("dim",n):"";return`${s}${a}`}case"cancel":{const c=`${e("gray",$)} `,a=r?O(t.output,n,c,void 0,l=>e(["strikethrough","dim"],l)):n?e(["strikethrough","dim"],n):"";return`${s}${a}`}default:{const c=r?`${e("cyan",$)} `:"",a=r?e("cyan",E):"",l=r?O(t.output,u,c):u;return`${s}${l}
|
|
${a}${o}
|
|
`}}}}).prompt(),Q=(t,r)=>t.split(`
|
|
`).map(s=>r(s)).join(`
|
|
`),ve=t=>{const r=(i,u)=>{const n=i.label??String(i.value);return u==="disabled"?`${e("gray",J)} ${Q(n,o=>e(["strikethrough","gray"],o))}${i.hint?` ${e("dim",`(${i.hint??"disabled"})`)}`:""}`:u==="active"?`${e("cyan",et)} ${n}${i.hint?` ${e("dim",`(${i.hint})`)}`:""}`:u==="selected"?`${e("green",U)} ${Q(n,o=>e("dim",o))}${i.hint?` ${e("dim",`(${i.hint})`)}`:""}`:u==="cancelled"?`${Q(n,o=>e(["strikethrough","dim"],o))}`:u==="active-selected"?`${e("green",U)} ${n}${i.hint?` ${e("dim",`(${i.hint})`)}`:""}`:u==="submitted"?`${Q(n,o=>e("dim",o))}`:`${e("dim",J)} ${Q(n,o=>e("dim",o))}`},s=t.required??!0;return new Ut({options:t.options,signal:t.signal,input:t.input,output:t.output,initialValues:t.initialValues,required:s,cursorAt:t.cursorAt,validate(i){if(s&&(i===void 0||i.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 i=t.withGuide??_.withGuide,u=O(t.output,t.message,i?`${yt(this.state)} `:"",`${M(this.state)} `),n=`${i?`${e("gray",$)}
|
|
`:""}${u}
|
|
`,o=this.value??[],c=(a,l)=>{if(a.disabled)return r(a,"disabled");const d=o.includes(a.value);return l&&d?r(a,"active-selected"):d?r(a,"selected"):r(a,l?"active":"inactive")};switch(this.state){case"submit":{const a=this.options.filter(({value:d})=>o.includes(d)).map(d=>r(d,"submitted")).join(e("dim",", "))||e("dim","none"),l=O(t.output,a,i?`${e("gray",$)} `:"");return`${n}${l}`}case"cancel":{const a=this.options.filter(({value:d})=>o.includes(d)).map(d=>r(d,"cancelled")).join(e("dim",", "));if(a.trim()==="")return`${n}${e("gray",$)}`;const l=O(t.output,a,i?`${e("gray",$)} `:"");return`${n}${l}${i?`
|
|
${e("gray",$)}`:""}`}case"error":{const a=i?`${e("yellow",$)} `:"",l=this.error.split(`
|
|
`).map((p,m)=>m===0?`${i?`${e("yellow",E)} `:""}${e("yellow",p)}`:` ${p}`).join(`
|
|
`),d=n.split(`
|
|
`).length,y=l.split(`
|
|
`).length+1;return`${n}${a}${Y({output:t.output,options:this.options,cursor:this.cursor,maxItems:t.maxItems,columnPadding:a.length,rowPadding:d+y,style:c}).join(`
|
|
${a}`)}
|
|
${l}
|
|
`}default:{const a=i?`${e("cyan",$)} `:"",l=n.split(`
|
|
`).length,d=i?2:1;return`${n}${a}${Y({output:t.output,options:this.options,cursor:this.cursor,maxItems:t.maxItems,columnPadding:a.length,rowPadding:l+d,style:c}).join(`
|
|
${a}`)}
|
|
${i?e("cyan",E):""}
|
|
`}}}}).prompt()},we=t=>e("dim",t),be=(t,r,s)=>{const i={hard:!0,trim:!1},u=q(t,r,i).split(`
|
|
`),n=u.reduce((a,l)=>Math.max(k(l),a),0),o=u.map(s).reduce((a,l)=>Math.max(k(l),a),0),c=r-(o-n);return q(t,c,i)},Se=(t="",r="",s)=>{const i=s?.output??j.stdout,u=s?.withGuide??_.withGuide,n=s?.format??we,o=["",...be(t,X(i)-6,n).split(`
|
|
`).map(n),""],c=k(r),a=Math.max(o.reduce((p,m)=>{const g=k(m);return g>p?g:p},0),c)+2,l=o.map(p=>`${e("gray",$)} ${p}${" ".repeat(a-k(p))}${e("gray",$)}`).join(`
|
|
`),d=u?`${e("gray",$)}
|
|
`:"",y=u?xt:dt;i.write(`${d}${e("green",F)} ${e("reset",r)} ${e("gray",st.repeat(Math.max(a-c-1,1))+ct)}
|
|
${l}
|
|
${e("gray",y+st.repeat(a+2)+$t)}
|
|
`)},Ce=t=>new Kt({validate:t.validate,mask:t.mask??Gt,signal:t.signal,input:t.input,output:t.output,render(){const r=t.withGuide??_.withGuide,s=`${r?`${e("gray",$)}
|
|
`:""}${M(this.state)} ${t.message}
|
|
`,i=this.userInputWithCursor,u=this.masked;switch(this.state){case"error":{const n=r?`${e("yellow",$)} `:"",o=r?`${e("yellow",E)} `:"",c=u??"";return t.clearOnError&&this.clear(),`${s.trim()}
|
|
${n}${c}
|
|
${o}${e("yellow",this.error)}
|
|
`}case"submit":{const n=r?`${e("gray",$)} `:"",o=u?e("dim",u):"";return`${s}${n}${o}`}case"cancel":{const n=r?`${e("gray",$)} `:"",o=u?e(["strikethrough","dim"],u):"";return`${s}${n}${o}${u&&r?`
|
|
${e("gray",$)}`:""}`}default:{const n=r?`${e("cyan",$)} `:"",o=r?e("cyan",E):"";return`${s}${n}${i}
|
|
${o}
|
|
`}}}}).prompt(),Te=t=>{const r=t.validate;return At({...t,initialUserInput:t.initialValue??t.root??process.cwd(),maxItems:5,validate(s){if(!Array.isArray(s)){if(!s)return"Please select a path";if(r)return r(s)}},options(){const s=this.userInput;if(s==="")return[];try{let i;zt(s)?wt(s).isDirectory()&&(!t.directory||s.endsWith("/"))?i=s:i=bt(s):i=bt(s);const u=s.length>1&&s.endsWith("/")?s.slice(0,-1):s;return Qt(i).map(n=>{const o=Zt(i,n),c=wt(o);return{name:n,path:o,isDirectory:c.isDirectory()}}).filter(({path:n,isDirectory:o})=>n.startsWith(u)&&(o||!t.directory)).map(n=>({value:n.path}))}catch{return[]}}})},_e=t=>e("magenta",t),ft=({indicator:t="dots",onCancel:r,output:s=process.stdout,cancelMessage:i,errorMessage:u,frames:n=tt?["\u25D2","\u25D0","\u25D3","\u25D1"]:["\u2022","o","O","0"],delay:o=tt?80:120,signal:c,...a}={})=>{const l=at();let d,y,p=!1,m=!1,g="",S,h=performance.now();const f=X(s),v=a?.styleFrame??_e,T=I=>{const V=I>1?u??_.messages.error:i??_.messages.cancel;m=I===1,p&&(W(V,I),m&&typeof r=="function"&&r())},C=()=>T(2),b=()=>T(1),G=()=>{process.on("uncaughtExceptionMonitor",C),process.on("unhandledRejection",C),process.on("SIGINT",b),process.on("SIGTERM",b),process.on("exit",T),c&&c.addEventListener("abort",b)},x=()=>{process.removeListener("uncaughtExceptionMonitor",C),process.removeListener("unhandledRejection",C),process.removeListener("SIGINT",b),process.removeListener("SIGTERM",b),process.removeListener("exit",T),c&&c.removeEventListener("abort",b)},A=()=>{if(S===void 0)return;l&&s.write(`
|
|
`);const I=q(S,f,{hard:!0,trim:!1}).split(`
|
|
`);I.length>1&&s.write(St.up(I.length-1)),s.write(St.to(0)),s.write(Ct.down())},P=I=>I.replace(/\.+$/,""),N=I=>{const V=(performance.now()-I)/1e3,B=Math.floor(V/60),L=Math.floor(V%60);return B>0?`[${B}m ${L}s]`:`[${L}s]`},D=a.withGuide??_.withGuide,rt=(I="")=>{p=!0,d=qt({output:s}),g=P(I),h=performance.now(),D&&s.write(`${e("gray",$)}
|
|
`);let V=0,B=0;G(),y=setInterval(()=>{if(l&&g===S)return;A(),S=g;const L=v(n[V]);let Z;if(l)Z=`${L} ${g}...`;else if(t==="timer")Z=`${L} ${g} ${N(h)}`;else{const kt=".".repeat(Math.floor(B)).slice(0,3);Z=`${L} ${g}${kt}`}const Nt=q(Z,f,{hard:!0,trim:!1});s.write(Nt),V=V+1<n.length?V+1:0,B=B<4?B+.125:0},o)},W=(I="",V=0,B=!1)=>{if(!p)return;p=!1,clearInterval(y),A();const L=V===0?e("green",F):V===1?e("red",ot):e("red",ut);g=I??g,B||(t==="timer"?s.write(`${L} ${g} ${N(h)}
|
|
`):s.write(`${L} ${g}
|
|
`)),x(),d()};return{start:rt,stop:(I="")=>W(I,0),message:(I="")=>{g=P(I??g)},cancel:(I="")=>W(I,1),error:(I="")=>W(I,2),clear:()=>W("",0,!0),get isCancelled(){return m}}},Vt={light:w("\u2500","-"),heavy:w("\u2501","="),block:w("\u2588","#")};function Ie({style:t="heavy",max:r=100,size:s=40,...i}={}){const u=ft(i);let n=0,o="";const c=Math.max(1,r),a=Math.max(1,s),l=m=>{switch(m){case"initial":case"active":return g=>e("magenta",g);case"error":case"cancel":return g=>e("red",g);case"submit":return g=>e("green",g);default:return g=>e("magenta",g)}},d=(m,g)=>{const S=Math.floor(n/c*a);return`${l(m)(Vt[t].repeat(S))}${e("dim",Vt[t].repeat(a-S))} ${g}`},y=(m="")=>{o=m,u.start(d("initial",m))},p=(m=1,g)=>{n=Math.min(c,m+n),u.message(d("active",g??o)),o=g??o};return{start:y,stop:u.stop,cancel:u.cancel,error:u.error,clear:u.clear,advance:p,isCancelled:u.isCancelled,message:m=>p(0,m)}}const it=(t,r)=>t.includes(`
|
|
`)?t.split(`
|
|
`).map(s=>r(s)).join(`
|
|
`):r(t),Ee=t=>{const r=(s,i)=>{const u=s.label??String(s.value);switch(i){case"disabled":return`${e("gray",H)} ${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",H)} ${it(u,n=>e("dim",n))}`}};return new Jt({options:t.options,signal:t.signal,input:t.input,output:t.output,initialValue:t.initialValue,render(){const s=t.withGuide??_.withGuide,i=`${M(this.state)} `,u=`${yt(this.state)} `,n=O(t.output,t.message,u,i),o=`${s?`${e("gray",$)}
|
|
`:""}${n}
|
|
`;switch(this.state){case"submit":{const c=s?`${e("gray",$)} `:"",a=O(t.output,r(this.options[this.cursor],"selected"),c);return`${o}${a}`}case"cancel":{const c=s?`${e("gray",$)} `:"",a=O(t.output,r(this.options[this.cursor],"cancelled"),c);return`${o}${a}${s?`
|
|
${e("gray",$)}`:""}`}default:{const c=s?`${e("cyan",$)} `:"",a=s?e("cyan",E):"",l=o.split(`
|
|
`).length,d=s?2:1;return`${o}${c}${Y({output:t.output,cursor:this.cursor,options:this.options,maxItems:t.maxItems,columnPadding:c.length,rowPadding:l+d,style:(y,p)=>r(y,y.disabled?"disabled":p?"active":"inactive")}).join(`
|
|
${c}`)}
|
|
${a}
|
|
`}}}}).prompt()},Ge=t=>{const r=(s,i="inactive")=>{const u=s.label??String(s.value);return i==="selected"?`${e("dim",u)}`:i==="cancelled"?`${e(["strikethrough","dim"],u)}`:i==="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 Yt({options:t.options,signal:t.signal,input:t.input,output:t.output,initialValue:t.initialValue,caseSensitive:t.caseSensitive,render(){const s=t.withGuide??_.withGuide,i=`${s?`${e("gray",$)}
|
|
`:""}${M(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],o=O(t.output,r(n,"selected"),u);return`${i}${o}`}case"cancel":{const u=s?`${e("gray",$)} `:"",n=O(t.output,r(this.options[0],"cancelled"),u);return`${i}${n}${s?`
|
|
${e("gray",$)}`:""}`}default:{const u=s?`${e("cyan",$)} `:"",n=s?e("cyan",E):"",o=this.options.map((c,a)=>O(t.output,r(c,a===this.cursor?"active":"inactive"),u)).join(`
|
|
`);return`${i}${o}
|
|
${n}
|
|
`}}}}).prompt()},jt=`${e("gray",$)} `,K={message:async(t,{symbol:r=e("gray",$)}={})=>{process.stdout.write(`${e("gray",$)}
|
|
${r} `);let s=3;for await(let i of t){i=i.replace(/\n/g,`
|
|
${jt}`),i.includes(`
|
|
`)&&(s=3+nt(i.slice(i.lastIndexOf(`
|
|
`))).length);const u=nt(i).length;s+u<process.stdout.columns?(s+=u,process.stdout.write(i)):(process.stdout.write(`
|
|
${jt}${i.trimStart()}`),s=3+nt(i.trimStart()).length)}process.stdout.write(`
|
|
`)},info:t=>K.message(t,{symbol:e("blue",ht)}),success:t=>K.message(t,{symbol:e("green",pt)}),step:t=>K.message(t,{symbol:e("green",F)}),warn:t=>K.message(t,{symbol:e("yellow",mt)}),warning:t=>K.warn(t),error:t=>K.message(t,{symbol:e("red",gt)})},xe=async(t,r)=>{for(const s of t){if(s.enabled===!1)continue;const i=ft(r);i.start(s.title);const u=await s.task(i.message);i.stop(u||s.title)}},Oe=t=>t.replace(/\x1b\[(?:\d+;)*\d*[ABCDEFGHfJKSTsu]|\x1b\[(s|u)/g,""),Me=t=>{const r=t.output??process.stdout,s=X(r),i=e("gray",$),u=t.spacing??1,n=3,o=t.retainLog===!0,c=!at()&&Tt(r);r.write(`${i}
|
|
`),r.write(`${e("green",F)} ${t.title}
|
|
`);for(let h=0;h<u;h++)r.write(`${i}
|
|
`);const a=[{value:"",full:""}];let l=!1;const d=h=>{if(a.length===0)return;let f=0;h&&(f+=u+2);for(const v of a){const{value:T,result:C}=v;let b=C?.message??T;if(b.length===0)continue;C===void 0&&v.header!==void 0&&v.header!==""&&(b+=`
|
|
${v.header}`);const G=b.split(`
|
|
`).reduce((x,A)=>A===""?x+1:x+Math.ceil((A.length+n)/s),0);f+=G}f>0&&(f+=1,r.write(Ct.lines(f)))},y=(h,f,v)=>{const T=v?`${h.full}
|
|
${h.value}`:h.value;h.header!==void 0&&h.header!==""&&R.message(h.header.split(`
|
|
`).map(C=>e("bold",C)),{output:r,secondarySymbol:i,symbol:i,spacing:0}),R.message(T.split(`
|
|
`).map(C=>e("dim",C)),{output:r,secondarySymbol:i,symbol:i,spacing:f??u})},p=()=>{for(const h of a){const{header:f,value:v,full:T}=h;(f===void 0||f.length===0)&&v.length===0||y(h,void 0,o===!0&&T.length>0)}},m=(h,f,v)=>{if(d(!1),(v?.raw!==!0||!l)&&h.value!==""&&(h.value+=`
|
|
`),h.value+=Oe(f),l=v?.raw===!0,t.limit!==void 0){const T=h.value.split(`
|
|
`),C=T.length-t.limit;if(C>0){const b=T.splice(0,C);o&&(h.full+=(h.full===""?"":`
|
|
`)+b.join(`
|
|
`))}h.value=T.join(`
|
|
`)}c&&g()},g=()=>{for(const h of a)h.result?h.result.status==="error"?R.error(h.result.message,{output:r,secondarySymbol:i,spacing:0}):R.success(h.result.message,{output:r,secondarySymbol:i,spacing:0}):h.value!==""&&y(h,0)},S=(h,f)=>{d(!1),h.result=f,c&&g()};return{message(h,f){m(a[0],h,f)},group(h){const f={header:h,value:"",full:""};return a.push(f),{message(v,T){m(f,v,T)},error(v){S(f,{status:"error",message:v})},success(v){S(f,{status:"success",message:v})}}},error(h,f){d(!0),R.error(h,{output:r,secondarySymbol:i,spacing:1}),f?.showLog!==!1&&p(),a.splice(1,a.length-1),a[0].value="",a[0].full=""},success(h,f){d(!0),R.success(h,{output:r,secondarySymbol:i,spacing:1}),f?.showLog===!0&&p(),a.splice(1,a.length-1),a[0].value="",a[0].full=""}}},Re=t=>new Xt({validate:t.validate,placeholder:t.placeholder,defaultValue:t.defaultValue,initialValue:t.initialValue,output:t.output,signal:t.signal,input:t.input,render(){const r=t?.withGuide??_.withGuide,s=`${`${r?`${e("gray",$)}
|
|
`:""}${M(this.state)} `}${t.message}
|
|
`,i=t.placeholder?e("inverse",t.placeholder[0])+e("dim",t.placeholder.slice(1)):e(["inverse","hidden"],"_"),u=this.userInput?this.userInputWithCursor:i,n=this.value??"";switch(this.state){case"error":{const o=this.error?` ${e("yellow",this.error)}`:"",c=r?`${e("yellow",$)} `:"",a=r?e("yellow",E):"";return`${s.trim()}
|
|
${c}${u}
|
|
${a}${o}
|
|
`}case"submit":{const o=n?` ${e("dim",n)}`:"",c=r?e("gray",$):"";return`${s}${c}${o}`}case"cancel":{const o=n?` ${e(["strikethrough","dim"],n)}`:"",c=r?e("gray",$):"";return`${s}${c}${o}${n.trim()?`
|
|
${c}`:""}`}default:{const o=r?`${e("cyan",$)} `:"",c=r?e("cyan",E):"";return`${s}${o}${u}
|
|
${c}
|
|
`}}}}).prompt();export{$ as S_BAR,E as S_BAR_END,Et as S_BAR_END_RIGHT,st as S_BAR_H,lt as S_BAR_START,It as S_BAR_START_RIGHT,et as S_CHECKBOX_ACTIVE,J as S_CHECKBOX_INACTIVE,U as S_CHECKBOX_SELECTED,xt as S_CONNECT_LEFT,dt as S_CORNER_BOTTOM_LEFT,$t as S_CORNER_BOTTOM_RIGHT,Ot as S_CORNER_TOP_LEFT,ct as S_CORNER_TOP_RIGHT,gt as S_ERROR,ht as S_INFO,Gt as S_PASSWORD_MASK,z as S_RADIO_ACTIVE,H as S_RADIO_INACTIVE,_t as S_STEP_ACTIVE,ot as S_STEP_CANCEL,ut as S_STEP_ERROR,F as S_STEP_SUBMIT,pt as S_SUCCESS,mt as S_WARN,At as autocomplete,ie as autocompleteMultiselect,oe as box,me as cancel,ue as confirm,le as date,he as group,pe as groupMultiselect,ge as intro,at as isCI,Tt as isTTY,Y as limitOptions,R as log,fe as multiline,ve as multiselect,Se as note,ye as outro,Ce as password,Te as path,Ie as progress,Ee as select,Ge as selectKey,ft as spinner,K as stream,M as symbol,yt as symbolBar,Me as taskLog,xe as tasks,Re as text,tt as unicode,w as unicodeOr};
|
|
//# sourceMappingURL=index.mjs.map
|