push neon reactor
This commit is contained in:
+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