import { stdin , stdout } from 'node:process' ;
import f from 'node:readline' ;
import { WriteStream } from 'node:tty' ;
import { g as getDefaultExportFromCjs , i as isUnicodeSupported } from '../shared/consola.36c0034f.mjs' ;
import require$$0 from 'tty' ;
import { colors } from '../utils.mjs' ;
import '../core.mjs' ;
import '../shared/consola.06ad8a64.mjs' ;
import 'node:util' ;
import 'node:path' ;
const ESC = '\x1B' ;
const CSI = ` ${ ESC } [ ` ;
const beep = '\u0007' ;
const cursor = {
to ( x , y ) {
if ( ! y ) return ` ${ CSI } ${ x + 1 } G ` ;
return ` ${ CSI } ${ y + 1 } ; ${ x + 1 } H ` ;
} ,
move ( x , y ) {
let ret = '' ;
if ( x < 0 ) ret += ` ${ CSI } ${ - x } D ` ;
else if ( x > 0 ) ret += ` ${ CSI } ${ x } C ` ;
if ( y < 0 ) ret += ` ${ CSI } ${ - y } A ` ;
else if ( y > 0 ) ret += ` ${ CSI } ${ y } B ` ;
return ret ;
} ,
up : ( count = 1 ) => ` ${ CSI } ${ count } A ` ,
down : ( count = 1 ) => ` ${ CSI } ${ count } B ` ,
forward : ( count = 1 ) => ` ${ CSI } ${ count } C ` ,
backward : ( count = 1 ) => ` ${ CSI } ${ count } D ` ,
nextLine : ( count = 1 ) => ` ${ CSI } E ` . repeat ( count ) ,
prevLine : ( count = 1 ) => ` ${ CSI } F ` . repeat ( count ) ,
left : ` ${ CSI } G ` ,
hide : ` ${ CSI } ?25l ` ,
show : ` ${ CSI } ?25h ` ,
save : ` ${ ESC } 7 ` ,
restore : ` ${ ESC } 8 `
} ;
const scroll = {
up : ( count = 1 ) => ` ${ CSI } S ` . repeat ( count ) ,
down : ( count = 1 ) => ` ${ CSI } T ` . repeat ( count )
} ;
const erase = {
screen : ` ${ CSI } 2J ` ,
up : ( count = 1 ) => ` ${ CSI } 1J ` . repeat ( count ) ,
down : ( count = 1 ) => ` ${ CSI } J ` . repeat ( count ) ,
line : ` ${ CSI } 2K ` ,
lineEnd : ` ${ CSI } K ` ,
lineStart : ` ${ CSI } 1K ` ,
lines ( count ) {
let clear = '' ;
for ( let i = 0 ; i < count ; i ++ )
clear += this . line + ( i < count - 1 ? cursor . up ( ) : '' ) ;
if ( count )
clear += cursor . left ;
return clear ;
}
} ;
var src = { cursor , scroll , erase , beep } ;
var picocolors = { exports : { } } ;
let tty = require$$0 ;
let isColorSupported =
! ( "NO_COLOR" in process . env || process . argv . includes ( "--no-color" ) ) &&
( "FORCE_COLOR" in process . env ||
process . argv . includes ( "--color" ) ||
process . platform === "win32" ||
( tty . isatty ( 1 ) && process . env . TERM !== "dumb" ) ||
"CI" in process . env ) ;
let formatter =
( open , close , replace = open ) =>
input => {
let string = "" + input ;
let index = string . indexOf ( close , open . length ) ;
return ~ index
? open + replaceClose ( string , close , replace , index ) + close
: open + string + close
} ;
let replaceClose = ( string , close , replace , index ) => {
let start = string . substring ( 0 , index ) + replace ;
let end = string . substring ( index + close . length ) ;
let nextIndex = end . indexOf ( close ) ;
return ~ nextIndex ? start + replaceClose ( end , close , replace , nextIndex ) : start + end
} ;
let createColors = ( enabled = isColorSupported ) => ( {
isColorSupported : enabled ,
reset : enabled ? s => ` \x 1b[0m ${ s } \x 1b[0m ` : String ,
bold : enabled ? formatter ( "\x1b[1m" , "\x1b[22m" , "\x1b[22m\x1b[1m" ) : String ,
dim : enabled ? formatter ( "\x1b[2m" , "\x1b[22m" , "\x1b[22m\x1b[2m" ) : String ,
italic : enabled ? formatter ( "\x1b[3m" , "\x1b[23m" ) : String ,
underline : enabled ? formatter ( "\x1b[4m" , "\x1b[24m" ) : String ,
inverse : enabled ? formatter ( "\x1b[7m" , "\x1b[27m" ) : String ,
hidden : enabled ? formatter ( "\x1b[8m" , "\x1b[28m" ) : String ,
strikethrough : enabled ? formatter ( "\x1b[9m" , "\x1b[29m" ) : String ,
black : enabled ? formatter ( "\x1b[30m" , "\x1b[39m" ) : String ,
red : enabled ? formatter ( "\x1b[31m" , "\x1b[39m" ) : String ,
green : enabled ? formatter ( "\x1b[32m" , "\x1b[39m" ) : String ,
yellow : enabled ? formatter ( "\x1b[33m" , "\x1b[39m" ) : String ,
blue : enabled ? formatter ( "\x1b[34m" , "\x1b[39m" ) : String ,
magenta : enabled ? formatter ( "\x1b[35m" , "\x1b[39m" ) : String ,
cyan : enabled ? formatter ( "\x1b[36m" , "\x1b[39m" ) : String ,
white : enabled ? formatter ( "\x1b[37m" , "\x1b[39m" ) : String ,
gray : enabled ? formatter ( "\x1b[90m" , "\x1b[39m" ) : String ,
bgBlack : enabled ? formatter ( "\x1b[40m" , "\x1b[49m" ) : String ,
bgRed : enabled ? formatter ( "\x1b[41m" , "\x1b[49m" ) : String ,
bgGreen : enabled ? formatter ( "\x1b[42m" , "\x1b[49m" ) : String ,
bgYellow : enabled ? formatter ( "\x1b[43m" , "\x1b[49m" ) : String ,
bgBlue : enabled ? formatter ( "\x1b[44m" , "\x1b[49m" ) : String ,
bgMagenta : enabled ? formatter ( "\x1b[45m" , "\x1b[49m" ) : String ,
bgCyan : enabled ? formatter ( "\x1b[46m" , "\x1b[49m" ) : String ,
bgWhite : enabled ? formatter ( "\x1b[47m" , "\x1b[49m" ) : String ,
} ) ;
picocolors . exports = createColors ( ) ;
picocolors . exports . createColors = createColors ;
var picocolorsExports = picocolors . exports ;
const l = /*@__PURE__*/ getDefaultExportFromCjs ( picocolorsExports ) ;
function z ( { onlyFirst : t = ! 1 } = { } ) { const u = [ "[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)" , "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))" ] . join ( "|" ) ; return new RegExp ( u , t ? void 0 : "g" ) } function $ ( t ) { if ( typeof t != "string" ) throw new TypeError ( ` Expected a \` string \` , got \` ${ typeof t } \` ` ) ; return t . replace ( z ( ) , "" ) } var m = { } , G = { get exports ( ) { return m } , set exports ( t ) { m = t ; } } ; ( function ( t ) { var u = { } ; t . exports = u , u . eastAsianWidth = function ( e ) { var s = e . charCodeAt ( 0 ) , C = e . length == 2 ? e . charCodeAt ( 1 ) : 0 , D = s ; return 55296 <= s && s <= 56319 && 56320 <= C && C <= 57343 && ( s &= 1023 , C &= 1023 , D = s << 10 | C , D += 65536 ) , D == 12288 || 65281 <= D && D <= 65376 || 65504 <= D && D <= 65510 ? "F" : D == 8361 || 65377 <= D && D <= 65470 || 65474 <= D && D <= 65479 || 65482 <= D && D <= 65487 || 65490 <= D && D <= 65495 || 65498 <= D && D <= 65500 || 65512 <= D && D <= 65518 ? "H" : 4352 <= D && D <= 4447 || 4515 <= D && D <= 4519 || 4602 <= D && D <= 4607 || 9001 <= D && D <= 9002 || 11904 <= D && D <= 11929 || 11931 <= D && D <= 12019 || 12032 <= D && D <= 12245 || 12272 <= D && D <= 12283 || 12289 <= D && D <= 12350 || 12353 <= D && D <= 12438 || 12441 <= D && D <= 12543 || 12549 <= D && D <= 12589 || 12593 <= D && D <= 12686 || 12688 <= D && D <= 12730 || 12736 <= D && D <= 12771 || 12784 <= D && D <= 12830 || 12832 <= D && D <= 12871 || 12880 <= D && D <= 13054 || 13056 <= D && D <= 19903 || 19968 <= D && D <= 42124 || 42128 <= D && D <= 42182 || 43360 <= D && D <= 43388 || 44032 <= D && D <= 55203 || 55216 <= D && D <= 55238 || 55243 <= D && D <= 55291 || 63744 <= D && D <= 64255 || 65040 <= D && D <= 65049 || 65072 <= D && D <= 65106 || 65108 <= D && D <= 65126 || 65128 <= D && D <= 65131 || 110592 <= D && D <= 110593 || 127488 <= D && D <= 127490 || 127504 <= D && D <= 127546 || 127552 <= D && D <= 127560 || 127568 <= D && D <= 127569 || 131072 <= D && D <= 194367 || 177984 <= D && D <= 196605 || 196608 <= D && D <= 262141 ? "W" : 32 <= D && D <= 126 || 162 <= D && D <= 163 || 165 <= D && D <= 166 || D == 172 || D == 175 || 10214 <= D && D <= 10221 || 10629 <= D && D <= 10630 ? "Na" : D == 161 || D == 164 || 167 <= D && D <= 168 || D == 170 || 173 <= D && D <= 174 || 176 <= D && D <= 180 || 182 <= D && D <= 186 || 188 <= D && D <= 191 || D == 198 || D == 208 || 215 <= D && D <= 216 || 222 <= D && D <= 225 || D == 230 || 232 <= D && D <= 234 || 236 <= D && D <= 237 || D == 240 || 242 <= D && D <= 243 || 247 <= D && D <= 250 || D == 252 || D == 254 || D == 257 || D == 273 || D == 275 || D == 283 || 294 <= D && D <= 295 || D == 299 || 305 <= D && D <= 307 || D == 312 || 319 <= D && D <= 322 || D == 324 || 328 <= D && D <= 331 || D == 333 || 338 <= D && D <= 339 || 358 <= D && D <= 359 || D == 363 || D == 462 || D == 464 || D == 466 || D == 468 || D == 470 || D == 472 || D == 474 || D == 476 || D == 593 || D == 609 || D == 708 || D == 711 || 713 <= D && D <= 715 || D == 717 || D == 720 || 728 <= D && D <= 731 || D == 733 || D == 735 || 768 <= D && D <= 879 || 913 <= D && D <= 929 || 931 <= D && D <= 937 || 945 <= D && D <= 961 || 963 <= D && D <= 969 || D == 1025 || 1040 <= D && D <= 1103 || D == 1105 || D == 8208 || 8211 <= D && D <= 8214 || 8216 <= D && D <= 8217 || 8220 <= D && D <= 8221 || 8224 <= D && D <= 8226 || 8228 <= D && D <= 8231 || D == 8240 || 8242 <= D && D <= 8243 || D == 8245 || D == 8251 || D == 8254 || D == 8308 || D == 8319 || 8321 <= D && D <= 8324 || D == 8364 || D == 8451 || D == 8453 || D == 8457 || D == 8467 || D == 8470 || 8481 <= D && D <= 8482 || D == 8486 || D == 8491 || 8531 <= D && D <= 8532 || 8539 <= D && D <= 8542 || 8544 <= D && D <= 8555 || 8560 <= D && D <= 8569 || D == 8585 || 8592 <= D && D <= 8601 || 8632 <= D && D <= 8633 || D == 8658 || D == 8660 || D == 8679 || D == 8704 || 8706 <= D && D <= 8707 || 8711 <= D && D <= 8712 || D == 8715 || D == 8719 || D == 8721 || D == 8725 || D == 8730 || 8733 <= D && D <= 8736 || D == 8739 || D == 8741 || 8743 <= D && D <= 8748 || D == 8750 || 8756 <= D && D <= 8759 || 8764 <= D && D <= 8765 || D == 8776 || D == 8780 || D == 8786 || 8800 <= D && D <= 8801 || 8804 <= D && D <= 8807 || 8810 <= D && D <= 8811 || 8814 <= D && D <= 8815 || 8834 <= D && D <= 8835 || 8838 <= D && D <= 8839 || D == 8853 || D == 8857 || D == 8869 || D == 8895 || D == 8978 || 9312 <= D && D <= 9449 || 9451 <= D && D <= 9547 || 9552 <= D && D <= 9587 || 9600 <= D && D <= 9615 || 9618 <= D && D <= 9621 || 9632 <= D && D <= 9633 || 9635 <= D && D <= 9641 || 9650 <= D && D <= 9651 || 9654 <= D && D <= 9655 || 9660 <= D && D <= 9661 || 9664 <= D && D <= 9665 || 9670 <= D && D <= 9672 || D == 9675 || 9678 <= D && D <= 9681 || 9698 <= D && D <= 9701 || D == 9711 || 9733 <= D && D <= 9734 || D == 9737 || 9742 <= D && D <= 9743 || 9748 <= D && D <= 9749 || D == 9756 || D == 9758 || D == 9792 || D == 9794 || 9824 <= D && D <= 9825 || 9827 <= D && D <= 9829 || 9831 <= D && D <= 9834 || 9836 <= D && D <= 9837 || D == 9839 || 9886 <= D && D <= 9887 || 9918 <= D && D <= 9919 || 9924 <= D && D <= 9933 || 9935 <= D && D <= 9953 || D == 9955 || 9960 <= D && D <= 9983 || D == 10045 || D == 10071 || 10102 <= D && D <= 10111 || 11093 <= D && D <= 11097 || 12872 <= D && D <= 12879 || 57344 <= D && D <= 63743 || 65024 <= D && D <= 65039 || D == 65533 || 127232 <= D && D <= 127242 || 127248 <= D && D <= 127277 || 127280 <= D && D <= 127337 || 127344 <= D && D <= 127386 || 917760 <= D && D <= 917999 || 983040 <= D && D <= 1048573 || 1048576 <= D && D <= 1114109 ? "A" : "N" } , u . characterLength = function ( e ) { var s = this . e
` )];for(const[E,a]of o.entries()){if(e+=a,p.has(a)){const{groups:B}=new RegExp( ` ( ? : \ \ $ { W } ( ? < code > \ \ d + ) m | \ \ $ { w } ( ? < uri > . * ) $ { b } ) ` ).exec(o.slice(E).join(""))||{groups:{}};if(B.code!==void 0){const A=Number.parseFloat(B.code);s=A===J?void 0:A;}else B.uri!==void 0&&(C=B.uri.length===0?void 0:B.uri);}const n=q.codes.get(Number(s));o[E+1]=== `
` ?(C&&(e+=j("")),s&&n&&(e+=N(n))):a=== `
` &&(s&&n&&(e+=N(s)),C&&(e+=j(C)));}return e};function P(t,u,F){return String(t).normalize().replace(/ \r \n /g, `
` ).split( `
` ).map(e=>uD(e,u,F)).join( `
` )}function FD(t,u){if(t===u)return;const F=t.split( `
` ),e=u.split( `
` ),s=[];for(let C=0;C<Math.max(F.length,e.length);C++)F[C]!==e[C]&&s.push(C);return s}const R=Symbol("clack:cancel");function g(t,u){t.isTTY&&t.setRawMode(u);}const V=new Map([["k","up"],["j","down"],["h","left"],["l","right"]]),tD=new Set(["up","down","left","right","space","enter"]);class h{constructor({render:u,input:F=stdin,output:e=stdout,...s},C=!0){this._track=!1,this._cursor=0,this.state="initial",this.error="",this.subscribers=new Map,this._prevFrame="",this.opts=s,this.onKeypress=this.onKeypress.bind(this),this.close=this.close.bind(this),this.render=this.render.bind(this),this._render=u.bind(this),this._track=C,this.input=F,this.output=e;}prompt(){const u=new WriteStream(0);return u._write=(F,e,s)=>{this._track&&(this.value=this.rl.line.replace(/ \t /g,""),this._cursor=this.rl.cursor,this.emit("value",this.value)),s();},this.input.pipe(u),this.rl=f.createInterface({input:this.input,output:u,tabSize:2,prompt:"",escapeCodeTimeout:50}),f.emitKeypressEvents(this.input,this.rl),this.rl.prompt(),this.opts.initialValue!==void 0&&this._track&&this.rl.write(this.opts.initialValue),this.input.on("keypress",this.onKeypress),g(this.input,!0),this.output.on("resize",this.render),this.render(),new Promise((F,e)=>{this.once("submit",()=>{this.output.write(src.cursor.show),this.output.off("resize",this.render),g(this.input,!1),F(this.value);}),this.once("cancel",()=>{this.output.write(src.cursor.show),this.output.off("resize",this.render),g(this.input,!1),F(R);});})}on(u,F){const e=this.subscribers.get(u)??[];e.push({cb:F}),this.subscribers.set(u,e);}once(u,F){const e=this.subscribers.get(u)??[];e.push({cb:F,once:!0}),this.subscribers.set(u,e);}emit(u,...F){const e=this.subscribers.get(u)??[],s=[];for(const C of e)C.cb(...F),C.once&&s.push(()=>e.splice(e.indexOf(C),1));for(const C of s)C();}unsubscribe(){this.subscribers.clear();}onKeypress(u,F){if(this.state==="error"&&(this.state="active"),F?.name&&!this._track&&V.has(F.name)&&this.emit("cursor",V.get(F.name)),F?.name&&tD.has(F.name)&&this.emit("cursor",F.name),u&&(u.toLowerCase()==="y"||u.toLowerCase()==="n")&&this.emit("confirm",u.toLowerCase()==="y"),u&&this.emit("key",u.toLowerCase()),F?.name==="return"){if(this.opts.validate){const e=this.opts.validate(this.value);e&&(this.error=e,this.state="error",this.rl.write(this.value));}this.state!=="error"&&(this.state="submit");}u===""&&(this.state="cancel"),(this.state==="submit"||this.state==="cancel")&&this.emit("finalize"),this.render(),(this.state==="submit"||this.state==="cancel")&&this.close();}close(){this.input.unpipe(),this.input.removeListener("keypress",this.onKeypress),this.output.write( `
` ),g(this.input,!1),this.rl.close(),this.emit( ` $ { this . state } ` ,this.value),this.unsubscribe();}restoreCursor(){const u=P(this._prevFrame,process.stdout.columns,{hard:!0}).split( `
` ).length-1;this.output.write(src.cursor.move(-999,u*-1));}render(){const u=P(this._render(this)??"",process.stdout.columns,{hard:!0});if(u!==this._prevFrame){if(this.state==="initial")this.output.write(src.cursor.hide);else {const F=FD(this._prevFrame,u);if(this.restoreCursor(),F&&F?.length===1){const e=F[0];this.output.write(src.cursor.move(0,e)),this.output.write(src.erase.lines(1));const s=u.split( `
` );this.output.write(s[e]),this._prevFrame=u,this.output.write(src.cursor.move(0,s.length-e-1));return}else if(F&&F?.length>1){const e=F[0];this.output.write(src.cursor.move(0,e)),this.output.write(src.erase.down());const C=u.split( `
` ).slice(e);this.output.write(C.join( `
` )),this._prevFrame=u;return}this.output.write(src.erase.down());}this.output.write(u),this.state==="initial"&&(this.state="active"),this._prevFrame=u;}}}class sD extends h{get cursor(){return this.value?0:1}get _value(){return this.cursor===0}constructor(u){super(u,!1),this.value=!!u.initialValue,this.on("value",()=>{this.value=this._value;}),this.on("confirm",F=>{this.output.write(src.cursor.move(0,-1)),this.value=F,this.state="submit",this.close();}),this.on("cursor",()=>{this.value=!this.value;});}}class iD extends h{constructor(u){super(u,!1),this.cursor=0,this.options=u.options,this.value=[...u.initialValues??[]],this.cursor=Math.max(this.options.findIndex(({value:F})=>F===u.cursorAt),0),this.on("key",F=>{F==="a"&&this.toggleAll();}),this.on("cursor",F=>{switch(F){case"left":case"up":this.cursor=this.cursor===0?this.options.length-1:this.cursor-1;break;case"down":case"right":this.cursor=this.cursor===this.options.length-1?0:this.cursor+1;break;case"space":this.toggleValue();break}});}get _value(){return this.options[this.cursor].value}toggleAll(){const u=this.value.length===this.options.length;this.value=u?[]:this.options.map(F=>F.value);}toggleValue(){const u=this.value.includes(this._value);this.value=u?this.value.filter(F=>F!==this._value):[...this.value,this._value];}}class ED extends h{constructor(u){super(u,!1),this.cursor=0,this.options=u.options,this.cursor=this.options.findIndex(({value:F})=>F===u.initialValue),this.cursor===-1&&(this.cursor=0),this.changeValue(),this.on("cursor",F=>{switch(F){case"left":case"up":this.cursor=this.cursor===0?this.options.length-1:this.cursor-1;break;case"down":case"right":this.cursor=this.cursor===this.options.length-1?0:this.cursor+1;break}this.changeValue();});}get _value(){return this.options[this.cursor]}changeValue(){this.value=this._value.value;}}class oD extends h{constructor(u){super(u),this.valueWithCursor="",this.on("finalize",()=>{this.value||(this.value=u.defaultValue),this.valueWithCursor=this.value;}),this.on("value",()=>{if(this.cursor>=this.value.length)this.valueWithCursor= ` $ { this . value } $ { l . inverse ( l . hidden ( "_" ) ) } ` ;else {const F=this.value.slice(0,this.cursor),e=this.value.slice(this.cursor);this.valueWithCursor= ` $ { F } $ { l . inverse ( e [ 0 ] ) } $ { e . slice ( 1 ) } ` ;}});}get cursor(){return this._cursor}}
const unicode = isUnicodeSupported ( ) ;
const s = ( c , fallback ) => unicode ? c : fallback ;
const S_STEP_ACTIVE = s ( "\u276F" , ">" ) ;
const S_STEP_CANCEL = s ( "\u25A0" , "x" ) ;
const S_STEP_ERROR = s ( "\u25B2" , "x" ) ;
const S_STEP_SUBMIT = s ( "\u2714" , "\u221A" ) ;
const S_BAR = "" ;
const S_BAR_END = "" ;
const S_RADIO_ACTIVE = s ( "\u25CF" , ">" ) ;
const S_RADIO_INACTIVE = s ( "\u25CB" , " " ) ;
const S_CHECKBOX_ACTIVE = s ( "\u25FB" , "[\u2022]" ) ;
const S_CHECKBOX_SELECTED = s ( "\u25FC" , "[+]" ) ;
const S_CHECKBOX_INACTIVE = s ( "\u25FB" , "[ ]" ) ;
const symbol = ( state ) => {
switch ( state ) {
case "initial" :
case "active" : {
return colors . cyan ( S_STEP_ACTIVE ) ;
}
case "cancel" : {
return colors . red ( S_STEP_CANCEL ) ;
}
case "error" : {
return colors . yellow ( S_STEP_ERROR ) ;
}
case "submit" : {
return colors . green ( S_STEP_SUBMIT ) ;
}
}
} ;
const text = ( opts ) => {
return new oD ( {
validate : opts . validate ,
placeholder : opts . placeholder ,
defaultValue : opts . defaultValue ,
initialValue : opts . initialValue ,
render ( ) {
const title = ` ${ colors . gray ( S_BAR ) }
$ { symbol ( this . state ) } $ { opts . message }
` ;
const placeholder = opts . placeholder ? colors . inverse ( opts . placeholder [ 0 ] ) + colors . dim ( opts . placeholder . slice ( 1 ) ) : colors . inverse ( colors . hidden ( "_" ) ) ;
const value = this . value ? this . valueWithCursor : placeholder ;
switch ( this . state ) {
case "error" : {
return ` ${ title . trim ( ) }
$ { colors . yellow (
S_BAR
) } $ { value }
$ { colors . yellow ( S_BAR_END ) } $ { colors . yellow (
this . error
) }
` ;
}
case "submit" : {
return ` ${ title } ${ colors . gray ( S_BAR ) } ${ colors . dim (
this . value || opts . placeholder
) } ` ;
}
case "cancel" : {
return ` ${ title } ${ colors . gray ( S_BAR ) } ${ colors . strikethrough (
colors . dim ( this . value ? ? "" )
) } $ { this . value ? . trim ( ) ? "\n" + colors . gray ( S_BAR ) : "" } ` ;
}
default : {
return ` ${ title } ${ colors . cyan ( S_BAR ) } ${ value }
$ { colors . cyan (
S_BAR_END
) }
` ;
}
}
}
} ) . prompt ( ) ;
} ;
const confirm = ( opts ) => {
const active = opts . active ? ? "Yes" ;
const inactive = opts . inactive ? ? "No" ;
return new sD ( {
active ,
inactive ,
initialValue : opts . initialValue ? ? true ,
render ( ) {
const title = ` ${ colors . gray ( S_BAR ) }
$ { symbol ( this . state ) } $ { opts . message }
` ;
const value = this . value ? active : inactive ;
switch ( this . state ) {
case "submit" : {
return ` ${ title } ${ colors . gray ( S_BAR ) } ${ colors . dim ( value ) } ` ;
}
case "cancel" : {
return ` ${ title } ${ colors . gray ( S_BAR ) } ${ colors . strikethrough (
colors . dim ( value )
) }
$ { colors . gray ( S_BAR ) } ` ;
}
default : {
return ` ${ title } ${ colors . cyan ( S_BAR ) } ${ this . value ? ` ${ colors . green ( S_RADIO_ACTIVE ) } ${ active } ` : ` ${ colors . dim ( S_RADIO_INACTIVE ) } ${ colors . dim ( active ) } ` } ${ colors . dim ( "/" ) } ${ this . value ? ` ${ colors . dim ( S_RADIO_INACTIVE ) } ${ colors . dim ( inactive ) } ` : ` ${ colors . green ( S_RADIO_ACTIVE ) } ${ inactive } ` }
$ { colors . cyan ( S_BAR_END ) }
` ;
}
}
}
} ) . prompt ( ) ;
} ;
const select = ( opts ) => {
const opt = ( option , state ) => {
const label = option . label ? ? String ( option . value ) ;
switch ( state ) {
case "active" : {
return ` ${ colors . green ( S_RADIO_ACTIVE ) } ${ label } ${ option . hint ? colors . dim ( ` ( ${ option . hint } ) ` ) : "" } ` ;
}
case "selected" : {
return ` ${ colors . dim ( label ) } ` ;
}
case "cancelled" : {
return ` ${ colors . strikethrough ( colors . dim ( label ) ) } ` ;
}
}
return ` ${ colors . dim ( S_RADIO_INACTIVE ) } ${ colors . dim ( label ) } ` ;
} ;
return new ED ( {
options : opts . options ,
initialValue : opts . initialValue ,
render ( ) {
const title = ` ${ colors . gray ( S_BAR ) }
$ { symbol ( this . state ) } $ { opts . message }
` ;
switch ( this . state ) {
case "submit" : {
return ` ${ title } ${ colors . gray ( S_BAR ) } ${ opt (
this . options [ this . cursor ] ,
"selected"
) } ` ;
}
case "cancel" : {
return ` ${ title } ${ colors . gray ( S_BAR ) } ${ opt (
this . options [ this . cursor ] ,
"cancelled"
) }
$ { colors . gray ( S_BAR ) } ` ;
}
default : {
return ` ${ title } ${ colors . cyan ( S_BAR ) } ${ this . options . map (
( option , i ) => opt ( option , i === this . cursor ? "active" : "inactive" )
) . join ( `
$ { colors . cyan ( S_BAR ) } ` )}
$ { colors . cyan ( S_BAR_END ) }
` ;
}
}
}
} ) . prompt ( ) ;
} ;
const multiselect = ( opts ) => {
const opt = ( option , state ) => {
const label = option . label ? ? String ( option . value ) ;
switch ( state ) {
case "active" : {
return ` ${ colors . cyan ( S_CHECKBOX_ACTIVE ) } ${ label } ${ option . hint ? colors . dim ( ` ( ${ option . hint } ) ` ) : "" } ` ;
}
case "selected" : {
return ` ${ colors . green ( S_CHECKBOX_SELECTED ) } ${ colors . dim ( label ) } ` ;
}
case "cancelled" : {
return ` ${ colors . strikethrough ( colors . dim ( label ) ) } ` ;
}
case "active-selected" : {
return ` ${ colors . green ( S_CHECKBOX_SELECTED ) } ${ label } ${ option . hint ? colors . dim ( ` ( ${ option . hint } ) ` ) : "" } ` ;
}
case "submitted" : {
return ` ${ colors . dim ( label ) } ` ;
}
}
return ` ${ colors . dim ( S_CHECKBOX_INACTIVE ) } ${ colors . dim ( label ) } ` ;
} ;
return new iD ( {
options : opts . options ,
initialValues : opts . initialValues ,
required : opts . required ? ? true ,
cursorAt : opts . cursorAt ,
validate ( selected ) {
if ( this . required && selected . length === 0 ) {
return ` Please select at least one option.
$ { colors . reset (
colors . dim (
` Press ${ colors . gray (
colors . bgWhite ( colors . inverse ( " space " ) )
) } to select , $ { colors . gray (
colors . bgWhite ( colors . inverse ( " enter " ) )
) } to submit `
)
) } ` ;
}
} ,
render ( ) {
const title = ` ${ colors . gray ( S_BAR ) }
$ { symbol ( this . state ) } $ { opts . message }
` ;
switch ( this . state ) {
case "submit" : {
return ` ${ title } ${ colors . gray ( S_BAR ) } ${ this . options . filter ( ( { value } ) => this.value.includes(value)).map((option) => opt(option, "submitted")).join(colors.dim(", ")) || colors.dim("none")} ` ;
}
case "cancel" : {
const label = this . options . filter ( ( { value } ) => this . value . includes ( value ) ) . map ( ( option ) => opt ( option , "cancelled" ) ) . join ( colors . dim ( ", " ) ) ;
return ` ${ title } ${ colors . gray ( S_BAR ) } ${ label . trim ( ) ? ` ${ label }
$ { colors . gray ( S_BAR ) } ` : ""} ` ;
}
case "error" : {
const footer = this . error . split ( "\n" ) . map (
( ln , i ) => i === 0 ? ` ${ colors . yellow ( S_BAR_END ) } ${ colors . yellow ( ln ) } ` : ` ${ ln } `
) . join ( "\n" ) ;
return title + colors . yellow ( S_BAR ) + " " + this . options . map ( ( option , i ) => {
const selected = this . value . includes ( option . value ) ;
const active = i === this . cursor ;
if ( active && selected ) {
return opt ( option , "active-selected" ) ;
}
if ( selected ) {
return opt ( option , "selected" ) ;
}
return opt ( option , active ? "active" : "inactive" ) ;
} ) . join ( `
$ { colors . yellow ( S_BAR ) } ` ) + " \n " + footer + " \n ";
}
default : {
return ` ${ title } ${ colors . cyan ( S_BAR ) } ${ this . options . map ( ( option , i ) => {
const selected = this . value . includes ( option . value ) ;
const active = i === this . cursor ;
if ( active && selected ) {
return opt ( option , "active-selected" ) ;
}
if ( selected ) {
return opt ( option , "selected" ) ;
}
return opt ( option , active ? "active" : "inactive" ) ;
} ) . join ( `
$ { colors . cyan ( S_BAR ) } ` )}
$ { colors . cyan ( S_BAR_END ) }
` ;
}
}
}
} ) . prompt ( ) ;
} ;
async function prompt ( message , opts = { } ) {
if ( ! opts . type || opts . type === "text" ) {
return await text ( {
message ,
defaultValue : opts . default ,
placeholder : opts . placeholder ,
initialValue : opts . initial
} ) ;
}
if ( opts . type === "confirm" ) {
return await confirm ( {
message ,
initialValue : opts . initial
} ) ;
}
if ( opts . type === "select" ) {
return await select ( {
message ,
options : opts . options . map (
( o ) => typeof o === "string" ? { value : o , label : o } : o
)
} ) ;
}
if ( opts . type === "multiselect" ) {
return await multiselect ( {
message ,
options : opts . options . map (
( o ) => typeof o === "string" ? { value : o , label : o } : o
) ,
required : opts . required
} ) ;
}
throw new Error ( ` Unknown prompt type: ${ opts . type } ` ) ;
}
export { prompt } ;