281 lines
43 KiB
JavaScript
281 lines
43 KiB
JavaScript
|
|
import 'node:util';
|
|||
|
|
import g, { stdin, stdout } from 'node:process';
|
|||
|
|
import f from 'node:readline';
|
|||
|
|
import { WriteStream } from 'node:tty';
|
|||
|
|
|
|||
|
|
function getDefaultExportFromCjs (x) {
|
|||
|
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
var src;
|
|||
|
|
var hasRequiredSrc;
|
|||
|
|
|
|||
|
|
function requireSrc () {
|
|||
|
|
if (hasRequiredSrc) return src;
|
|||
|
|
hasRequiredSrc = 1;
|
|||
|
|
|
|||
|
|
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;
|
|||
|
|
}
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
src = { cursor, scroll, erase, beep };
|
|||
|
|
return src;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
var srcExports = requireSrc();
|
|||
|
|
|
|||
|
|
var picocolors = {exports: {}};
|
|||
|
|
|
|||
|
|
var hasRequiredPicocolors;
|
|||
|
|
|
|||
|
|
function requirePicocolors () {
|
|||
|
|
if (hasRequiredPicocolors) return picocolors.exports;
|
|||
|
|
hasRequiredPicocolors = 1;
|
|||
|
|
let p = process || {}, argv = p.argv || [], env = p.env || {};
|
|||
|
|
let isColorSupported =
|
|||
|
|
!(!!env.NO_COLOR || argv.includes("--no-color")) &&
|
|||
|
|
(!!env.FORCE_COLOR || argv.includes("--color") || p.platform === "win32" || ((p.stdout || {}).isTTY && env.TERM !== "dumb") || !!env.CI);
|
|||
|
|
|
|||
|
|
let formatter = (open, close, replace = open) =>
|
|||
|
|
input => {
|
|||
|
|
let string = "" + input, 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 result = "", cursor = 0;
|
|||
|
|
do {
|
|||
|
|
result += string.substring(cursor, index) + replace;
|
|||
|
|
cursor = index + close.length;
|
|||
|
|
index = string.indexOf(close, cursor);
|
|||
|
|
} while (~index)
|
|||
|
|
return result + string.substring(cursor)
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
let createColors = (enabled = isColorSupported) => {
|
|||
|
|
let f = enabled ? formatter : () => String;
|
|||
|
|
return {
|
|||
|
|
isColorSupported: enabled,
|
|||
|
|
reset: f("\x1b[0m", "\x1b[0m"),
|
|||
|
|
bold: f("\x1b[1m", "\x1b[22m", "\x1b[22m\x1b[1m"),
|
|||
|
|
dim: f("\x1b[2m", "\x1b[22m", "\x1b[22m\x1b[2m"),
|
|||
|
|
italic: f("\x1b[3m", "\x1b[23m"),
|
|||
|
|
underline: f("\x1b[4m", "\x1b[24m"),
|
|||
|
|
inverse: f("\x1b[7m", "\x1b[27m"),
|
|||
|
|
hidden: f("\x1b[8m", "\x1b[28m"),
|
|||
|
|
strikethrough: f("\x1b[9m", "\x1b[29m"),
|
|||
|
|
|
|||
|
|
black: f("\x1b[30m", "\x1b[39m"),
|
|||
|
|
red: f("\x1b[31m", "\x1b[39m"),
|
|||
|
|
green: f("\x1b[32m", "\x1b[39m"),
|
|||
|
|
yellow: f("\x1b[33m", "\x1b[39m"),
|
|||
|
|
blue: f("\x1b[34m", "\x1b[39m"),
|
|||
|
|
magenta: f("\x1b[35m", "\x1b[39m"),
|
|||
|
|
cyan: f("\x1b[36m", "\x1b[39m"),
|
|||
|
|
white: f("\x1b[37m", "\x1b[39m"),
|
|||
|
|
gray: f("\x1b[90m", "\x1b[39m"),
|
|||
|
|
|
|||
|
|
bgBlack: f("\x1b[40m", "\x1b[49m"),
|
|||
|
|
bgRed: f("\x1b[41m", "\x1b[49m"),
|
|||
|
|
bgGreen: f("\x1b[42m", "\x1b[49m"),
|
|||
|
|
bgYellow: f("\x1b[43m", "\x1b[49m"),
|
|||
|
|
bgBlue: f("\x1b[44m", "\x1b[49m"),
|
|||
|
|
bgMagenta: f("\x1b[45m", "\x1b[49m"),
|
|||
|
|
bgCyan: f("\x1b[46m", "\x1b[49m"),
|
|||
|
|
bgWhite: f("\x1b[47m", "\x1b[49m"),
|
|||
|
|
|
|||
|
|
blackBright: f("\x1b[90m", "\x1b[39m"),
|
|||
|
|
redBright: f("\x1b[91m", "\x1b[39m"),
|
|||
|
|
greenBright: f("\x1b[92m", "\x1b[39m"),
|
|||
|
|
yellowBright: f("\x1b[93m", "\x1b[39m"),
|
|||
|
|
blueBright: f("\x1b[94m", "\x1b[39m"),
|
|||
|
|
magentaBright: f("\x1b[95m", "\x1b[39m"),
|
|||
|
|
cyanBright: f("\x1b[96m", "\x1b[39m"),
|
|||
|
|
whiteBright: f("\x1b[97m", "\x1b[39m"),
|
|||
|
|
|
|||
|
|
bgBlackBright: f("\x1b[100m", "\x1b[49m"),
|
|||
|
|
bgRedBright: f("\x1b[101m", "\x1b[49m"),
|
|||
|
|
bgGreenBright: f("\x1b[102m", "\x1b[49m"),
|
|||
|
|
bgYellowBright: f("\x1b[103m", "\x1b[49m"),
|
|||
|
|
bgBlueBright: f("\x1b[104m", "\x1b[49m"),
|
|||
|
|
bgMagentaBright: f("\x1b[105m", "\x1b[49m"),
|
|||
|
|
bgCyanBright: f("\x1b[106m", "\x1b[49m"),
|
|||
|
|
bgWhiteBright: f("\x1b[107m", "\x1b[49m"),
|
|||
|
|
}
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
picocolors.exports = createColors();
|
|||
|
|
picocolors.exports.createColors = createColors;
|
|||
|
|
return picocolors.exports;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
var picocolorsExports = /*@__PURE__*/ requirePicocolors();
|
|||
|
|
const e = /*@__PURE__*/getDefaultExportFromCjs(picocolorsExports);
|
|||
|
|
|
|||
|
|
function J({onlyFirst:t=false}={}){const F=["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?(?:\\u0007|\\u001B\\u005C|\\u009C))","(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))"].join("|");return new RegExp(F,t?void 0:"g")}const Q=J();function T$1(t){if(typeof t!="string")throw new TypeError(`Expected a \`string\`, got \`${typeof t}\``);return t.replace(Q,"")}function O(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var P$1={exports:{}};(function(t){var u={};t.exports=u,u.eastAsianWidth=function(e){var s=e.charCodeAt(0),i=e.length==2?e.charCodeAt(1):0,D=s;return 55296<=s&&s<=56319&&56320<=i&&i<=57343&&(s&=1023,i&=1023,D=s<<10|i,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<=
|
|||
|
|
`)];for(const[E,a]of o.entries()){if(e+=a,v.has(a)){const{groups:B}=new RegExp(`(?:\\${W$1}(?<code>\\d+)m|\\${y}(?<uri>.*)${w$1})`).exec(o.slice(E).join(""))||{groups:{}};if(B.code!==void 0){const p=Number.parseFloat(B.code);s=p===CD?void 0:p;}else B.uri!==void 0&&(i=B.uri.length===0?void 0:B.uri);}const n=iD.codes.get(Number(s));o[E+1]===`
|
|||
|
|
`?(i&&(e+=z("")),s&&n&&(e+=V$1(n))):a===`
|
|||
|
|
`&&(s&&n&&(e+=V$1(s)),i&&(e+=z(i)));}return e};function G(t,u,F){return String(t).normalize().replace(/\r\n/g,`
|
|||
|
|
`).split(`
|
|||
|
|
`).map(e=>oD(e,u,F)).join(`
|
|||
|
|
`)}const aD=["up","down","left","right","space","enter","cancel"],c={actions:new Set(aD),aliases:new Map([["k","up"],["j","down"],["h","left"],["l","right"],["","cancel"],["escape","cancel"]])};function k$1(t,u){if(typeof t=="string")return c.aliases.get(t)===u;for(const F of t)if(F!==void 0&&k$1(F,u))return true;return false}function lD(t,u){if(t===u)return;const F=t.split(`
|
|||
|
|
`),e=u.split(`
|
|||
|
|
`),s=[];for(let i=0;i<Math.max(F.length,e.length);i++)F[i]!==e[i]&&s.push(i);return s}globalThis.process.platform.startsWith("win");const S=Symbol("clack:cancel");function d$1(t,u){const F=t;F.isTTY&&F.setRawMode(u);}var AD=Object.defineProperty,pD=(t,u,F)=>u in t?AD(t,u,{enumerable:true,configurable:true,writable:true,value:F}):t[u]=F,h=(t,u,F)=>(pD(t,typeof u!="symbol"?u+"":u,F),F);class x{constructor(u,F=true){h(this,"input"),h(this,"output"),h(this,"_abortSignal"),h(this,"rl"),h(this,"opts"),h(this,"_render"),h(this,"_track",false),h(this,"_prevFrame",""),h(this,"_subscribers",new Map),h(this,"_cursor",0),h(this,"state","initial"),h(this,"error",""),h(this,"value");const{input:e=stdin,output:s=stdout,render:i,signal:D,...C}=u;this.opts=C,this.onKeypress=this.onKeypress.bind(this),this.close=this.close.bind(this),this.render=this.render.bind(this),this._render=i.bind(this),this._track=F,this._abortSignal=D,this.input=e,this.output=s;}unsubscribe(){this._subscribers.clear();}setSubscriber(u,F){const e=this._subscribers.get(u)??[];e.push(F),this._subscribers.set(u,e);}on(u,F){this.setSubscriber(u,{cb:F});}once(u,F){this.setSubscriber(u,{cb:F,once:true});}emit(u,...F){const e=this._subscribers.get(u)??[],s=[];for(const i of e)i.cb(...F),i.once&&s.push(()=>e.splice(e.indexOf(i),1));for(const i of s)i();}prompt(){return new Promise((u,F)=>{if(this._abortSignal){if(this._abortSignal.aborted)return this.state="cancel",this.close(),u(S);this._abortSignal.addEventListener("abort",()=>{this.state="cancel",this.close();},{once:true});}const e=new WriteStream(0);e._write=(s,i,D)=>{this._track&&(this.value=this.rl?.line.replace(/\t/g,""),this._cursor=this.rl?.cursor??0,this.emit("value",this.value)),D();},this.input.pipe(e),this.rl=f.createInterface({input:this.input,output:e,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),d$1(this.input,true),this.output.on("resize",this.render),this.render(),this.once("submit",()=>{this.output.write(srcExports.cursor.show),this.output.off("resize",this.render),d$1(this.input,false),u(this.value);}),this.once("cancel",()=>{this.output.write(srcExports.cursor.show),this.output.off("resize",this.render),d$1(this.input,false),u(S);});})}onKeypress(u,F){if(this.state==="error"&&(this.state="active"),F?.name&&(!this._track&&c.aliases.has(F.name)&&this.emit("cursor",c.aliases.get(F.name)),c.actions.has(F.name)&&this.emit("cursor",F.name)),u&&(u.toLowerCase()==="y"||u.toLowerCase()==="n")&&this.emit("confirm",u.toLowerCase()==="y"),u===" "&&this.opts.placeholder&&(this.value||(this.rl?.write(this.opts.placeholder),this.emit("value",this.opts.placeholder))),u&&this.emit("key",u.toLowerCase()),F?.name==="return"){if(this.opts.validate){const e=this.opts.validate(this.value);e&&(this.error=e instanceof Error?e.message:e,this.state="error",this.rl?.write(this.value));}this.state!=="error"&&(this.state="submit");}k$1([u,F?.name,F?.sequence],"cancel")&&(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(`
|
|||
|
|
`),d$1(this.input,false),this.rl?.close(),this.rl=void 0,this.emit(`${this.state}`,this.value),this.unsubscribe();}restoreCursor(){const u=G(this._prevFrame,process.stdout.columns,{hard:true}).split(`
|
|||
|
|
`).length-1;this.output.write(srcExports.cursor.move(-999,u*-1));}render(){const u=G(this._render(this)??"",process.stdout.columns,{hard:true});if(u!==this._prevFrame){if(this.state==="initial")this.output.write(srcExports.cursor.hide);else {const F=lD(this._prevFrame,u);if(this.restoreCursor(),F&&F?.length===1){const e=F[0];this.output.write(srcExports.cursor.move(0,e)),this.output.write(srcExports.erase.lines(1));const s=u.split(`
|
|||
|
|
`);this.output.write(s[e]),this._prevFrame=u,this.output.write(srcExports.cursor.move(0,s.length-e-1));return}if(F&&F?.length>1){const e=F[0];this.output.write(srcExports.cursor.move(0,e)),this.output.write(srcExports.erase.down());const s=u.split(`
|
|||
|
|
`).slice(e);this.output.write(s.join(`
|
|||
|
|
`)),this._prevFrame=u;return}this.output.write(srcExports.erase.down());}this.output.write(u),this.state==="initial"&&(this.state="active"),this._prevFrame=u;}}}class fD extends x{get cursor(){return this.value?0:1}get _value(){return this.cursor===0}constructor(u){super(u,false),this.value=!!u.initialValue,this.on("value",()=>{this.value=this._value;}),this.on("confirm",F=>{this.output.write(srcExports.cursor.move(0,-1)),this.value=F,this.state="submit",this.close();}),this.on("cursor",()=>{this.value=!this.value;});}}var bD=Object.defineProperty,mD=(t,u,F)=>u in t?bD(t,u,{enumerable:true,configurable:true,writable:true,value:F}):t[u]=F,Y=(t,u,F)=>(mD(t,typeof u!="symbol"?u+"":u,F),F);let wD=class extends x{constructor(u){super(u,false),Y(this,"options"),Y(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];}};var SD=Object.defineProperty,$D=(t,u,F)=>u in t?SD(t,u,{enumerable:true,configurable:true,writable:true,value:F}):t[u]=F,q=(t,u,F)=>($D(t,typeof u!="symbol"?u+"":u,F),F);class jD extends x{constructor(u){super(u,false),q(this,"options"),q(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 PD extends x{get valueWithCursor(){if(this.state==="submit")return this.value;if(this.cursor>=this.value.length)return `${this.value}\u2588`;const u=this.value.slice(0,this.cursor),[F,...e$1]=this.value.slice(this.cursor);return `${u}${e.inverse(F)}${e$1.join("")}`}get cursor(){return this._cursor}constructor(u){super(u),this.on("finalize",()=>{this.value||(this.value=u.defaultValue);});}}
|
|||
|
|
|
|||
|
|
function ce(){return g.platform!=="win32"?g.env.TERM!=="linux":!!g.env.CI||!!g.env.WT_SESSION||!!g.env.TERMINUS_SUBLIME||g.env.ConEmuTask==="{cmd::Cmder}"||g.env.TERM_PROGRAM==="Terminus-Sublime"||g.env.TERM_PROGRAM==="vscode"||g.env.TERM==="xterm-256color"||g.env.TERM==="alacritty"||g.env.TERMINAL_EMULATOR==="JetBrains-JediTerm"}const V=ce(),u=(t,n)=>V?t:n,le=u("❯", ">"),L=u("■", "x"),W=u("▲", "x"),C=u("✔", "√"),o=u(""),d=u(""),k=u("\u25CF",">"),P=u("\u25CB"," "),A=u("\u25FB","[\u2022]"),T=u("\u25FC","[+]"),F=u("\u25FB","[ ]"),w=t=>{switch(t){case "initial":case "active":return e.cyan(le);case "cancel":return e.red(L);case "error":return e.yellow(W);case "submit":return e.green(C)}},B=t=>{const{cursor:n,options:s,style:r}=t,i=t.maxItems??Number.POSITIVE_INFINITY,a=Math.max(process.stdout.rows-4,0),c=Math.min(a,Math.max(i,5));let l=0;n>=l+c-3?l=Math.max(Math.min(n-c+3,s.length-c),0):n<l+2&&(l=Math.max(n-2,0));const $=c<s.length&&l>0,p=c<s.length&&l+c<s.length;return s.slice(l,l+c).map((M,v,x)=>{const j=v===0&&$,E=v===x.length-1&&p;return j||E?e.dim("..."):r(M,v+l===n)})},he=t=>new PD({validate:t.validate,placeholder:t.placeholder,defaultValue:t.defaultValue,initialValue:t.initialValue,render(){const n=`${e.gray(o)}
|
|||
|
|
${w(this.state)} ${t.message}
|
|||
|
|
`,s=t.placeholder?e.inverse(t.placeholder[0])+e.dim(t.placeholder.slice(1)):e.inverse(e.hidden("_")),r=this.value?this.valueWithCursor:s;switch(this.state){case "error":return `${n.trim()}
|
|||
|
|
${e.yellow(o)} ${r}
|
|||
|
|
${e.yellow(d)} ${e.yellow(this.error)}
|
|||
|
|
`;case "submit":return `${n}${e.gray(o)} ${e.dim(this.value||t.placeholder)}`;case "cancel":return `${n}${e.gray(o)} ${e.strikethrough(e.dim(this.value??""))}${this.value?.trim()?`
|
|||
|
|
${e.gray(o)}`:""}`;default:return `${n}${e.cyan(o)} ${r}
|
|||
|
|
${e.cyan(d)}
|
|||
|
|
`}}}).prompt(),ye=t=>{const n=t.active??"Yes",s=t.inactive??"No";return new fD({active:n,inactive:s,initialValue:t.initialValue??true,render(){const r=`${e.gray(o)}
|
|||
|
|
${w(this.state)} ${t.message}
|
|||
|
|
`,i=this.value?n:s;switch(this.state){case "submit":return `${r}${e.gray(o)} ${e.dim(i)}`;case "cancel":return `${r}${e.gray(o)} ${e.strikethrough(e.dim(i))}
|
|||
|
|
${e.gray(o)}`;default:return `${r}${e.cyan(o)} ${this.value?`${e.green(k)} ${n}`:`${e.dim(P)} ${e.dim(n)}`} ${e.dim("/")} ${this.value?`${e.dim(P)} ${e.dim(s)}`:`${e.green(k)} ${s}`}
|
|||
|
|
${e.cyan(d)}
|
|||
|
|
`}}}).prompt()},ve=t=>{const n=(s,r)=>{const i=s.label??String(s.value);switch(r){case "selected":return `${e.dim(i)}`;case "active":return `${e.green(k)} ${i} ${s.hint?e.dim(`(${s.hint})`):""}`;case "cancelled":return `${e.strikethrough(e.dim(i))}`;default:return `${e.dim(P)} ${e.dim(i)}`}};return new jD({options:t.options,initialValue:t.initialValue,render(){const s=`${e.gray(o)}
|
|||
|
|
${w(this.state)} ${t.message}
|
|||
|
|
`;switch(this.state){case "submit":return `${s}${e.gray(o)} ${n(this.options[this.cursor],"selected")}`;case "cancel":return `${s}${e.gray(o)} ${n(this.options[this.cursor],"cancelled")}
|
|||
|
|
${e.gray(o)}`;default:return `${s}${e.cyan(o)} ${B({cursor:this.cursor,options:this.options,maxItems:t.maxItems,style:(r,i)=>n(r,i?"active":"inactive")}).join(`
|
|||
|
|
${e.cyan(o)} `)}
|
|||
|
|
${e.cyan(d)}
|
|||
|
|
`}}}).prompt()},fe=t=>{const n=(s,r)=>{const i=s.label??String(s.value);return r==="active"?`${e.cyan(A)} ${i} ${s.hint?e.dim(`(${s.hint})`):""}`:r==="selected"?`${e.green(T)} ${e.dim(i)}`:r==="cancelled"?`${e.strikethrough(e.dim(i))}`:r==="active-selected"?`${e.green(T)} ${i} ${s.hint?e.dim(`(${s.hint})`):""}`:r==="submitted"?`${e.dim(i)}`:`${e.dim(F)} ${e.dim(i)}`};return new wD({options:t.options,initialValues:t.initialValues,required:t.required??true,cursorAt:t.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(){const s=`${e.gray(o)}
|
|||
|
|
${w(this.state)} ${t.message}
|
|||
|
|
`,r=(i,a)=>{const c=this.value.includes(i.value);return a&&c?n(i,"active-selected"):c?n(i,"selected"):n(i,a?"active":"inactive")};switch(this.state){case "submit":return `${s}${e.gray(o)} ${this.options.filter(({value:i})=>this.value.includes(i)).map(i=>n(i,"submitted")).join(e.dim(", "))||e.dim("none")}`;case "cancel":{const i=this.options.filter(({value:a})=>this.value.includes(a)).map(a=>n(a,"cancelled")).join(e.dim(", "));return `${s}${e.gray(o)} ${i.trim()?`${i}
|
|||
|
|
${e.gray(o)}`:""}`}case "error":{const i=this.error.split(`
|
|||
|
|
`).map((a,c)=>c===0?`${e.yellow(d)} ${e.yellow(a)}`:` ${a}`).join(`
|
|||
|
|
`);return `${s+e.yellow(o)} ${B({options:this.options,cursor:this.cursor,maxItems:t.maxItems,style:r}).join(`
|
|||
|
|
${e.yellow(o)} `)}
|
|||
|
|
${i}
|
|||
|
|
`}default:return `${s}${e.cyan(o)} ${B({options:this.options,cursor:this.cursor,maxItems:t.maxItems,style:r}).join(`
|
|||
|
|
${e.cyan(o)} `)}
|
|||
|
|
${e.cyan(d)}
|
|||
|
|
`}}}).prompt()};`${e.gray(o)} `;
|
|||
|
|
|
|||
|
|
const kCancel = Symbol.for("cancel");
|
|||
|
|
async function prompt(message, opts = {}) {
|
|||
|
|
const handleCancel = (value) => {
|
|||
|
|
if (typeof value !== "symbol" || value.toString() !== "Symbol(clack:cancel)") {
|
|||
|
|
return value;
|
|||
|
|
}
|
|||
|
|
switch (opts.cancel) {
|
|||
|
|
case "reject": {
|
|||
|
|
const error = new Error("Prompt cancelled.");
|
|||
|
|
error.name = "ConsolaPromptCancelledError";
|
|||
|
|
if (Error.captureStackTrace) {
|
|||
|
|
Error.captureStackTrace(error, prompt);
|
|||
|
|
}
|
|||
|
|
throw error;
|
|||
|
|
}
|
|||
|
|
case "undefined": {
|
|||
|
|
return void 0;
|
|||
|
|
}
|
|||
|
|
case "null": {
|
|||
|
|
return null;
|
|||
|
|
}
|
|||
|
|
case "symbol": {
|
|||
|
|
return kCancel;
|
|||
|
|
}
|
|||
|
|
default:
|
|||
|
|
case "default": {
|
|||
|
|
return opts.default ?? opts.initial;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
};
|
|||
|
|
if (!opts.type || opts.type === "text") {
|
|||
|
|
return await he({
|
|||
|
|
message,
|
|||
|
|
defaultValue: opts.default,
|
|||
|
|
placeholder: opts.placeholder,
|
|||
|
|
initialValue: opts.initial
|
|||
|
|
}).then(handleCancel);
|
|||
|
|
}
|
|||
|
|
if (opts.type === "confirm") {
|
|||
|
|
return await ye({
|
|||
|
|
message,
|
|||
|
|
initialValue: opts.initial
|
|||
|
|
}).then(handleCancel);
|
|||
|
|
}
|
|||
|
|
if (opts.type === "select") {
|
|||
|
|
return await ve({
|
|||
|
|
message,
|
|||
|
|
options: opts.options.map(
|
|||
|
|
(o) => typeof o === "string" ? { value: o, label: o } : o
|
|||
|
|
),
|
|||
|
|
initialValue: opts.initial
|
|||
|
|
}).then(handleCancel);
|
|||
|
|
}
|
|||
|
|
if (opts.type === "multiselect") {
|
|||
|
|
return await fe({
|
|||
|
|
message,
|
|||
|
|
options: opts.options.map(
|
|||
|
|
(o) => typeof o === "string" ? { value: o, label: o } : o
|
|||
|
|
),
|
|||
|
|
required: opts.required,
|
|||
|
|
initialValues: opts.initial
|
|||
|
|
}).then(handleCancel);
|
|||
|
|
}
|
|||
|
|
throw new Error(`Unknown prompt type: ${opts.type}`);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
export { kCancel, prompt };
|