123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291 |
- import require$$0 from 'readline';
- import require$$2 from 'events';
- function _mergeNamespaces(n, m) {
- m.forEach(function (e) {
- e && typeof e !== 'string' && !Array.isArray(e) && Object.keys(e).forEach(function (k) {
- if (k !== 'default' && !(k in n)) {
- var d = Object.getOwnPropertyDescriptor(e, k);
- Object.defineProperty(n, k, d.get ? d : {
- enumerable: true,
- get: function () { return e[k]; }
- });
- }
- });
- });
- return Object.freeze(n);
- }
- var prompts$2 = {};
- var kleur;
- var hasRequiredKleur;
- function requireKleur () {
- if (hasRequiredKleur) return kleur;
- hasRequiredKleur = 1;
- const { FORCE_COLOR, NODE_DISABLE_COLORS, TERM } = process.env;
- const $ = {
- enabled: !NODE_DISABLE_COLORS && TERM !== 'dumb' && FORCE_COLOR !== '0',
- // modifiers
- reset: init(0, 0),
- bold: init(1, 22),
- dim: init(2, 22),
- italic: init(3, 23),
- underline: init(4, 24),
- inverse: init(7, 27),
- hidden: init(8, 28),
- strikethrough: init(9, 29),
- // colors
- black: init(30, 39),
- red: init(31, 39),
- green: init(32, 39),
- yellow: init(33, 39),
- blue: init(34, 39),
- magenta: init(35, 39),
- cyan: init(36, 39),
- white: init(37, 39),
- gray: init(90, 39),
- grey: init(90, 39),
- // background colors
- bgBlack: init(40, 49),
- bgRed: init(41, 49),
- bgGreen: init(42, 49),
- bgYellow: init(43, 49),
- bgBlue: init(44, 49),
- bgMagenta: init(45, 49),
- bgCyan: init(46, 49),
- bgWhite: init(47, 49)
- };
- function run(arr, str) {
- let i=0, tmp, beg='', end='';
- for (; i < arr.length; i++) {
- tmp = arr[i];
- beg += tmp.open;
- end += tmp.close;
- if (str.includes(tmp.close)) {
- str = str.replace(tmp.rgx, tmp.close + tmp.open);
- }
- }
- return beg + str + end;
- }
- function chain(has, keys) {
- let ctx = { has, keys };
- ctx.reset = $.reset.bind(ctx);
- ctx.bold = $.bold.bind(ctx);
- ctx.dim = $.dim.bind(ctx);
- ctx.italic = $.italic.bind(ctx);
- ctx.underline = $.underline.bind(ctx);
- ctx.inverse = $.inverse.bind(ctx);
- ctx.hidden = $.hidden.bind(ctx);
- ctx.strikethrough = $.strikethrough.bind(ctx);
- ctx.black = $.black.bind(ctx);
- ctx.red = $.red.bind(ctx);
- ctx.green = $.green.bind(ctx);
- ctx.yellow = $.yellow.bind(ctx);
- ctx.blue = $.blue.bind(ctx);
- ctx.magenta = $.magenta.bind(ctx);
- ctx.cyan = $.cyan.bind(ctx);
- ctx.white = $.white.bind(ctx);
- ctx.gray = $.gray.bind(ctx);
- ctx.grey = $.grey.bind(ctx);
- ctx.bgBlack = $.bgBlack.bind(ctx);
- ctx.bgRed = $.bgRed.bind(ctx);
- ctx.bgGreen = $.bgGreen.bind(ctx);
- ctx.bgYellow = $.bgYellow.bind(ctx);
- ctx.bgBlue = $.bgBlue.bind(ctx);
- ctx.bgMagenta = $.bgMagenta.bind(ctx);
- ctx.bgCyan = $.bgCyan.bind(ctx);
- ctx.bgWhite = $.bgWhite.bind(ctx);
- return ctx;
- }
- function init(open, close) {
- let blk = {
- open: `\x1b[${open}m`,
- close: `\x1b[${close}m`,
- rgx: new RegExp(`\\x1b\\[${close}m`, 'g')
- };
- return function (txt) {
- if (this !== void 0 && this.has !== void 0) {
- this.has.includes(open) || (this.has.push(open),this.keys.push(blk));
- return txt === void 0 ? this : $.enabled ? run(this.keys, txt+'') : txt+'';
- }
- return txt === void 0 ? chain([open], [blk]) : $.enabled ? run([blk], txt+'') : txt+'';
- };
- }
- kleur = $;
- return kleur;
- }
- var action$1;
- var hasRequiredAction$1;
- function requireAction$1 () {
- if (hasRequiredAction$1) return action$1;
- hasRequiredAction$1 = 1;
- action$1 = (key, isSelect) => {
- if (key.meta && key.name !== 'escape') return;
- if (key.ctrl) {
- if (key.name === 'a') return 'first';
- if (key.name === 'c') return 'abort';
- if (key.name === 'd') return 'abort';
- if (key.name === 'e') return 'last';
- if (key.name === 'g') return 'reset';
- }
- if (isSelect) {
- if (key.name === 'j') return 'down';
- if (key.name === 'k') return 'up';
- }
- if (key.name === 'return') return 'submit';
- if (key.name === 'enter') return 'submit'; // ctrl + J
- if (key.name === 'backspace') return 'delete';
- if (key.name === 'delete') return 'deleteForward';
- if (key.name === 'abort') return 'abort';
- if (key.name === 'escape') return 'exit';
- if (key.name === 'tab') return 'next';
- if (key.name === 'pagedown') return 'nextPage';
- if (key.name === 'pageup') return 'prevPage'; // TODO create home() in prompt types (e.g. TextPrompt)
- if (key.name === 'home') return 'home'; // TODO create end() in prompt types (e.g. TextPrompt)
- if (key.name === 'end') return 'end';
- if (key.name === 'up') return 'up';
- if (key.name === 'down') return 'down';
- if (key.name === 'right') return 'right';
- if (key.name === 'left') return 'left';
- return false;
- };
- return action$1;
- }
- var strip$1;
- var hasRequiredStrip$1;
- function requireStrip$1 () {
- if (hasRequiredStrip$1) return strip$1;
- hasRequiredStrip$1 = 1;
- strip$1 = str => {
- const pattern = ['[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)', '(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))'].join('|');
- const RGX = new RegExp(pattern, 'g');
- return typeof str === 'string' ? str.replace(RGX, '') : str;
- };
- return strip$1;
- }
- 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 clear$1;
- var hasRequiredClear$1;
- function requireClear$1 () {
- if (hasRequiredClear$1) return clear$1;
- hasRequiredClear$1 = 1;
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
- const strip = requireStrip$1();
- const _require = requireSrc(),
- erase = _require.erase,
- cursor = _require.cursor;
- const width = str => [...strip(str)].length;
- /**
- * @param {string} prompt
- * @param {number} perLine
- */
- clear$1 = function (prompt, perLine) {
- if (!perLine) return erase.line + cursor.to(0);
- let rows = 0;
- const lines = prompt.split(/\r?\n/);
- var _iterator = _createForOfIteratorHelper(lines),
- _step;
- try {
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
- let line = _step.value;
- rows += 1 + Math.floor(Math.max(width(line) - 1, 0) / perLine);
- }
- } catch (err) {
- _iterator.e(err);
- } finally {
- _iterator.f();
- }
- return erase.lines(rows);
- };
- return clear$1;
- }
- var figures_1$1;
- var hasRequiredFigures$1;
- function requireFigures$1 () {
- if (hasRequiredFigures$1) return figures_1$1;
- hasRequiredFigures$1 = 1;
- const main = {
- arrowUp: '↑',
- arrowDown: '↓',
- arrowLeft: '←',
- arrowRight: '→',
- radioOn: '◉',
- radioOff: '◯',
- tick: '✔',
- cross: '✖',
- ellipsis: '…',
- pointerSmall: '›',
- line: '─',
- pointer: '❯'
- };
- const win = {
- arrowUp: main.arrowUp,
- arrowDown: main.arrowDown,
- arrowLeft: main.arrowLeft,
- arrowRight: main.arrowRight,
- radioOn: '(*)',
- radioOff: '( )',
- tick: '√',
- cross: '×',
- ellipsis: '...',
- pointerSmall: '»',
- line: '─',
- pointer: '>'
- };
- const figures = process.platform === 'win32' ? win : main;
- figures_1$1 = figures;
- return figures_1$1;
- }
- var style$1;
- var hasRequiredStyle$1;
- function requireStyle$1 () {
- if (hasRequiredStyle$1) return style$1;
- hasRequiredStyle$1 = 1;
- const c = requireKleur();
- const figures = requireFigures$1(); // rendering user input.
- const styles = Object.freeze({
- password: {
- scale: 1,
- render: input => '*'.repeat(input.length)
- },
- emoji: {
- scale: 2,
- render: input => '😃'.repeat(input.length)
- },
- invisible: {
- scale: 0,
- render: input => ''
- },
- default: {
- scale: 1,
- render: input => `${input}`
- }
- });
- const render = type => styles[type] || styles.default; // icon to signalize a prompt.
- const symbols = Object.freeze({
- aborted: c.red(figures.cross),
- done: c.green(figures.tick),
- exited: c.yellow(figures.cross),
- default: c.cyan('?')
- });
- const symbol = (done, aborted, exited) => aborted ? symbols.aborted : exited ? symbols.exited : done ? symbols.done : symbols.default; // between the question and the user's input.
- const delimiter = completing => c.gray(completing ? figures.ellipsis : figures.pointerSmall);
- const item = (expandable, expanded) => c.gray(expandable ? expanded ? figures.pointerSmall : '+' : figures.line);
- style$1 = {
- styles,
- render,
- symbols,
- symbol,
- delimiter,
- item
- };
- return style$1;
- }
- var lines$1;
- var hasRequiredLines$1;
- function requireLines$1 () {
- if (hasRequiredLines$1) return lines$1;
- hasRequiredLines$1 = 1;
- const strip = requireStrip$1();
- /**
- * @param {string} msg
- * @param {number} perLine
- */
- lines$1 = function (msg, perLine) {
- let lines = String(strip(msg) || '').split(/\r?\n/);
- if (!perLine) return lines.length;
- return lines.map(l => Math.ceil(l.length / perLine)).reduce((a, b) => a + b);
- };
- return lines$1;
- }
- var wrap$1;
- var hasRequiredWrap$1;
- function requireWrap$1 () {
- if (hasRequiredWrap$1) return wrap$1;
- hasRequiredWrap$1 = 1;
- /**
- * @param {string} msg The message to wrap
- * @param {object} opts
- * @param {number|string} [opts.margin] Left margin
- * @param {number} opts.width Maximum characters per line including the margin
- */
- wrap$1 = (msg, opts = {}) => {
- const tab = Number.isSafeInteger(parseInt(opts.margin)) ? new Array(parseInt(opts.margin)).fill(' ').join('') : opts.margin || '';
- const width = opts.width;
- return (msg || '').split(/\r?\n/g).map(line => line.split(/\s+/g).reduce((arr, w) => {
- if (w.length + tab.length >= width || arr[arr.length - 1].length + w.length + 1 < width) arr[arr.length - 1] += ` ${w}`;else arr.push(`${tab}${w}`);
- return arr;
- }, [tab]).join('\n')).join('\n');
- };
- return wrap$1;
- }
- var entriesToDisplay$1;
- var hasRequiredEntriesToDisplay$1;
- function requireEntriesToDisplay$1 () {
- if (hasRequiredEntriesToDisplay$1) return entriesToDisplay$1;
- hasRequiredEntriesToDisplay$1 = 1;
- /**
- * Determine what entries should be displayed on the screen, based on the
- * currently selected index and the maximum visible. Used in list-based
- * prompts like `select` and `multiselect`.
- *
- * @param {number} cursor the currently selected entry
- * @param {number} total the total entries available to display
- * @param {number} [maxVisible] the number of entries that can be displayed
- */
- entriesToDisplay$1 = (cursor, total, maxVisible) => {
- maxVisible = maxVisible || total;
- let startIndex = Math.min(total - maxVisible, cursor - Math.floor(maxVisible / 2));
- if (startIndex < 0) startIndex = 0;
- let endIndex = Math.min(startIndex + maxVisible, total);
- return {
- startIndex,
- endIndex
- };
- };
- return entriesToDisplay$1;
- }
- var util$1;
- var hasRequiredUtil$1;
- function requireUtil$1 () {
- if (hasRequiredUtil$1) return util$1;
- hasRequiredUtil$1 = 1;
- util$1 = {
- action: requireAction$1(),
- clear: requireClear$1(),
- style: requireStyle$1(),
- strip: requireStrip$1(),
- figures: requireFigures$1(),
- lines: requireLines$1(),
- wrap: requireWrap$1(),
- entriesToDisplay: requireEntriesToDisplay$1()
- };
- return util$1;
- }
- var prompt$1;
- var hasRequiredPrompt$1;
- function requirePrompt$1 () {
- if (hasRequiredPrompt$1) return prompt$1;
- hasRequiredPrompt$1 = 1;
- const readline = require$$0;
- const _require = requireUtil$1(),
- action = _require.action;
- const EventEmitter = require$$2;
- const _require2 = requireSrc(),
- beep = _require2.beep,
- cursor = _require2.cursor;
- const color = requireKleur();
- /**
- * Base prompt skeleton
- * @param {Stream} [opts.stdin] The Readable stream to listen to
- * @param {Stream} [opts.stdout] The Writable stream to write readline data to
- */
- class Prompt extends EventEmitter {
- constructor(opts = {}) {
- super();
- this.firstRender = true;
- this.in = opts.stdin || process.stdin;
- this.out = opts.stdout || process.stdout;
- this.onRender = (opts.onRender || (() => void 0)).bind(this);
- const rl = readline.createInterface({
- input: this.in,
- escapeCodeTimeout: 50
- });
- readline.emitKeypressEvents(this.in, rl);
- if (this.in.isTTY) this.in.setRawMode(true);
- const isSelect = ['SelectPrompt', 'MultiselectPrompt'].indexOf(this.constructor.name) > -1;
- const keypress = (str, key) => {
- let a = action(key, isSelect);
- if (a === false) {
- this._ && this._(str, key);
- } else if (typeof this[a] === 'function') {
- this[a](key);
- } else {
- this.bell();
- }
- };
- this.close = () => {
- this.out.write(cursor.show);
- this.in.removeListener('keypress', keypress);
- if (this.in.isTTY) this.in.setRawMode(false);
- rl.close();
- this.emit(this.aborted ? 'abort' : this.exited ? 'exit' : 'submit', this.value);
- this.closed = true;
- };
- this.in.on('keypress', keypress);
- }
- fire() {
- this.emit('state', {
- value: this.value,
- aborted: !!this.aborted,
- exited: !!this.exited
- });
- }
- bell() {
- this.out.write(beep);
- }
- render() {
- this.onRender(color);
- if (this.firstRender) this.firstRender = false;
- }
- }
- prompt$1 = Prompt;
- return prompt$1;
- }
- var text$1;
- var hasRequiredText$1;
- function requireText$1 () {
- if (hasRequiredText$1) return text$1;
- hasRequiredText$1 = 1;
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
- const color = requireKleur();
- const Prompt = requirePrompt$1();
- const _require = requireSrc(),
- erase = _require.erase,
- cursor = _require.cursor;
- const _require2 = requireUtil$1(),
- style = _require2.style,
- clear = _require2.clear,
- lines = _require2.lines,
- figures = _require2.figures;
- /**
- * TextPrompt Base Element
- * @param {Object} opts Options
- * @param {String} opts.message Message
- * @param {String} [opts.style='default'] Render style
- * @param {String} [opts.initial] Default value
- * @param {Function} [opts.validate] Validate function
- * @param {Stream} [opts.stdin] The Readable stream to listen to
- * @param {Stream} [opts.stdout] The Writable stream to write readline data to
- * @param {String} [opts.error] The invalid error label
- */
- class TextPrompt extends Prompt {
- constructor(opts = {}) {
- super(opts);
- this.transform = style.render(opts.style);
- this.scale = this.transform.scale;
- this.msg = opts.message;
- this.initial = opts.initial || ``;
- this.validator = opts.validate || (() => true);
- this.value = ``;
- this.errorMsg = opts.error || `Please Enter A Valid Value`;
- this.cursor = Number(!!this.initial);
- this.cursorOffset = 0;
- this.clear = clear(``, this.out.columns);
- this.render();
- }
- set value(v) {
- if (!v && this.initial) {
- this.placeholder = true;
- this.rendered = color.gray(this.transform.render(this.initial));
- } else {
- this.placeholder = false;
- this.rendered = this.transform.render(v);
- }
- this._value = v;
- this.fire();
- }
- get value() {
- return this._value;
- }
- reset() {
- this.value = ``;
- this.cursor = Number(!!this.initial);
- this.cursorOffset = 0;
- this.fire();
- this.render();
- }
- exit() {
- this.abort();
- }
- abort() {
- this.value = this.value || this.initial;
- this.done = this.aborted = true;
- this.error = false;
- this.red = false;
- this.fire();
- this.render();
- this.out.write('\n');
- this.close();
- }
- validate() {
- var _this = this;
- return _asyncToGenerator(function* () {
- let valid = yield _this.validator(_this.value);
- if (typeof valid === `string`) {
- _this.errorMsg = valid;
- valid = false;
- }
- _this.error = !valid;
- })();
- }
- submit() {
- var _this2 = this;
- return _asyncToGenerator(function* () {
- _this2.value = _this2.value || _this2.initial;
- _this2.cursorOffset = 0;
- _this2.cursor = _this2.rendered.length;
- yield _this2.validate();
- if (_this2.error) {
- _this2.red = true;
- _this2.fire();
- _this2.render();
- return;
- }
- _this2.done = true;
- _this2.aborted = false;
- _this2.fire();
- _this2.render();
- _this2.out.write('\n');
- _this2.close();
- })();
- }
- next() {
- if (!this.placeholder) return this.bell();
- this.value = this.initial;
- this.cursor = this.rendered.length;
- this.fire();
- this.render();
- }
- moveCursor(n) {
- if (this.placeholder) return;
- this.cursor = this.cursor + n;
- this.cursorOffset += n;
- }
- _(c, key) {
- let s1 = this.value.slice(0, this.cursor);
- let s2 = this.value.slice(this.cursor);
- this.value = `${s1}${c}${s2}`;
- this.red = false;
- this.cursor = this.placeholder ? 0 : s1.length + 1;
- this.render();
- }
- delete() {
- if (this.isCursorAtStart()) return this.bell();
- let s1 = this.value.slice(0, this.cursor - 1);
- let s2 = this.value.slice(this.cursor);
- this.value = `${s1}${s2}`;
- this.red = false;
- if (this.isCursorAtStart()) {
- this.cursorOffset = 0;
- } else {
- this.cursorOffset++;
- this.moveCursor(-1);
- }
- this.render();
- }
- deleteForward() {
- if (this.cursor * this.scale >= this.rendered.length || this.placeholder) return this.bell();
- let s1 = this.value.slice(0, this.cursor);
- let s2 = this.value.slice(this.cursor + 1);
- this.value = `${s1}${s2}`;
- this.red = false;
- if (this.isCursorAtEnd()) {
- this.cursorOffset = 0;
- } else {
- this.cursorOffset++;
- }
- this.render();
- }
- first() {
- this.cursor = 0;
- this.render();
- }
- last() {
- this.cursor = this.value.length;
- this.render();
- }
- left() {
- if (this.cursor <= 0 || this.placeholder) return this.bell();
- this.moveCursor(-1);
- this.render();
- }
- right() {
- if (this.cursor * this.scale >= this.rendered.length || this.placeholder) return this.bell();
- this.moveCursor(1);
- this.render();
- }
- isCursorAtStart() {
- return this.cursor === 0 || this.placeholder && this.cursor === 1;
- }
- isCursorAtEnd() {
- return this.cursor === this.rendered.length || this.placeholder && this.cursor === this.rendered.length + 1;
- }
- render() {
- if (this.closed) return;
- if (!this.firstRender) {
- if (this.outputError) this.out.write(cursor.down(lines(this.outputError, this.out.columns) - 1) + clear(this.outputError, this.out.columns));
- this.out.write(clear(this.outputText, this.out.columns));
- }
- super.render();
- this.outputError = '';
- this.outputText = [style.symbol(this.done, this.aborted), color.bold(this.msg), style.delimiter(this.done), this.red ? color.red(this.rendered) : this.rendered].join(` `);
- if (this.error) {
- this.outputError += this.errorMsg.split(`\n`).reduce((a, l, i) => a + `\n${i ? ' ' : figures.pointerSmall} ${color.red().italic(l)}`, ``);
- }
- this.out.write(erase.line + cursor.to(0) + this.outputText + cursor.save + this.outputError + cursor.restore + cursor.move(this.cursorOffset, 0));
- }
- }
- text$1 = TextPrompt;
- return text$1;
- }
- var select$1;
- var hasRequiredSelect$1;
- function requireSelect$1 () {
- if (hasRequiredSelect$1) return select$1;
- hasRequiredSelect$1 = 1;
- const color = requireKleur();
- const Prompt = requirePrompt$1();
- const _require = requireUtil$1(),
- style = _require.style,
- clear = _require.clear,
- figures = _require.figures,
- wrap = _require.wrap,
- entriesToDisplay = _require.entriesToDisplay;
- const _require2 = requireSrc(),
- cursor = _require2.cursor;
- /**
- * SelectPrompt Base Element
- * @param {Object} opts Options
- * @param {String} opts.message Message
- * @param {Array} opts.choices Array of choice objects
- * @param {String} [opts.hint] Hint to display
- * @param {Number} [opts.initial] Index of default value
- * @param {Stream} [opts.stdin] The Readable stream to listen to
- * @param {Stream} [opts.stdout] The Writable stream to write readline data to
- * @param {Number} [opts.optionsPerPage=10] Max options to display at once
- */
- class SelectPrompt extends Prompt {
- constructor(opts = {}) {
- super(opts);
- this.msg = opts.message;
- this.hint = opts.hint || '- Use arrow-keys. Return to submit.';
- this.warn = opts.warn || '- This option is disabled';
- this.cursor = opts.initial || 0;
- this.choices = opts.choices.map((ch, idx) => {
- if (typeof ch === 'string') ch = {
- title: ch,
- value: idx
- };
- return {
- title: ch && (ch.title || ch.value || ch),
- value: ch && (ch.value === undefined ? idx : ch.value),
- description: ch && ch.description,
- selected: ch && ch.selected,
- disabled: ch && ch.disabled
- };
- });
- this.optionsPerPage = opts.optionsPerPage || 10;
- this.value = (this.choices[this.cursor] || {}).value;
- this.clear = clear('', this.out.columns);
- this.render();
- }
- moveCursor(n) {
- this.cursor = n;
- this.value = this.choices[n].value;
- this.fire();
- }
- reset() {
- this.moveCursor(0);
- this.fire();
- this.render();
- }
- exit() {
- this.abort();
- }
- abort() {
- this.done = this.aborted = true;
- this.fire();
- this.render();
- this.out.write('\n');
- this.close();
- }
- submit() {
- if (!this.selection.disabled) {
- this.done = true;
- this.aborted = false;
- this.fire();
- this.render();
- this.out.write('\n');
- this.close();
- } else this.bell();
- }
- first() {
- this.moveCursor(0);
- this.render();
- }
- last() {
- this.moveCursor(this.choices.length - 1);
- this.render();
- }
- up() {
- if (this.cursor === 0) {
- this.moveCursor(this.choices.length - 1);
- } else {
- this.moveCursor(this.cursor - 1);
- }
- this.render();
- }
- down() {
- if (this.cursor === this.choices.length - 1) {
- this.moveCursor(0);
- } else {
- this.moveCursor(this.cursor + 1);
- }
- this.render();
- }
- next() {
- this.moveCursor((this.cursor + 1) % this.choices.length);
- this.render();
- }
- _(c, key) {
- if (c === ' ') return this.submit();
- }
- get selection() {
- return this.choices[this.cursor];
- }
- render() {
- if (this.closed) return;
- if (this.firstRender) this.out.write(cursor.hide);else this.out.write(clear(this.outputText, this.out.columns));
- super.render();
- let _entriesToDisplay = entriesToDisplay(this.cursor, this.choices.length, this.optionsPerPage),
- startIndex = _entriesToDisplay.startIndex,
- endIndex = _entriesToDisplay.endIndex; // Print prompt
- this.outputText = [style.symbol(this.done, this.aborted), color.bold(this.msg), style.delimiter(false), this.done ? this.selection.title : this.selection.disabled ? color.yellow(this.warn) : color.gray(this.hint)].join(' '); // Print choices
- if (!this.done) {
- this.outputText += '\n';
- for (let i = startIndex; i < endIndex; i++) {
- let title,
- prefix,
- desc = '',
- v = this.choices[i]; // Determine whether to display "more choices" indicators
- if (i === startIndex && startIndex > 0) {
- prefix = figures.arrowUp;
- } else if (i === endIndex - 1 && endIndex < this.choices.length) {
- prefix = figures.arrowDown;
- } else {
- prefix = ' ';
- }
- if (v.disabled) {
- title = this.cursor === i ? color.gray().underline(v.title) : color.strikethrough().gray(v.title);
- prefix = (this.cursor === i ? color.bold().gray(figures.pointer) + ' ' : ' ') + prefix;
- } else {
- title = this.cursor === i ? color.cyan().underline(v.title) : v.title;
- prefix = (this.cursor === i ? color.cyan(figures.pointer) + ' ' : ' ') + prefix;
- if (v.description && this.cursor === i) {
- desc = ` - ${v.description}`;
- if (prefix.length + title.length + desc.length >= this.out.columns || v.description.split(/\r?\n/).length > 1) {
- desc = '\n' + wrap(v.description, {
- margin: 3,
- width: this.out.columns
- });
- }
- }
- }
- this.outputText += `${prefix} ${title}${color.gray(desc)}\n`;
- }
- }
- this.out.write(this.outputText);
- }
- }
- select$1 = SelectPrompt;
- return select$1;
- }
- var toggle$1;
- var hasRequiredToggle$1;
- function requireToggle$1 () {
- if (hasRequiredToggle$1) return toggle$1;
- hasRequiredToggle$1 = 1;
- const color = requireKleur();
- const Prompt = requirePrompt$1();
- const _require = requireUtil$1(),
- style = _require.style,
- clear = _require.clear;
- const _require2 = requireSrc(),
- cursor = _require2.cursor,
- erase = _require2.erase;
- /**
- * TogglePrompt Base Element
- * @param {Object} opts Options
- * @param {String} opts.message Message
- * @param {Boolean} [opts.initial=false] Default value
- * @param {String} [opts.active='no'] Active label
- * @param {String} [opts.inactive='off'] Inactive label
- * @param {Stream} [opts.stdin] The Readable stream to listen to
- * @param {Stream} [opts.stdout] The Writable stream to write readline data to
- */
- class TogglePrompt extends Prompt {
- constructor(opts = {}) {
- super(opts);
- this.msg = opts.message;
- this.value = !!opts.initial;
- this.active = opts.active || 'on';
- this.inactive = opts.inactive || 'off';
- this.initialValue = this.value;
- this.render();
- }
- reset() {
- this.value = this.initialValue;
- this.fire();
- this.render();
- }
- exit() {
- this.abort();
- }
- abort() {
- this.done = this.aborted = true;
- this.fire();
- this.render();
- this.out.write('\n');
- this.close();
- }
- submit() {
- this.done = true;
- this.aborted = false;
- this.fire();
- this.render();
- this.out.write('\n');
- this.close();
- }
- deactivate() {
- if (this.value === false) return this.bell();
- this.value = false;
- this.render();
- }
- activate() {
- if (this.value === true) return this.bell();
- this.value = true;
- this.render();
- }
- delete() {
- this.deactivate();
- }
- left() {
- this.deactivate();
- }
- right() {
- this.activate();
- }
- down() {
- this.deactivate();
- }
- up() {
- this.activate();
- }
- next() {
- this.value = !this.value;
- this.fire();
- this.render();
- }
- _(c, key) {
- if (c === ' ') {
- this.value = !this.value;
- } else if (c === '1') {
- this.value = true;
- } else if (c === '0') {
- this.value = false;
- } else return this.bell();
- this.render();
- }
- render() {
- if (this.closed) return;
- if (this.firstRender) this.out.write(cursor.hide);else this.out.write(clear(this.outputText, this.out.columns));
- super.render();
- this.outputText = [style.symbol(this.done, this.aborted), color.bold(this.msg), style.delimiter(this.done), this.value ? this.inactive : color.cyan().underline(this.inactive), color.gray('/'), this.value ? color.cyan().underline(this.active) : this.active].join(' ');
- this.out.write(erase.line + cursor.to(0) + this.outputText);
- }
- }
- toggle$1 = TogglePrompt;
- return toggle$1;
- }
- var datepart$1;
- var hasRequiredDatepart$1;
- function requireDatepart$1 () {
- if (hasRequiredDatepart$1) return datepart$1;
- hasRequiredDatepart$1 = 1;
- class DatePart {
- constructor({
- token,
- date,
- parts,
- locales
- }) {
- this.token = token;
- this.date = date || new Date();
- this.parts = parts || [this];
- this.locales = locales || {};
- }
- up() {}
- down() {}
- next() {
- const currentIdx = this.parts.indexOf(this);
- return this.parts.find((part, idx) => idx > currentIdx && part instanceof DatePart);
- }
- setTo(val) {}
- prev() {
- let parts = [].concat(this.parts).reverse();
- const currentIdx = parts.indexOf(this);
- return parts.find((part, idx) => idx > currentIdx && part instanceof DatePart);
- }
- toString() {
- return String(this.date);
- }
- }
- datepart$1 = DatePart;
- return datepart$1;
- }
- var meridiem$1;
- var hasRequiredMeridiem$1;
- function requireMeridiem$1 () {
- if (hasRequiredMeridiem$1) return meridiem$1;
- hasRequiredMeridiem$1 = 1;
- const DatePart = requireDatepart$1();
- class Meridiem extends DatePart {
- constructor(opts = {}) {
- super(opts);
- }
- up() {
- this.date.setHours((this.date.getHours() + 12) % 24);
- }
- down() {
- this.up();
- }
- toString() {
- let meridiem = this.date.getHours() > 12 ? 'pm' : 'am';
- return /\A/.test(this.token) ? meridiem.toUpperCase() : meridiem;
- }
- }
- meridiem$1 = Meridiem;
- return meridiem$1;
- }
- var day$1;
- var hasRequiredDay$1;
- function requireDay$1 () {
- if (hasRequiredDay$1) return day$1;
- hasRequiredDay$1 = 1;
- const DatePart = requireDatepart$1();
- const pos = n => {
- n = n % 10;
- return n === 1 ? 'st' : n === 2 ? 'nd' : n === 3 ? 'rd' : 'th';
- };
- class Day extends DatePart {
- constructor(opts = {}) {
- super(opts);
- }
- up() {
- this.date.setDate(this.date.getDate() + 1);
- }
- down() {
- this.date.setDate(this.date.getDate() - 1);
- }
- setTo(val) {
- this.date.setDate(parseInt(val.substr(-2)));
- }
- toString() {
- let date = this.date.getDate();
- let day = this.date.getDay();
- return this.token === 'DD' ? String(date).padStart(2, '0') : this.token === 'Do' ? date + pos(date) : this.token === 'd' ? day + 1 : this.token === 'ddd' ? this.locales.weekdaysShort[day] : this.token === 'dddd' ? this.locales.weekdays[day] : date;
- }
- }
- day$1 = Day;
- return day$1;
- }
- var hours$1;
- var hasRequiredHours$1;
- function requireHours$1 () {
- if (hasRequiredHours$1) return hours$1;
- hasRequiredHours$1 = 1;
- const DatePart = requireDatepart$1();
- class Hours extends DatePart {
- constructor(opts = {}) {
- super(opts);
- }
- up() {
- this.date.setHours(this.date.getHours() + 1);
- }
- down() {
- this.date.setHours(this.date.getHours() - 1);
- }
- setTo(val) {
- this.date.setHours(parseInt(val.substr(-2)));
- }
- toString() {
- let hours = this.date.getHours();
- if (/h/.test(this.token)) hours = hours % 12 || 12;
- return this.token.length > 1 ? String(hours).padStart(2, '0') : hours;
- }
- }
- hours$1 = Hours;
- return hours$1;
- }
- var milliseconds$1;
- var hasRequiredMilliseconds$1;
- function requireMilliseconds$1 () {
- if (hasRequiredMilliseconds$1) return milliseconds$1;
- hasRequiredMilliseconds$1 = 1;
- const DatePart = requireDatepart$1();
- class Milliseconds extends DatePart {
- constructor(opts = {}) {
- super(opts);
- }
- up() {
- this.date.setMilliseconds(this.date.getMilliseconds() + 1);
- }
- down() {
- this.date.setMilliseconds(this.date.getMilliseconds() - 1);
- }
- setTo(val) {
- this.date.setMilliseconds(parseInt(val.substr(-this.token.length)));
- }
- toString() {
- return String(this.date.getMilliseconds()).padStart(4, '0').substr(0, this.token.length);
- }
- }
- milliseconds$1 = Milliseconds;
- return milliseconds$1;
- }
- var minutes$1;
- var hasRequiredMinutes$1;
- function requireMinutes$1 () {
- if (hasRequiredMinutes$1) return minutes$1;
- hasRequiredMinutes$1 = 1;
- const DatePart = requireDatepart$1();
- class Minutes extends DatePart {
- constructor(opts = {}) {
- super(opts);
- }
- up() {
- this.date.setMinutes(this.date.getMinutes() + 1);
- }
- down() {
- this.date.setMinutes(this.date.getMinutes() - 1);
- }
- setTo(val) {
- this.date.setMinutes(parseInt(val.substr(-2)));
- }
- toString() {
- let m = this.date.getMinutes();
- return this.token.length > 1 ? String(m).padStart(2, '0') : m;
- }
- }
- minutes$1 = Minutes;
- return minutes$1;
- }
- var month$1;
- var hasRequiredMonth$1;
- function requireMonth$1 () {
- if (hasRequiredMonth$1) return month$1;
- hasRequiredMonth$1 = 1;
- const DatePart = requireDatepart$1();
- class Month extends DatePart {
- constructor(opts = {}) {
- super(opts);
- }
- up() {
- this.date.setMonth(this.date.getMonth() + 1);
- }
- down() {
- this.date.setMonth(this.date.getMonth() - 1);
- }
- setTo(val) {
- val = parseInt(val.substr(-2)) - 1;
- this.date.setMonth(val < 0 ? 0 : val);
- }
- toString() {
- let month = this.date.getMonth();
- let tl = this.token.length;
- return tl === 2 ? String(month + 1).padStart(2, '0') : tl === 3 ? this.locales.monthsShort[month] : tl === 4 ? this.locales.months[month] : String(month + 1);
- }
- }
- month$1 = Month;
- return month$1;
- }
- var seconds$1;
- var hasRequiredSeconds$1;
- function requireSeconds$1 () {
- if (hasRequiredSeconds$1) return seconds$1;
- hasRequiredSeconds$1 = 1;
- const DatePart = requireDatepart$1();
- class Seconds extends DatePart {
- constructor(opts = {}) {
- super(opts);
- }
- up() {
- this.date.setSeconds(this.date.getSeconds() + 1);
- }
- down() {
- this.date.setSeconds(this.date.getSeconds() - 1);
- }
- setTo(val) {
- this.date.setSeconds(parseInt(val.substr(-2)));
- }
- toString() {
- let s = this.date.getSeconds();
- return this.token.length > 1 ? String(s).padStart(2, '0') : s;
- }
- }
- seconds$1 = Seconds;
- return seconds$1;
- }
- var year$1;
- var hasRequiredYear$1;
- function requireYear$1 () {
- if (hasRequiredYear$1) return year$1;
- hasRequiredYear$1 = 1;
- const DatePart = requireDatepart$1();
- class Year extends DatePart {
- constructor(opts = {}) {
- super(opts);
- }
- up() {
- this.date.setFullYear(this.date.getFullYear() + 1);
- }
- down() {
- this.date.setFullYear(this.date.getFullYear() - 1);
- }
- setTo(val) {
- this.date.setFullYear(val.substr(-4));
- }
- toString() {
- let year = String(this.date.getFullYear()).padStart(4, '0');
- return this.token.length === 2 ? year.substr(-2) : year;
- }
- }
- year$1 = Year;
- return year$1;
- }
- var dateparts$1;
- var hasRequiredDateparts$1;
- function requireDateparts$1 () {
- if (hasRequiredDateparts$1) return dateparts$1;
- hasRequiredDateparts$1 = 1;
- dateparts$1 = {
- DatePart: requireDatepart$1(),
- Meridiem: requireMeridiem$1(),
- Day: requireDay$1(),
- Hours: requireHours$1(),
- Milliseconds: requireMilliseconds$1(),
- Minutes: requireMinutes$1(),
- Month: requireMonth$1(),
- Seconds: requireSeconds$1(),
- Year: requireYear$1()
- };
- return dateparts$1;
- }
- var date$1;
- var hasRequiredDate$1;
- function requireDate$1 () {
- if (hasRequiredDate$1) return date$1;
- hasRequiredDate$1 = 1;
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
- const color = requireKleur();
- const Prompt = requirePrompt$1();
- const _require = requireUtil$1(),
- style = _require.style,
- clear = _require.clear,
- figures = _require.figures;
- const _require2 = requireSrc(),
- erase = _require2.erase,
- cursor = _require2.cursor;
- const _require3 = requireDateparts$1(),
- DatePart = _require3.DatePart,
- Meridiem = _require3.Meridiem,
- Day = _require3.Day,
- Hours = _require3.Hours,
- Milliseconds = _require3.Milliseconds,
- Minutes = _require3.Minutes,
- Month = _require3.Month,
- Seconds = _require3.Seconds,
- Year = _require3.Year;
- const regex = /\\(.)|"((?:\\["\\]|[^"])+)"|(D[Do]?|d{3,4}|d)|(M{1,4})|(YY(?:YY)?)|([aA])|([Hh]{1,2})|(m{1,2})|(s{1,2})|(S{1,4})|./g;
- const regexGroups = {
- 1: ({
- token
- }) => token.replace(/\\(.)/g, '$1'),
- 2: opts => new Day(opts),
- // Day // TODO
- 3: opts => new Month(opts),
- // Month
- 4: opts => new Year(opts),
- // Year
- 5: opts => new Meridiem(opts),
- // AM/PM // TODO (special)
- 6: opts => new Hours(opts),
- // Hours
- 7: opts => new Minutes(opts),
- // Minutes
- 8: opts => new Seconds(opts),
- // Seconds
- 9: opts => new Milliseconds(opts) // Fractional seconds
- };
- const dfltLocales = {
- months: 'January,February,March,April,May,June,July,August,September,October,November,December'.split(','),
- monthsShort: 'Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec'.split(','),
- weekdays: 'Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday'.split(','),
- weekdaysShort: 'Sun,Mon,Tue,Wed,Thu,Fri,Sat'.split(',')
- };
- /**
- * DatePrompt Base Element
- * @param {Object} opts Options
- * @param {String} opts.message Message
- * @param {Number} [opts.initial] Index of default value
- * @param {String} [opts.mask] The format mask
- * @param {object} [opts.locales] The date locales
- * @param {String} [opts.error] The error message shown on invalid value
- * @param {Function} [opts.validate] Function to validate the submitted value
- * @param {Stream} [opts.stdin] The Readable stream to listen to
- * @param {Stream} [opts.stdout] The Writable stream to write readline data to
- */
- class DatePrompt extends Prompt {
- constructor(opts = {}) {
- super(opts);
- this.msg = opts.message;
- this.cursor = 0;
- this.typed = '';
- this.locales = Object.assign(dfltLocales, opts.locales);
- this._date = opts.initial || new Date();
- this.errorMsg = opts.error || 'Please Enter A Valid Value';
- this.validator = opts.validate || (() => true);
- this.mask = opts.mask || 'YYYY-MM-DD HH:mm:ss';
- this.clear = clear('', this.out.columns);
- this.render();
- }
- get value() {
- return this.date;
- }
- get date() {
- return this._date;
- }
- set date(date) {
- if (date) this._date.setTime(date.getTime());
- }
- set mask(mask) {
- let result;
- this.parts = [];
- while (result = regex.exec(mask)) {
- let match = result.shift();
- let idx = result.findIndex(gr => gr != null);
- this.parts.push(idx in regexGroups ? regexGroups[idx]({
- token: result[idx] || match,
- date: this.date,
- parts: this.parts,
- locales: this.locales
- }) : result[idx] || match);
- }
- let parts = this.parts.reduce((arr, i) => {
- if (typeof i === 'string' && typeof arr[arr.length - 1] === 'string') arr[arr.length - 1] += i;else arr.push(i);
- return arr;
- }, []);
- this.parts.splice(0);
- this.parts.push(...parts);
- this.reset();
- }
- moveCursor(n) {
- this.typed = '';
- this.cursor = n;
- this.fire();
- }
- reset() {
- this.moveCursor(this.parts.findIndex(p => p instanceof DatePart));
- this.fire();
- this.render();
- }
- exit() {
- this.abort();
- }
- abort() {
- this.done = this.aborted = true;
- this.error = false;
- this.fire();
- this.render();
- this.out.write('\n');
- this.close();
- }
- validate() {
- var _this = this;
- return _asyncToGenerator(function* () {
- let valid = yield _this.validator(_this.value);
- if (typeof valid === 'string') {
- _this.errorMsg = valid;
- valid = false;
- }
- _this.error = !valid;
- })();
- }
- submit() {
- var _this2 = this;
- return _asyncToGenerator(function* () {
- yield _this2.validate();
- if (_this2.error) {
- _this2.color = 'red';
- _this2.fire();
- _this2.render();
- return;
- }
- _this2.done = true;
- _this2.aborted = false;
- _this2.fire();
- _this2.render();
- _this2.out.write('\n');
- _this2.close();
- })();
- }
- up() {
- this.typed = '';
- this.parts[this.cursor].up();
- this.render();
- }
- down() {
- this.typed = '';
- this.parts[this.cursor].down();
- this.render();
- }
- left() {
- let prev = this.parts[this.cursor].prev();
- if (prev == null) return this.bell();
- this.moveCursor(this.parts.indexOf(prev));
- this.render();
- }
- right() {
- let next = this.parts[this.cursor].next();
- if (next == null) return this.bell();
- this.moveCursor(this.parts.indexOf(next));
- this.render();
- }
- next() {
- let next = this.parts[this.cursor].next();
- this.moveCursor(next ? this.parts.indexOf(next) : this.parts.findIndex(part => part instanceof DatePart));
- this.render();
- }
- _(c) {
- if (/\d/.test(c)) {
- this.typed += c;
- this.parts[this.cursor].setTo(this.typed);
- this.render();
- }
- }
- render() {
- if (this.closed) return;
- if (this.firstRender) this.out.write(cursor.hide);else this.out.write(clear(this.outputText, this.out.columns));
- super.render(); // Print prompt
- this.outputText = [style.symbol(this.done, this.aborted), color.bold(this.msg), style.delimiter(false), this.parts.reduce((arr, p, idx) => arr.concat(idx === this.cursor && !this.done ? color.cyan().underline(p.toString()) : p), []).join('')].join(' '); // Print error
- if (this.error) {
- this.outputText += this.errorMsg.split('\n').reduce((a, l, i) => a + `\n${i ? ` ` : figures.pointerSmall} ${color.red().italic(l)}`, ``);
- }
- this.out.write(erase.line + cursor.to(0) + this.outputText);
- }
- }
- date$1 = DatePrompt;
- return date$1;
- }
- var number$1;
- var hasRequiredNumber$1;
- function requireNumber$1 () {
- if (hasRequiredNumber$1) return number$1;
- hasRequiredNumber$1 = 1;
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
- const color = requireKleur();
- const Prompt = requirePrompt$1();
- const _require = requireSrc(),
- cursor = _require.cursor,
- erase = _require.erase;
- const _require2 = requireUtil$1(),
- style = _require2.style,
- figures = _require2.figures,
- clear = _require2.clear,
- lines = _require2.lines;
- const isNumber = /[0-9]/;
- const isDef = any => any !== undefined;
- const round = (number, precision) => {
- let factor = Math.pow(10, precision);
- return Math.round(number * factor) / factor;
- };
- /**
- * NumberPrompt Base Element
- * @param {Object} opts Options
- * @param {String} opts.message Message
- * @param {String} [opts.style='default'] Render style
- * @param {Number} [opts.initial] Default value
- * @param {Number} [opts.max=+Infinity] Max value
- * @param {Number} [opts.min=-Infinity] Min value
- * @param {Boolean} [opts.float=false] Parse input as floats
- * @param {Number} [opts.round=2] Round floats to x decimals
- * @param {Number} [opts.increment=1] Number to increment by when using arrow-keys
- * @param {Function} [opts.validate] Validate function
- * @param {Stream} [opts.stdin] The Readable stream to listen to
- * @param {Stream} [opts.stdout] The Writable stream to write readline data to
- * @param {String} [opts.error] The invalid error label
- */
- class NumberPrompt extends Prompt {
- constructor(opts = {}) {
- super(opts);
- this.transform = style.render(opts.style);
- this.msg = opts.message;
- this.initial = isDef(opts.initial) ? opts.initial : '';
- this.float = !!opts.float;
- this.round = opts.round || 2;
- this.inc = opts.increment || 1;
- this.min = isDef(opts.min) ? opts.min : -Infinity;
- this.max = isDef(opts.max) ? opts.max : Infinity;
- this.errorMsg = opts.error || `Please Enter A Valid Value`;
- this.validator = opts.validate || (() => true);
- this.color = `cyan`;
- this.value = ``;
- this.typed = ``;
- this.lastHit = 0;
- this.render();
- }
- set value(v) {
- if (!v && v !== 0) {
- this.placeholder = true;
- this.rendered = color.gray(this.transform.render(`${this.initial}`));
- this._value = ``;
- } else {
- this.placeholder = false;
- this.rendered = this.transform.render(`${round(v, this.round)}`);
- this._value = round(v, this.round);
- }
- this.fire();
- }
- get value() {
- return this._value;
- }
- parse(x) {
- return this.float ? parseFloat(x) : parseInt(x);
- }
- valid(c) {
- return c === `-` || c === `.` && this.float || isNumber.test(c);
- }
- reset() {
- this.typed = ``;
- this.value = ``;
- this.fire();
- this.render();
- }
- exit() {
- this.abort();
- }
- abort() {
- let x = this.value;
- this.value = x !== `` ? x : this.initial;
- this.done = this.aborted = true;
- this.error = false;
- this.fire();
- this.render();
- this.out.write(`\n`);
- this.close();
- }
- validate() {
- var _this = this;
- return _asyncToGenerator(function* () {
- let valid = yield _this.validator(_this.value);
- if (typeof valid === `string`) {
- _this.errorMsg = valid;
- valid = false;
- }
- _this.error = !valid;
- })();
- }
- submit() {
- var _this2 = this;
- return _asyncToGenerator(function* () {
- yield _this2.validate();
- if (_this2.error) {
- _this2.color = `red`;
- _this2.fire();
- _this2.render();
- return;
- }
- let x = _this2.value;
- _this2.value = x !== `` ? x : _this2.initial;
- _this2.done = true;
- _this2.aborted = false;
- _this2.error = false;
- _this2.fire();
- _this2.render();
- _this2.out.write(`\n`);
- _this2.close();
- })();
- }
- up() {
- this.typed = ``;
- if (this.value === '') {
- this.value = this.min - this.inc;
- }
- if (this.value >= this.max) return this.bell();
- this.value += this.inc;
- this.color = `cyan`;
- this.fire();
- this.render();
- }
- down() {
- this.typed = ``;
- if (this.value === '') {
- this.value = this.min + this.inc;
- }
- if (this.value <= this.min) return this.bell();
- this.value -= this.inc;
- this.color = `cyan`;
- this.fire();
- this.render();
- }
- delete() {
- let val = this.value.toString();
- if (val.length === 0) return this.bell();
- this.value = this.parse(val = val.slice(0, -1)) || ``;
- if (this.value !== '' && this.value < this.min) {
- this.value = this.min;
- }
- this.color = `cyan`;
- this.fire();
- this.render();
- }
- next() {
- this.value = this.initial;
- this.fire();
- this.render();
- }
- _(c, key) {
- if (!this.valid(c)) return this.bell();
- const now = Date.now();
- if (now - this.lastHit > 1000) this.typed = ``; // 1s elapsed
- this.typed += c;
- this.lastHit = now;
- this.color = `cyan`;
- if (c === `.`) return this.fire();
- this.value = Math.min(this.parse(this.typed), this.max);
- if (this.value > this.max) this.value = this.max;
- if (this.value < this.min) this.value = this.min;
- this.fire();
- this.render();
- }
- render() {
- if (this.closed) return;
- if (!this.firstRender) {
- if (this.outputError) this.out.write(cursor.down(lines(this.outputError, this.out.columns) - 1) + clear(this.outputError, this.out.columns));
- this.out.write(clear(this.outputText, this.out.columns));
- }
- super.render();
- this.outputError = ''; // Print prompt
- this.outputText = [style.symbol(this.done, this.aborted), color.bold(this.msg), style.delimiter(this.done), !this.done || !this.done && !this.placeholder ? color[this.color]().underline(this.rendered) : this.rendered].join(` `); // Print error
- if (this.error) {
- this.outputError += this.errorMsg.split(`\n`).reduce((a, l, i) => a + `\n${i ? ` ` : figures.pointerSmall} ${color.red().italic(l)}`, ``);
- }
- this.out.write(erase.line + cursor.to(0) + this.outputText + cursor.save + this.outputError + cursor.restore);
- }
- }
- number$1 = NumberPrompt;
- return number$1;
- }
- var multiselect$1;
- var hasRequiredMultiselect$1;
- function requireMultiselect$1 () {
- if (hasRequiredMultiselect$1) return multiselect$1;
- hasRequiredMultiselect$1 = 1;
- const color = requireKleur();
- const _require = requireSrc(),
- cursor = _require.cursor;
- const Prompt = requirePrompt$1();
- const _require2 = requireUtil$1(),
- clear = _require2.clear,
- figures = _require2.figures,
- style = _require2.style,
- wrap = _require2.wrap,
- entriesToDisplay = _require2.entriesToDisplay;
- /**
- * MultiselectPrompt Base Element
- * @param {Object} opts Options
- * @param {String} opts.message Message
- * @param {Array} opts.choices Array of choice objects
- * @param {String} [opts.hint] Hint to display
- * @param {String} [opts.warn] Hint shown for disabled choices
- * @param {Number} [opts.max] Max choices
- * @param {Number} [opts.cursor=0] Cursor start position
- * @param {Number} [opts.optionsPerPage=10] Max options to display at once
- * @param {Stream} [opts.stdin] The Readable stream to listen to
- * @param {Stream} [opts.stdout] The Writable stream to write readline data to
- */
- class MultiselectPrompt extends Prompt {
- constructor(opts = {}) {
- super(opts);
- this.msg = opts.message;
- this.cursor = opts.cursor || 0;
- this.scrollIndex = opts.cursor || 0;
- this.hint = opts.hint || '';
- this.warn = opts.warn || '- This option is disabled -';
- this.minSelected = opts.min;
- this.showMinError = false;
- this.maxChoices = opts.max;
- this.instructions = opts.instructions;
- this.optionsPerPage = opts.optionsPerPage || 10;
- this.value = opts.choices.map((ch, idx) => {
- if (typeof ch === 'string') ch = {
- title: ch,
- value: idx
- };
- return {
- title: ch && (ch.title || ch.value || ch),
- description: ch && ch.description,
- value: ch && (ch.value === undefined ? idx : ch.value),
- selected: ch && ch.selected,
- disabled: ch && ch.disabled
- };
- });
- this.clear = clear('', this.out.columns);
- if (!opts.overrideRender) {
- this.render();
- }
- }
- reset() {
- this.value.map(v => !v.selected);
- this.cursor = 0;
- this.fire();
- this.render();
- }
- selected() {
- return this.value.filter(v => v.selected);
- }
- exit() {
- this.abort();
- }
- abort() {
- this.done = this.aborted = true;
- this.fire();
- this.render();
- this.out.write('\n');
- this.close();
- }
- submit() {
- const selected = this.value.filter(e => e.selected);
- if (this.minSelected && selected.length < this.minSelected) {
- this.showMinError = true;
- this.render();
- } else {
- this.done = true;
- this.aborted = false;
- this.fire();
- this.render();
- this.out.write('\n');
- this.close();
- }
- }
- first() {
- this.cursor = 0;
- this.render();
- }
- last() {
- this.cursor = this.value.length - 1;
- this.render();
- }
- next() {
- this.cursor = (this.cursor + 1) % this.value.length;
- this.render();
- }
- up() {
- if (this.cursor === 0) {
- this.cursor = this.value.length - 1;
- } else {
- this.cursor--;
- }
- this.render();
- }
- down() {
- if (this.cursor === this.value.length - 1) {
- this.cursor = 0;
- } else {
- this.cursor++;
- }
- this.render();
- }
- left() {
- this.value[this.cursor].selected = false;
- this.render();
- }
- right() {
- if (this.value.filter(e => e.selected).length >= this.maxChoices) return this.bell();
- this.value[this.cursor].selected = true;
- this.render();
- }
- handleSpaceToggle() {
- const v = this.value[this.cursor];
- if (v.selected) {
- v.selected = false;
- this.render();
- } else if (v.disabled || this.value.filter(e => e.selected).length >= this.maxChoices) {
- return this.bell();
- } else {
- v.selected = true;
- this.render();
- }
- }
- toggleAll() {
- if (this.maxChoices !== undefined || this.value[this.cursor].disabled) {
- return this.bell();
- }
- const newSelected = !this.value[this.cursor].selected;
- this.value.filter(v => !v.disabled).forEach(v => v.selected = newSelected);
- this.render();
- }
- _(c, key) {
- if (c === ' ') {
- this.handleSpaceToggle();
- } else if (c === 'a') {
- this.toggleAll();
- } else {
- return this.bell();
- }
- }
- renderInstructions() {
- if (this.instructions === undefined || this.instructions) {
- if (typeof this.instructions === 'string') {
- return this.instructions;
- }
- return '\nInstructions:\n' + ` ${figures.arrowUp}/${figures.arrowDown}: Highlight option\n` + ` ${figures.arrowLeft}/${figures.arrowRight}/[space]: Toggle selection\n` + (this.maxChoices === undefined ? ` a: Toggle all\n` : '') + ` enter/return: Complete answer`;
- }
- return '';
- }
- renderOption(cursor, v, i, arrowIndicator) {
- const prefix = (v.selected ? color.green(figures.radioOn) : figures.radioOff) + ' ' + arrowIndicator + ' ';
- let title, desc;
- if (v.disabled) {
- title = cursor === i ? color.gray().underline(v.title) : color.strikethrough().gray(v.title);
- } else {
- title = cursor === i ? color.cyan().underline(v.title) : v.title;
- if (cursor === i && v.description) {
- desc = ` - ${v.description}`;
- if (prefix.length + title.length + desc.length >= this.out.columns || v.description.split(/\r?\n/).length > 1) {
- desc = '\n' + wrap(v.description, {
- margin: prefix.length,
- width: this.out.columns
- });
- }
- }
- }
- return prefix + title + color.gray(desc || '');
- } // shared with autocompleteMultiselect
- paginateOptions(options) {
- if (options.length === 0) {
- return color.red('No matches for this query.');
- }
- let _entriesToDisplay = entriesToDisplay(this.cursor, options.length, this.optionsPerPage),
- startIndex = _entriesToDisplay.startIndex,
- endIndex = _entriesToDisplay.endIndex;
- let prefix,
- styledOptions = [];
- for (let i = startIndex; i < endIndex; i++) {
- if (i === startIndex && startIndex > 0) {
- prefix = figures.arrowUp;
- } else if (i === endIndex - 1 && endIndex < options.length) {
- prefix = figures.arrowDown;
- } else {
- prefix = ' ';
- }
- styledOptions.push(this.renderOption(this.cursor, options[i], i, prefix));
- }
- return '\n' + styledOptions.join('\n');
- } // shared with autocomleteMultiselect
- renderOptions(options) {
- if (!this.done) {
- return this.paginateOptions(options);
- }
- return '';
- }
- renderDoneOrInstructions() {
- if (this.done) {
- return this.value.filter(e => e.selected).map(v => v.title).join(', ');
- }
- const output = [color.gray(this.hint), this.renderInstructions()];
- if (this.value[this.cursor].disabled) {
- output.push(color.yellow(this.warn));
- }
- return output.join(' ');
- }
- render() {
- if (this.closed) return;
- if (this.firstRender) this.out.write(cursor.hide);
- super.render(); // print prompt
- let prompt = [style.symbol(this.done, this.aborted), color.bold(this.msg), style.delimiter(false), this.renderDoneOrInstructions()].join(' ');
- if (this.showMinError) {
- prompt += color.red(`You must select a minimum of ${this.minSelected} choices.`);
- this.showMinError = false;
- }
- prompt += this.renderOptions(this.value);
- this.out.write(this.clear + prompt);
- this.clear = clear(prompt, this.out.columns);
- }
- }
- multiselect$1 = MultiselectPrompt;
- return multiselect$1;
- }
- var autocomplete$1;
- var hasRequiredAutocomplete$1;
- function requireAutocomplete$1 () {
- if (hasRequiredAutocomplete$1) return autocomplete$1;
- hasRequiredAutocomplete$1 = 1;
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
- const color = requireKleur();
- const Prompt = requirePrompt$1();
- const _require = requireSrc(),
- erase = _require.erase,
- cursor = _require.cursor;
- const _require2 = requireUtil$1(),
- style = _require2.style,
- clear = _require2.clear,
- figures = _require2.figures,
- wrap = _require2.wrap,
- entriesToDisplay = _require2.entriesToDisplay;
- const getVal = (arr, i) => arr[i] && (arr[i].value || arr[i].title || arr[i]);
- const getTitle = (arr, i) => arr[i] && (arr[i].title || arr[i].value || arr[i]);
- const getIndex = (arr, valOrTitle) => {
- const index = arr.findIndex(el => el.value === valOrTitle || el.title === valOrTitle);
- return index > -1 ? index : undefined;
- };
- /**
- * TextPrompt Base Element
- * @param {Object} opts Options
- * @param {String} opts.message Message
- * @param {Array} opts.choices Array of auto-complete choices objects
- * @param {Function} [opts.suggest] Filter function. Defaults to sort by title
- * @param {Number} [opts.limit=10] Max number of results to show
- * @param {Number} [opts.cursor=0] Cursor start position
- * @param {String} [opts.style='default'] Render style
- * @param {String} [opts.fallback] Fallback message - initial to default value
- * @param {String} [opts.initial] Index of the default value
- * @param {Boolean} [opts.clearFirst] The first ESCAPE keypress will clear the input
- * @param {Stream} [opts.stdin] The Readable stream to listen to
- * @param {Stream} [opts.stdout] The Writable stream to write readline data to
- * @param {String} [opts.noMatches] The no matches found label
- */
- class AutocompletePrompt extends Prompt {
- constructor(opts = {}) {
- super(opts);
- this.msg = opts.message;
- this.suggest = opts.suggest;
- this.choices = opts.choices;
- this.initial = typeof opts.initial === 'number' ? opts.initial : getIndex(opts.choices, opts.initial);
- this.select = this.initial || opts.cursor || 0;
- this.i18n = {
- noMatches: opts.noMatches || 'no matches found'
- };
- this.fallback = opts.fallback || this.initial;
- this.clearFirst = opts.clearFirst || false;
- this.suggestions = [];
- this.input = '';
- this.limit = opts.limit || 10;
- this.cursor = 0;
- this.transform = style.render(opts.style);
- this.scale = this.transform.scale;
- this.render = this.render.bind(this);
- this.complete = this.complete.bind(this);
- this.clear = clear('', this.out.columns);
- this.complete(this.render);
- this.render();
- }
- set fallback(fb) {
- this._fb = Number.isSafeInteger(parseInt(fb)) ? parseInt(fb) : fb;
- }
- get fallback() {
- let choice;
- if (typeof this._fb === 'number') choice = this.choices[this._fb];else if (typeof this._fb === 'string') choice = {
- title: this._fb
- };
- return choice || this._fb || {
- title: this.i18n.noMatches
- };
- }
- moveSelect(i) {
- this.select = i;
- if (this.suggestions.length > 0) this.value = getVal(this.suggestions, i);else this.value = this.fallback.value;
- this.fire();
- }
- complete(cb) {
- var _this = this;
- return _asyncToGenerator(function* () {
- const p = _this.completing = _this.suggest(_this.input, _this.choices);
- const suggestions = yield p;
- if (_this.completing !== p) return;
- _this.suggestions = suggestions.map((s, i, arr) => ({
- title: getTitle(arr, i),
- value: getVal(arr, i),
- description: s.description
- }));
- _this.completing = false;
- const l = Math.max(suggestions.length - 1, 0);
- _this.moveSelect(Math.min(l, _this.select));
- cb && cb();
- })();
- }
- reset() {
- this.input = '';
- this.complete(() => {
- this.moveSelect(this.initial !== void 0 ? this.initial : 0);
- this.render();
- });
- this.render();
- }
- exit() {
- if (this.clearFirst && this.input.length > 0) {
- this.reset();
- } else {
- this.done = this.exited = true;
- this.aborted = false;
- this.fire();
- this.render();
- this.out.write('\n');
- this.close();
- }
- }
- abort() {
- this.done = this.aborted = true;
- this.exited = false;
- this.fire();
- this.render();
- this.out.write('\n');
- this.close();
- }
- submit() {
- this.done = true;
- this.aborted = this.exited = false;
- this.fire();
- this.render();
- this.out.write('\n');
- this.close();
- }
- _(c, key) {
- let s1 = this.input.slice(0, this.cursor);
- let s2 = this.input.slice(this.cursor);
- this.input = `${s1}${c}${s2}`;
- this.cursor = s1.length + 1;
- this.complete(this.render);
- this.render();
- }
- delete() {
- if (this.cursor === 0) return this.bell();
- let s1 = this.input.slice(0, this.cursor - 1);
- let s2 = this.input.slice(this.cursor);
- this.input = `${s1}${s2}`;
- this.complete(this.render);
- this.cursor = this.cursor - 1;
- this.render();
- }
- deleteForward() {
- if (this.cursor * this.scale >= this.rendered.length) return this.bell();
- let s1 = this.input.slice(0, this.cursor);
- let s2 = this.input.slice(this.cursor + 1);
- this.input = `${s1}${s2}`;
- this.complete(this.render);
- this.render();
- }
- first() {
- this.moveSelect(0);
- this.render();
- }
- last() {
- this.moveSelect(this.suggestions.length - 1);
- this.render();
- }
- up() {
- if (this.select === 0) {
- this.moveSelect(this.suggestions.length - 1);
- } else {
- this.moveSelect(this.select - 1);
- }
- this.render();
- }
- down() {
- if (this.select === this.suggestions.length - 1) {
- this.moveSelect(0);
- } else {
- this.moveSelect(this.select + 1);
- }
- this.render();
- }
- next() {
- if (this.select === this.suggestions.length - 1) {
- this.moveSelect(0);
- } else this.moveSelect(this.select + 1);
- this.render();
- }
- nextPage() {
- this.moveSelect(Math.min(this.select + this.limit, this.suggestions.length - 1));
- this.render();
- }
- prevPage() {
- this.moveSelect(Math.max(this.select - this.limit, 0));
- this.render();
- }
- left() {
- if (this.cursor <= 0) return this.bell();
- this.cursor = this.cursor - 1;
- this.render();
- }
- right() {
- if (this.cursor * this.scale >= this.rendered.length) return this.bell();
- this.cursor = this.cursor + 1;
- this.render();
- }
- renderOption(v, hovered, isStart, isEnd) {
- let desc;
- let prefix = isStart ? figures.arrowUp : isEnd ? figures.arrowDown : ' ';
- let title = hovered ? color.cyan().underline(v.title) : v.title;
- prefix = (hovered ? color.cyan(figures.pointer) + ' ' : ' ') + prefix;
- if (v.description) {
- desc = ` - ${v.description}`;
- if (prefix.length + title.length + desc.length >= this.out.columns || v.description.split(/\r?\n/).length > 1) {
- desc = '\n' + wrap(v.description, {
- margin: 3,
- width: this.out.columns
- });
- }
- }
- return prefix + ' ' + title + color.gray(desc || '');
- }
- render() {
- if (this.closed) return;
- if (this.firstRender) this.out.write(cursor.hide);else this.out.write(clear(this.outputText, this.out.columns));
- super.render();
- let _entriesToDisplay = entriesToDisplay(this.select, this.choices.length, this.limit),
- startIndex = _entriesToDisplay.startIndex,
- endIndex = _entriesToDisplay.endIndex;
- this.outputText = [style.symbol(this.done, this.aborted, this.exited), color.bold(this.msg), style.delimiter(this.completing), this.done && this.suggestions[this.select] ? this.suggestions[this.select].title : this.rendered = this.transform.render(this.input)].join(' ');
- if (!this.done) {
- const suggestions = this.suggestions.slice(startIndex, endIndex).map((item, i) => this.renderOption(item, this.select === i + startIndex, i === 0 && startIndex > 0, i + startIndex === endIndex - 1 && endIndex < this.choices.length)).join('\n');
- this.outputText += `\n` + (suggestions || color.gray(this.fallback.title));
- }
- this.out.write(erase.line + cursor.to(0) + this.outputText);
- }
- }
- autocomplete$1 = AutocompletePrompt;
- return autocomplete$1;
- }
- var autocompleteMultiselect$1;
- var hasRequiredAutocompleteMultiselect$1;
- function requireAutocompleteMultiselect$1 () {
- if (hasRequiredAutocompleteMultiselect$1) return autocompleteMultiselect$1;
- hasRequiredAutocompleteMultiselect$1 = 1;
- const color = requireKleur();
- const _require = requireSrc(),
- cursor = _require.cursor;
- const MultiselectPrompt = requireMultiselect$1();
- const _require2 = requireUtil$1(),
- clear = _require2.clear,
- style = _require2.style,
- figures = _require2.figures;
- /**
- * MultiselectPrompt Base Element
- * @param {Object} opts Options
- * @param {String} opts.message Message
- * @param {Array} opts.choices Array of choice objects
- * @param {String} [opts.hint] Hint to display
- * @param {String} [opts.warn] Hint shown for disabled choices
- * @param {Number} [opts.max] Max choices
- * @param {Number} [opts.cursor=0] Cursor start position
- * @param {Stream} [opts.stdin] The Readable stream to listen to
- * @param {Stream} [opts.stdout] The Writable stream to write readline data to
- */
- class AutocompleteMultiselectPrompt extends MultiselectPrompt {
- constructor(opts = {}) {
- opts.overrideRender = true;
- super(opts);
- this.inputValue = '';
- this.clear = clear('', this.out.columns);
- this.filteredOptions = this.value;
- this.render();
- }
- last() {
- this.cursor = this.filteredOptions.length - 1;
- this.render();
- }
- next() {
- this.cursor = (this.cursor + 1) % this.filteredOptions.length;
- this.render();
- }
- up() {
- if (this.cursor === 0) {
- this.cursor = this.filteredOptions.length - 1;
- } else {
- this.cursor--;
- }
- this.render();
- }
- down() {
- if (this.cursor === this.filteredOptions.length - 1) {
- this.cursor = 0;
- } else {
- this.cursor++;
- }
- this.render();
- }
- left() {
- this.filteredOptions[this.cursor].selected = false;
- this.render();
- }
- right() {
- if (this.value.filter(e => e.selected).length >= this.maxChoices) return this.bell();
- this.filteredOptions[this.cursor].selected = true;
- this.render();
- }
- delete() {
- if (this.inputValue.length) {
- this.inputValue = this.inputValue.substr(0, this.inputValue.length - 1);
- this.updateFilteredOptions();
- }
- }
- updateFilteredOptions() {
- const currentHighlight = this.filteredOptions[this.cursor];
- this.filteredOptions = this.value.filter(v => {
- if (this.inputValue) {
- if (typeof v.title === 'string') {
- if (v.title.toLowerCase().includes(this.inputValue.toLowerCase())) {
- return true;
- }
- }
- if (typeof v.value === 'string') {
- if (v.value.toLowerCase().includes(this.inputValue.toLowerCase())) {
- return true;
- }
- }
- return false;
- }
- return true;
- });
- const newHighlightIndex = this.filteredOptions.findIndex(v => v === currentHighlight);
- this.cursor = newHighlightIndex < 0 ? 0 : newHighlightIndex;
- this.render();
- }
- handleSpaceToggle() {
- const v = this.filteredOptions[this.cursor];
- if (v.selected) {
- v.selected = false;
- this.render();
- } else if (v.disabled || this.value.filter(e => e.selected).length >= this.maxChoices) {
- return this.bell();
- } else {
- v.selected = true;
- this.render();
- }
- }
- handleInputChange(c) {
- this.inputValue = this.inputValue + c;
- this.updateFilteredOptions();
- }
- _(c, key) {
- if (c === ' ') {
- this.handleSpaceToggle();
- } else {
- this.handleInputChange(c);
- }
- }
- renderInstructions() {
- if (this.instructions === undefined || this.instructions) {
- if (typeof this.instructions === 'string') {
- return this.instructions;
- }
- return `
- Instructions:
- ${figures.arrowUp}/${figures.arrowDown}: Highlight option
- ${figures.arrowLeft}/${figures.arrowRight}/[space]: Toggle selection
- [a,b,c]/delete: Filter choices
- enter/return: Complete answer
- `;
- }
- return '';
- }
- renderCurrentInput() {
- return `
- Filtered results for: ${this.inputValue ? this.inputValue : color.gray('Enter something to filter')}\n`;
- }
- renderOption(cursor, v, i) {
- let title;
- if (v.disabled) title = cursor === i ? color.gray().underline(v.title) : color.strikethrough().gray(v.title);else title = cursor === i ? color.cyan().underline(v.title) : v.title;
- return (v.selected ? color.green(figures.radioOn) : figures.radioOff) + ' ' + title;
- }
- renderDoneOrInstructions() {
- if (this.done) {
- return this.value.filter(e => e.selected).map(v => v.title).join(', ');
- }
- const output = [color.gray(this.hint), this.renderInstructions(), this.renderCurrentInput()];
- if (this.filteredOptions.length && this.filteredOptions[this.cursor].disabled) {
- output.push(color.yellow(this.warn));
- }
- return output.join(' ');
- }
- render() {
- if (this.closed) return;
- if (this.firstRender) this.out.write(cursor.hide);
- super.render(); // print prompt
- let prompt = [style.symbol(this.done, this.aborted), color.bold(this.msg), style.delimiter(false), this.renderDoneOrInstructions()].join(' ');
- if (this.showMinError) {
- prompt += color.red(`You must select a minimum of ${this.minSelected} choices.`);
- this.showMinError = false;
- }
- prompt += this.renderOptions(this.filteredOptions);
- this.out.write(this.clear + prompt);
- this.clear = clear(prompt, this.out.columns);
- }
- }
- autocompleteMultiselect$1 = AutocompleteMultiselectPrompt;
- return autocompleteMultiselect$1;
- }
- var confirm$1;
- var hasRequiredConfirm$1;
- function requireConfirm$1 () {
- if (hasRequiredConfirm$1) return confirm$1;
- hasRequiredConfirm$1 = 1;
- const color = requireKleur();
- const Prompt = requirePrompt$1();
- const _require = requireUtil$1(),
- style = _require.style,
- clear = _require.clear;
- const _require2 = requireSrc(),
- erase = _require2.erase,
- cursor = _require2.cursor;
- /**
- * ConfirmPrompt Base Element
- * @param {Object} opts Options
- * @param {String} opts.message Message
- * @param {Boolean} [opts.initial] Default value (true/false)
- * @param {Stream} [opts.stdin] The Readable stream to listen to
- * @param {Stream} [opts.stdout] The Writable stream to write readline data to
- * @param {String} [opts.yes] The "Yes" label
- * @param {String} [opts.yesOption] The "Yes" option when choosing between yes/no
- * @param {String} [opts.no] The "No" label
- * @param {String} [opts.noOption] The "No" option when choosing between yes/no
- */
- class ConfirmPrompt extends Prompt {
- constructor(opts = {}) {
- super(opts);
- this.msg = opts.message;
- this.value = opts.initial;
- this.initialValue = !!opts.initial;
- this.yesMsg = opts.yes || 'yes';
- this.yesOption = opts.yesOption || '(Y/n)';
- this.noMsg = opts.no || 'no';
- this.noOption = opts.noOption || '(y/N)';
- this.render();
- }
- reset() {
- this.value = this.initialValue;
- this.fire();
- this.render();
- }
- exit() {
- this.abort();
- }
- abort() {
- this.done = this.aborted = true;
- this.fire();
- this.render();
- this.out.write('\n');
- this.close();
- }
- submit() {
- this.value = this.value || false;
- this.done = true;
- this.aborted = false;
- this.fire();
- this.render();
- this.out.write('\n');
- this.close();
- }
- _(c, key) {
- if (c.toLowerCase() === 'y') {
- this.value = true;
- return this.submit();
- }
- if (c.toLowerCase() === 'n') {
- this.value = false;
- return this.submit();
- }
- return this.bell();
- }
- render() {
- if (this.closed) return;
- if (this.firstRender) this.out.write(cursor.hide);else this.out.write(clear(this.outputText, this.out.columns));
- super.render();
- this.outputText = [style.symbol(this.done, this.aborted), color.bold(this.msg), style.delimiter(this.done), this.done ? this.value ? this.yesMsg : this.noMsg : color.gray(this.initialValue ? this.yesOption : this.noOption)].join(' ');
- this.out.write(erase.line + cursor.to(0) + this.outputText);
- }
- }
- confirm$1 = ConfirmPrompt;
- return confirm$1;
- }
- var elements$1;
- var hasRequiredElements$1;
- function requireElements$1 () {
- if (hasRequiredElements$1) return elements$1;
- hasRequiredElements$1 = 1;
- elements$1 = {
- TextPrompt: requireText$1(),
- SelectPrompt: requireSelect$1(),
- TogglePrompt: requireToggle$1(),
- DatePrompt: requireDate$1(),
- NumberPrompt: requireNumber$1(),
- MultiselectPrompt: requireMultiselect$1(),
- AutocompletePrompt: requireAutocomplete$1(),
- AutocompleteMultiselectPrompt: requireAutocompleteMultiselect$1(),
- ConfirmPrompt: requireConfirm$1()
- };
- return elements$1;
- }
- var hasRequiredPrompts$1;
- function requirePrompts$1 () {
- if (hasRequiredPrompts$1) return prompts$2;
- hasRequiredPrompts$1 = 1;
- (function (exports) {
- const $ = exports;
- const el = requireElements$1();
- const noop = v => v;
- function toPrompt(type, args, opts = {}) {
- return new Promise((res, rej) => {
- const p = new el[type](args);
- const onAbort = opts.onAbort || noop;
- const onSubmit = opts.onSubmit || noop;
- const onExit = opts.onExit || noop;
- p.on('state', args.onState || noop);
- p.on('submit', x => res(onSubmit(x)));
- p.on('exit', x => res(onExit(x)));
- p.on('abort', x => rej(onAbort(x)));
- });
- }
- /**
- * Text prompt
- * @param {string} args.message Prompt message to display
- * @param {string} [args.initial] Default string value
- * @param {string} [args.style="default"] Render style ('default', 'password', 'invisible')
- * @param {function} [args.onState] On state change callback
- * @param {function} [args.validate] Function to validate user input
- * @param {Stream} [args.stdin] The Readable stream to listen to
- * @param {Stream} [args.stdout] The Writable stream to write readline data to
- * @returns {Promise} Promise with user input
- */
- $.text = args => toPrompt('TextPrompt', args);
- /**
- * Password prompt with masked input
- * @param {string} args.message Prompt message to display
- * @param {string} [args.initial] Default string value
- * @param {function} [args.onState] On state change callback
- * @param {function} [args.validate] Function to validate user input
- * @param {Stream} [args.stdin] The Readable stream to listen to
- * @param {Stream} [args.stdout] The Writable stream to write readline data to
- * @returns {Promise} Promise with user input
- */
- $.password = args => {
- args.style = 'password';
- return $.text(args);
- };
- /**
- * Prompt where input is invisible, like sudo
- * @param {string} args.message Prompt message to display
- * @param {string} [args.initial] Default string value
- * @param {function} [args.onState] On state change callback
- * @param {function} [args.validate] Function to validate user input
- * @param {Stream} [args.stdin] The Readable stream to listen to
- * @param {Stream} [args.stdout] The Writable stream to write readline data to
- * @returns {Promise} Promise with user input
- */
- $.invisible = args => {
- args.style = 'invisible';
- return $.text(args);
- };
- /**
- * Number prompt
- * @param {string} args.message Prompt message to display
- * @param {number} args.initial Default number value
- * @param {function} [args.onState] On state change callback
- * @param {number} [args.max] Max value
- * @param {number} [args.min] Min value
- * @param {string} [args.style="default"] Render style ('default', 'password', 'invisible')
- * @param {Boolean} [opts.float=false] Parse input as floats
- * @param {Number} [opts.round=2] Round floats to x decimals
- * @param {Number} [opts.increment=1] Number to increment by when using arrow-keys
- * @param {function} [args.validate] Function to validate user input
- * @param {Stream} [args.stdin] The Readable stream to listen to
- * @param {Stream} [args.stdout] The Writable stream to write readline data to
- * @returns {Promise} Promise with user input
- */
- $.number = args => toPrompt('NumberPrompt', args);
- /**
- * Date prompt
- * @param {string} args.message Prompt message to display
- * @param {number} args.initial Default number value
- * @param {function} [args.onState] On state change callback
- * @param {number} [args.max] Max value
- * @param {number} [args.min] Min value
- * @param {string} [args.style="default"] Render style ('default', 'password', 'invisible')
- * @param {Boolean} [opts.float=false] Parse input as floats
- * @param {Number} [opts.round=2] Round floats to x decimals
- * @param {Number} [opts.increment=1] Number to increment by when using arrow-keys
- * @param {function} [args.validate] Function to validate user input
- * @param {Stream} [args.stdin] The Readable stream to listen to
- * @param {Stream} [args.stdout] The Writable stream to write readline data to
- * @returns {Promise} Promise with user input
- */
- $.date = args => toPrompt('DatePrompt', args);
- /**
- * Classic yes/no prompt
- * @param {string} args.message Prompt message to display
- * @param {boolean} [args.initial=false] Default value
- * @param {function} [args.onState] On state change callback
- * @param {Stream} [args.stdin] The Readable stream to listen to
- * @param {Stream} [args.stdout] The Writable stream to write readline data to
- * @returns {Promise} Promise with user input
- */
- $.confirm = args => toPrompt('ConfirmPrompt', args);
- /**
- * List prompt, split intput string by `seperator`
- * @param {string} args.message Prompt message to display
- * @param {string} [args.initial] Default string value
- * @param {string} [args.style="default"] Render style ('default', 'password', 'invisible')
- * @param {string} [args.separator] String separator
- * @param {function} [args.onState] On state change callback
- * @param {Stream} [args.stdin] The Readable stream to listen to
- * @param {Stream} [args.stdout] The Writable stream to write readline data to
- * @returns {Promise} Promise with user input, in form of an `Array`
- */
- $.list = args => {
- const sep = args.separator || ',';
- return toPrompt('TextPrompt', args, {
- onSubmit: str => str.split(sep).map(s => s.trim())
- });
- };
- /**
- * Toggle/switch prompt
- * @param {string} args.message Prompt message to display
- * @param {boolean} [args.initial=false] Default value
- * @param {string} [args.active="on"] Text for `active` state
- * @param {string} [args.inactive="off"] Text for `inactive` state
- * @param {function} [args.onState] On state change callback
- * @param {Stream} [args.stdin] The Readable stream to listen to
- * @param {Stream} [args.stdout] The Writable stream to write readline data to
- * @returns {Promise} Promise with user input
- */
- $.toggle = args => toPrompt('TogglePrompt', args);
- /**
- * Interactive select prompt
- * @param {string} args.message Prompt message to display
- * @param {Array} args.choices Array of choices objects `[{ title, value }, ...]`
- * @param {number} [args.initial] Index of default value
- * @param {String} [args.hint] Hint to display
- * @param {function} [args.onState] On state change callback
- * @param {Stream} [args.stdin] The Readable stream to listen to
- * @param {Stream} [args.stdout] The Writable stream to write readline data to
- * @returns {Promise} Promise with user input
- */
- $.select = args => toPrompt('SelectPrompt', args);
- /**
- * Interactive multi-select / autocompleteMultiselect prompt
- * @param {string} args.message Prompt message to display
- * @param {Array} args.choices Array of choices objects `[{ title, value, [selected] }, ...]`
- * @param {number} [args.max] Max select
- * @param {string} [args.hint] Hint to display user
- * @param {Number} [args.cursor=0] Cursor start position
- * @param {function} [args.onState] On state change callback
- * @param {Stream} [args.stdin] The Readable stream to listen to
- * @param {Stream} [args.stdout] The Writable stream to write readline data to
- * @returns {Promise} Promise with user input
- */
- $.multiselect = args => {
- args.choices = [].concat(args.choices || []);
- const toSelected = items => items.filter(item => item.selected).map(item => item.value);
- return toPrompt('MultiselectPrompt', args, {
- onAbort: toSelected,
- onSubmit: toSelected
- });
- };
- $.autocompleteMultiselect = args => {
- args.choices = [].concat(args.choices || []);
- const toSelected = items => items.filter(item => item.selected).map(item => item.value);
- return toPrompt('AutocompleteMultiselectPrompt', args, {
- onAbort: toSelected,
- onSubmit: toSelected
- });
- };
- const byTitle = (input, choices) => Promise.resolve(choices.filter(item => item.title.slice(0, input.length).toLowerCase() === input.toLowerCase()));
- /**
- * Interactive auto-complete prompt
- * @param {string} args.message Prompt message to display
- * @param {Array} args.choices Array of auto-complete choices objects `[{ title, value }, ...]`
- * @param {Function} [args.suggest] Function to filter results based on user input. Defaults to sort by `title`
- * @param {number} [args.limit=10] Max number of results to show
- * @param {string} [args.style="default"] Render style ('default', 'password', 'invisible')
- * @param {String} [args.initial] Index of the default value
- * @param {boolean} [opts.clearFirst] The first ESCAPE keypress will clear the input
- * @param {String} [args.fallback] Fallback message - defaults to initial value
- * @param {function} [args.onState] On state change callback
- * @param {Stream} [args.stdin] The Readable stream to listen to
- * @param {Stream} [args.stdout] The Writable stream to write readline data to
- * @returns {Promise} Promise with user input
- */
- $.autocomplete = args => {
- args.suggest = args.suggest || byTitle;
- args.choices = [].concat(args.choices || []);
- return toPrompt('AutocompletePrompt', args);
- };
- } (prompts$2));
- return prompts$2;
- }
- var dist;
- var hasRequiredDist;
- function requireDist () {
- if (hasRequiredDist) return dist;
- hasRequiredDist = 1;
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
- const prompts = requirePrompts$1();
- const passOn = ['suggest', 'format', 'onState', 'validate', 'onRender', 'type'];
- const noop = () => {};
- /**
- * Prompt for a series of questions
- * @param {Array|Object} questions Single question object or Array of question objects
- * @param {Function} [onSubmit] Callback function called on prompt submit
- * @param {Function} [onCancel] Callback function called on cancel/abort
- * @returns {Object} Object with values from user input
- */
- function prompt() {
- return _prompt.apply(this, arguments);
- }
- function _prompt() {
- _prompt = _asyncToGenerator(function* (questions = [], {
- onSubmit = noop,
- onCancel = noop
- } = {}) {
- const answers = {};
- const override = prompt._override || {};
- questions = [].concat(questions);
- let answer, question, quit, name, type, lastPrompt;
- const getFormattedAnswer = /*#__PURE__*/function () {
- var _ref = _asyncToGenerator(function* (question, answer, skipValidation = false) {
- if (!skipValidation && question.validate && question.validate(answer) !== true) {
- return;
- }
- return question.format ? yield question.format(answer, answers) : answer;
- });
- return function getFormattedAnswer(_x, _x2) {
- return _ref.apply(this, arguments);
- };
- }();
- var _iterator = _createForOfIteratorHelper(questions),
- _step;
- try {
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
- question = _step.value;
- var _question = question;
- name = _question.name;
- type = _question.type;
- // evaluate type first and skip if type is a falsy value
- if (typeof type === 'function') {
- type = yield type(answer, _objectSpread({}, answers), question);
- question['type'] = type;
- }
- if (!type) continue; // if property is a function, invoke it unless it's a special function
- for (let key in question) {
- if (passOn.includes(key)) continue;
- let value = question[key];
- question[key] = typeof value === 'function' ? yield value(answer, _objectSpread({}, answers), lastPrompt) : value;
- }
- lastPrompt = question;
- if (typeof question.message !== 'string') {
- throw new Error('prompt message is required');
- } // update vars in case they changed
- var _question2 = question;
- name = _question2.name;
- type = _question2.type;
- if (prompts[type] === void 0) {
- throw new Error(`prompt type (${type}) is not defined`);
- }
- if (override[question.name] !== undefined) {
- answer = yield getFormattedAnswer(question, override[question.name]);
- if (answer !== undefined) {
- answers[name] = answer;
- continue;
- }
- }
- try {
- // Get the injected answer if there is one or prompt the user
- answer = prompt._injected ? getInjectedAnswer(prompt._injected, question.initial) : yield prompts[type](question);
- answers[name] = answer = yield getFormattedAnswer(question, answer, true);
- quit = yield onSubmit(question, answer, answers);
- } catch (err) {
- quit = !(yield onCancel(question, answers));
- }
- if (quit) return answers;
- }
- } catch (err) {
- _iterator.e(err);
- } finally {
- _iterator.f();
- }
- return answers;
- });
- return _prompt.apply(this, arguments);
- }
- function getInjectedAnswer(injected, deafultValue) {
- const answer = injected.shift();
- if (answer instanceof Error) {
- throw answer;
- }
- return answer === undefined ? deafultValue : answer;
- }
- function inject(answers) {
- prompt._injected = (prompt._injected || []).concat(answers);
- }
- function override(answers) {
- prompt._override = Object.assign({}, answers);
- }
- dist = Object.assign(prompt, {
- prompt,
- prompts,
- inject,
- override
- });
- return dist;
- }
- var prompts$1 = {};
- var action;
- var hasRequiredAction;
- function requireAction () {
- if (hasRequiredAction) return action;
- hasRequiredAction = 1;
- action = (key, isSelect) => {
- if (key.meta && key.name !== 'escape') return;
-
- if (key.ctrl) {
- if (key.name === 'a') return 'first';
- if (key.name === 'c') return 'abort';
- if (key.name === 'd') return 'abort';
- if (key.name === 'e') return 'last';
- if (key.name === 'g') return 'reset';
- }
-
- if (isSelect) {
- if (key.name === 'j') return 'down';
- if (key.name === 'k') return 'up';
- }
- if (key.name === 'return') return 'submit';
- if (key.name === 'enter') return 'submit'; // ctrl + J
- if (key.name === 'backspace') return 'delete';
- if (key.name === 'delete') return 'deleteForward';
- if (key.name === 'abort') return 'abort';
- if (key.name === 'escape') return 'exit';
- if (key.name === 'tab') return 'next';
- if (key.name === 'pagedown') return 'nextPage';
- if (key.name === 'pageup') return 'prevPage';
- // TODO create home() in prompt types (e.g. TextPrompt)
- if (key.name === 'home') return 'home';
- // TODO create end() in prompt types (e.g. TextPrompt)
- if (key.name === 'end') return 'end';
- if (key.name === 'up') return 'up';
- if (key.name === 'down') return 'down';
- if (key.name === 'right') return 'right';
- if (key.name === 'left') return 'left';
- return false;
- };
- return action;
- }
- var strip;
- var hasRequiredStrip;
- function requireStrip () {
- if (hasRequiredStrip) return strip;
- hasRequiredStrip = 1;
- strip = str => {
- const pattern = [
- '[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)',
- '(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))'
- ].join('|');
- const RGX = new RegExp(pattern, 'g');
- return typeof str === 'string' ? str.replace(RGX, '') : str;
- };
- return strip;
- }
- var clear;
- var hasRequiredClear;
- function requireClear () {
- if (hasRequiredClear) return clear;
- hasRequiredClear = 1;
- const strip = requireStrip();
- const { erase, cursor } = requireSrc();
- const width = str => [...strip(str)].length;
- /**
- * @param {string} prompt
- * @param {number} perLine
- */
- clear = function(prompt, perLine) {
- if (!perLine) return erase.line + cursor.to(0);
- let rows = 0;
- const lines = prompt.split(/\r?\n/);
- for (let line of lines) {
- rows += 1 + Math.floor(Math.max(width(line) - 1, 0) / perLine);
- }
- return erase.lines(rows);
- };
- return clear;
- }
- var figures_1;
- var hasRequiredFigures;
- function requireFigures () {
- if (hasRequiredFigures) return figures_1;
- hasRequiredFigures = 1;
- const main = {
- arrowUp: '↑',
- arrowDown: '↓',
- arrowLeft: '←',
- arrowRight: '→',
- radioOn: '◉',
- radioOff: '◯',
- tick: '✔',
- cross: '✖',
- ellipsis: '…',
- pointerSmall: '›',
- line: '─',
- pointer: '❯'
- };
- const win = {
- arrowUp: main.arrowUp,
- arrowDown: main.arrowDown,
- arrowLeft: main.arrowLeft,
- arrowRight: main.arrowRight,
- radioOn: '(*)',
- radioOff: '( )',
- tick: '√',
- cross: '×',
- ellipsis: '...',
- pointerSmall: '»',
- line: '─',
- pointer: '>'
- };
- const figures = process.platform === 'win32' ? win : main;
- figures_1 = figures;
- return figures_1;
- }
- var style;
- var hasRequiredStyle;
- function requireStyle () {
- if (hasRequiredStyle) return style;
- hasRequiredStyle = 1;
- const c = requireKleur();
- const figures = requireFigures();
- // rendering user input.
- const styles = Object.freeze({
- password: { scale: 1, render: input => '*'.repeat(input.length) },
- emoji: { scale: 2, render: input => '😃'.repeat(input.length) },
- invisible: { scale: 0, render: input => '' },
- default: { scale: 1, render: input => `${input}` }
- });
- const render = type => styles[type] || styles.default;
- // icon to signalize a prompt.
- const symbols = Object.freeze({
- aborted: c.red(figures.cross),
- done: c.green(figures.tick),
- exited: c.yellow(figures.cross),
- default: c.cyan('?')
- });
- const symbol = (done, aborted, exited) =>
- aborted ? symbols.aborted : exited ? symbols.exited : done ? symbols.done : symbols.default;
- // between the question and the user's input.
- const delimiter = completing =>
- c.gray(completing ? figures.ellipsis : figures.pointerSmall);
- const item = (expandable, expanded) =>
- c.gray(expandable ? (expanded ? figures.pointerSmall : '+') : figures.line);
- style = {
- styles,
- render,
- symbols,
- symbol,
- delimiter,
- item
- };
- return style;
- }
- var lines;
- var hasRequiredLines;
- function requireLines () {
- if (hasRequiredLines) return lines;
- hasRequiredLines = 1;
- const strip = requireStrip();
- /**
- * @param {string} msg
- * @param {number} perLine
- */
- lines = function (msg, perLine) {
- let lines = String(strip(msg) || '').split(/\r?\n/);
- if (!perLine) return lines.length;
- return lines.map(l => Math.ceil(l.length / perLine))
- .reduce((a, b) => a + b);
- };
- return lines;
- }
- var wrap;
- var hasRequiredWrap;
- function requireWrap () {
- if (hasRequiredWrap) return wrap;
- hasRequiredWrap = 1;
- /**
- * @param {string} msg The message to wrap
- * @param {object} opts
- * @param {number|string} [opts.margin] Left margin
- * @param {number} opts.width Maximum characters per line including the margin
- */
- wrap = (msg, opts = {}) => {
- const tab = Number.isSafeInteger(parseInt(opts.margin))
- ? new Array(parseInt(opts.margin)).fill(' ').join('')
- : (opts.margin || '');
- const width = opts.width;
- return (msg || '').split(/\r?\n/g)
- .map(line => line
- .split(/\s+/g)
- .reduce((arr, w) => {
- if (w.length + tab.length >= width || arr[arr.length - 1].length + w.length + 1 < width)
- arr[arr.length - 1] += ` ${w}`;
- else arr.push(`${tab}${w}`);
- return arr;
- }, [ tab ])
- .join('\n'))
- .join('\n');
- };
- return wrap;
- }
- var entriesToDisplay;
- var hasRequiredEntriesToDisplay;
- function requireEntriesToDisplay () {
- if (hasRequiredEntriesToDisplay) return entriesToDisplay;
- hasRequiredEntriesToDisplay = 1;
- /**
- * Determine what entries should be displayed on the screen, based on the
- * currently selected index and the maximum visible. Used in list-based
- * prompts like `select` and `multiselect`.
- *
- * @param {number} cursor the currently selected entry
- * @param {number} total the total entries available to display
- * @param {number} [maxVisible] the number of entries that can be displayed
- */
- entriesToDisplay = (cursor, total, maxVisible) => {
- maxVisible = maxVisible || total;
- let startIndex = Math.min(total- maxVisible, cursor - Math.floor(maxVisible / 2));
- if (startIndex < 0) startIndex = 0;
- let endIndex = Math.min(startIndex + maxVisible, total);
- return { startIndex, endIndex };
- };
- return entriesToDisplay;
- }
- var util;
- var hasRequiredUtil;
- function requireUtil () {
- if (hasRequiredUtil) return util;
- hasRequiredUtil = 1;
- util = {
- action: requireAction(),
- clear: requireClear(),
- style: requireStyle(),
- strip: requireStrip(),
- figures: requireFigures(),
- lines: requireLines(),
- wrap: requireWrap(),
- entriesToDisplay: requireEntriesToDisplay()
- };
- return util;
- }
- var prompt;
- var hasRequiredPrompt;
- function requirePrompt () {
- if (hasRequiredPrompt) return prompt;
- hasRequiredPrompt = 1;
- const readline = require$$0;
- const { action } = requireUtil();
- const EventEmitter = require$$2;
- const { beep, cursor } = requireSrc();
- const color = requireKleur();
- /**
- * Base prompt skeleton
- * @param {Stream} [opts.stdin] The Readable stream to listen to
- * @param {Stream} [opts.stdout] The Writable stream to write readline data to
- */
- class Prompt extends EventEmitter {
- constructor(opts={}) {
- super();
- this.firstRender = true;
- this.in = opts.stdin || process.stdin;
- this.out = opts.stdout || process.stdout;
- this.onRender = (opts.onRender || (() => void 0)).bind(this);
- const rl = readline.createInterface({ input:this.in, escapeCodeTimeout:50 });
- readline.emitKeypressEvents(this.in, rl);
- if (this.in.isTTY) this.in.setRawMode(true);
- const isSelect = [ 'SelectPrompt', 'MultiselectPrompt' ].indexOf(this.constructor.name) > -1;
- const keypress = (str, key) => {
- let a = action(key, isSelect);
- if (a === false) {
- this._ && this._(str, key);
- } else if (typeof this[a] === 'function') {
- this[a](key);
- } else {
- this.bell();
- }
- };
- this.close = () => {
- this.out.write(cursor.show);
- this.in.removeListener('keypress', keypress);
- if (this.in.isTTY) this.in.setRawMode(false);
- rl.close();
- this.emit(this.aborted ? 'abort' : this.exited ? 'exit' : 'submit', this.value);
- this.closed = true;
- };
- this.in.on('keypress', keypress);
- }
- fire() {
- this.emit('state', {
- value: this.value,
- aborted: !!this.aborted,
- exited: !!this.exited
- });
- }
- bell() {
- this.out.write(beep);
- }
- render() {
- this.onRender(color);
- if (this.firstRender) this.firstRender = false;
- }
- }
- prompt = Prompt;
- return prompt;
- }
- var text;
- var hasRequiredText;
- function requireText () {
- if (hasRequiredText) return text;
- hasRequiredText = 1;
- const color = requireKleur();
- const Prompt = requirePrompt();
- const { erase, cursor } = requireSrc();
- const { style, clear, lines, figures } = requireUtil();
- /**
- * TextPrompt Base Element
- * @param {Object} opts Options
- * @param {String} opts.message Message
- * @param {String} [opts.style='default'] Render style
- * @param {String} [opts.initial] Default value
- * @param {Function} [opts.validate] Validate function
- * @param {Stream} [opts.stdin] The Readable stream to listen to
- * @param {Stream} [opts.stdout] The Writable stream to write readline data to
- * @param {String} [opts.error] The invalid error label
- */
- class TextPrompt extends Prompt {
- constructor(opts={}) {
- super(opts);
- this.transform = style.render(opts.style);
- this.scale = this.transform.scale;
- this.msg = opts.message;
- this.initial = opts.initial || ``;
- this.validator = opts.validate || (() => true);
- this.value = ``;
- this.errorMsg = opts.error || `Please Enter A Valid Value`;
- this.cursor = Number(!!this.initial);
- this.cursorOffset = 0;
- this.clear = clear(``, this.out.columns);
- this.render();
- }
- set value(v) {
- if (!v && this.initial) {
- this.placeholder = true;
- this.rendered = color.gray(this.transform.render(this.initial));
- } else {
- this.placeholder = false;
- this.rendered = this.transform.render(v);
- }
- this._value = v;
- this.fire();
- }
- get value() {
- return this._value;
- }
- reset() {
- this.value = ``;
- this.cursor = Number(!!this.initial);
- this.cursorOffset = 0;
- this.fire();
- this.render();
- }
- exit() {
- this.abort();
- }
- abort() {
- this.value = this.value || this.initial;
- this.done = this.aborted = true;
- this.error = false;
- this.red = false;
- this.fire();
- this.render();
- this.out.write('\n');
- this.close();
- }
- async validate() {
- let valid = await this.validator(this.value);
- if (typeof valid === `string`) {
- this.errorMsg = valid;
- valid = false;
- }
- this.error = !valid;
- }
- async submit() {
- this.value = this.value || this.initial;
- this.cursorOffset = 0;
- this.cursor = this.rendered.length;
- await this.validate();
- if (this.error) {
- this.red = true;
- this.fire();
- this.render();
- return;
- }
- this.done = true;
- this.aborted = false;
- this.fire();
- this.render();
- this.out.write('\n');
- this.close();
- }
- next() {
- if (!this.placeholder) return this.bell();
- this.value = this.initial;
- this.cursor = this.rendered.length;
- this.fire();
- this.render();
- }
- moveCursor(n) {
- if (this.placeholder) return;
- this.cursor = this.cursor+n;
- this.cursorOffset += n;
- }
- _(c, key) {
- let s1 = this.value.slice(0, this.cursor);
- let s2 = this.value.slice(this.cursor);
- this.value = `${s1}${c}${s2}`;
- this.red = false;
- this.cursor = this.placeholder ? 0 : s1.length+1;
- this.render();
- }
- delete() {
- if (this.isCursorAtStart()) return this.bell();
- let s1 = this.value.slice(0, this.cursor-1);
- let s2 = this.value.slice(this.cursor);
- this.value = `${s1}${s2}`;
- this.red = false;
- if (this.isCursorAtStart()) {
- this.cursorOffset = 0;
- } else {
- this.cursorOffset++;
- this.moveCursor(-1);
- }
- this.render();
- }
- deleteForward() {
- if(this.cursor*this.scale >= this.rendered.length || this.placeholder) return this.bell();
- let s1 = this.value.slice(0, this.cursor);
- let s2 = this.value.slice(this.cursor+1);
- this.value = `${s1}${s2}`;
- this.red = false;
- if (this.isCursorAtEnd()) {
- this.cursorOffset = 0;
- } else {
- this.cursorOffset++;
- }
- this.render();
- }
- first() {
- this.cursor = 0;
- this.render();
- }
- last() {
- this.cursor = this.value.length;
- this.render();
- }
- left() {
- if (this.cursor <= 0 || this.placeholder) return this.bell();
- this.moveCursor(-1);
- this.render();
- }
- right() {
- if (this.cursor*this.scale >= this.rendered.length || this.placeholder) return this.bell();
- this.moveCursor(1);
- this.render();
- }
- isCursorAtStart() {
- return this.cursor === 0 || (this.placeholder && this.cursor === 1);
- }
- isCursorAtEnd() {
- return this.cursor === this.rendered.length || (this.placeholder && this.cursor === this.rendered.length + 1)
- }
- render() {
- if (this.closed) return;
- if (!this.firstRender) {
- if (this.outputError)
- this.out.write(cursor.down(lines(this.outputError, this.out.columns) - 1) + clear(this.outputError, this.out.columns));
- this.out.write(clear(this.outputText, this.out.columns));
- }
- super.render();
- this.outputError = '';
- this.outputText = [
- style.symbol(this.done, this.aborted),
- color.bold(this.msg),
- style.delimiter(this.done),
- this.red ? color.red(this.rendered) : this.rendered
- ].join(` `);
- if (this.error) {
- this.outputError += this.errorMsg.split(`\n`)
- .reduce((a, l, i) => a + `\n${i ? ' ' : figures.pointerSmall} ${color.red().italic(l)}`, ``);
- }
- this.out.write(erase.line + cursor.to(0) + this.outputText + cursor.save + this.outputError + cursor.restore + cursor.move(this.cursorOffset, 0));
- }
- }
- text = TextPrompt;
- return text;
- }
- var select;
- var hasRequiredSelect;
- function requireSelect () {
- if (hasRequiredSelect) return select;
- hasRequiredSelect = 1;
- const color = requireKleur();
- const Prompt = requirePrompt();
- const { style, clear, figures, wrap, entriesToDisplay } = requireUtil();
- const { cursor } = requireSrc();
- /**
- * SelectPrompt Base Element
- * @param {Object} opts Options
- * @param {String} opts.message Message
- * @param {Array} opts.choices Array of choice objects
- * @param {String} [opts.hint] Hint to display
- * @param {Number} [opts.initial] Index of default value
- * @param {Stream} [opts.stdin] The Readable stream to listen to
- * @param {Stream} [opts.stdout] The Writable stream to write readline data to
- * @param {Number} [opts.optionsPerPage=10] Max options to display at once
- */
- class SelectPrompt extends Prompt {
- constructor(opts={}) {
- super(opts);
- this.msg = opts.message;
- this.hint = opts.hint || '- Use arrow-keys. Return to submit.';
- this.warn = opts.warn || '- This option is disabled';
- this.cursor = opts.initial || 0;
- this.choices = opts.choices.map((ch, idx) => {
- if (typeof ch === 'string')
- ch = {title: ch, value: idx};
- return {
- title: ch && (ch.title || ch.value || ch),
- value: ch && (ch.value === undefined ? idx : ch.value),
- description: ch && ch.description,
- selected: ch && ch.selected,
- disabled: ch && ch.disabled
- };
- });
- this.optionsPerPage = opts.optionsPerPage || 10;
- this.value = (this.choices[this.cursor] || {}).value;
- this.clear = clear('', this.out.columns);
- this.render();
- }
- moveCursor(n) {
- this.cursor = n;
- this.value = this.choices[n].value;
- this.fire();
- }
- reset() {
- this.moveCursor(0);
- this.fire();
- this.render();
- }
- exit() {
- this.abort();
- }
- abort() {
- this.done = this.aborted = true;
- this.fire();
- this.render();
- this.out.write('\n');
- this.close();
- }
- submit() {
- if (!this.selection.disabled) {
- this.done = true;
- this.aborted = false;
- this.fire();
- this.render();
- this.out.write('\n');
- this.close();
- } else
- this.bell();
- }
- first() {
- this.moveCursor(0);
- this.render();
- }
- last() {
- this.moveCursor(this.choices.length - 1);
- this.render();
- }
- up() {
- if (this.cursor === 0) {
- this.moveCursor(this.choices.length - 1);
- } else {
- this.moveCursor(this.cursor - 1);
- }
- this.render();
- }
- down() {
- if (this.cursor === this.choices.length - 1) {
- this.moveCursor(0);
- } else {
- this.moveCursor(this.cursor + 1);
- }
- this.render();
- }
- next() {
- this.moveCursor((this.cursor + 1) % this.choices.length);
- this.render();
- }
- _(c, key) {
- if (c === ' ') return this.submit();
- }
- get selection() {
- return this.choices[this.cursor];
- }
- render() {
- if (this.closed) return;
- if (this.firstRender) this.out.write(cursor.hide);
- else this.out.write(clear(this.outputText, this.out.columns));
- super.render();
- let { startIndex, endIndex } = entriesToDisplay(this.cursor, this.choices.length, this.optionsPerPage);
- // Print prompt
- this.outputText = [
- style.symbol(this.done, this.aborted),
- color.bold(this.msg),
- style.delimiter(false),
- this.done ? this.selection.title : this.selection.disabled
- ? color.yellow(this.warn) : color.gray(this.hint)
- ].join(' ');
- // Print choices
- if (!this.done) {
- this.outputText += '\n';
- for (let i = startIndex; i < endIndex; i++) {
- let title, prefix, desc = '', v = this.choices[i];
- // Determine whether to display "more choices" indicators
- if (i === startIndex && startIndex > 0) {
- prefix = figures.arrowUp;
- } else if (i === endIndex - 1 && endIndex < this.choices.length) {
- prefix = figures.arrowDown;
- } else {
- prefix = ' ';
- }
- if (v.disabled) {
- title = this.cursor === i ? color.gray().underline(v.title) : color.strikethrough().gray(v.title);
- prefix = (this.cursor === i ? color.bold().gray(figures.pointer) + ' ' : ' ') + prefix;
- } else {
- title = this.cursor === i ? color.cyan().underline(v.title) : v.title;
- prefix = (this.cursor === i ? color.cyan(figures.pointer) + ' ' : ' ') + prefix;
- if (v.description && this.cursor === i) {
- desc = ` - ${v.description}`;
- if (prefix.length + title.length + desc.length >= this.out.columns
- || v.description.split(/\r?\n/).length > 1) {
- desc = '\n' + wrap(v.description, { margin: 3, width: this.out.columns });
- }
- }
- }
- this.outputText += `${prefix} ${title}${color.gray(desc)}\n`;
- }
- }
- this.out.write(this.outputText);
- }
- }
- select = SelectPrompt;
- return select;
- }
- var toggle;
- var hasRequiredToggle;
- function requireToggle () {
- if (hasRequiredToggle) return toggle;
- hasRequiredToggle = 1;
- const color = requireKleur();
- const Prompt = requirePrompt();
- const { style, clear } = requireUtil();
- const { cursor, erase } = requireSrc();
- /**
- * TogglePrompt Base Element
- * @param {Object} opts Options
- * @param {String} opts.message Message
- * @param {Boolean} [opts.initial=false] Default value
- * @param {String} [opts.active='no'] Active label
- * @param {String} [opts.inactive='off'] Inactive label
- * @param {Stream} [opts.stdin] The Readable stream to listen to
- * @param {Stream} [opts.stdout] The Writable stream to write readline data to
- */
- class TogglePrompt extends Prompt {
- constructor(opts={}) {
- super(opts);
- this.msg = opts.message;
- this.value = !!opts.initial;
- this.active = opts.active || 'on';
- this.inactive = opts.inactive || 'off';
- this.initialValue = this.value;
- this.render();
- }
- reset() {
- this.value = this.initialValue;
- this.fire();
- this.render();
- }
- exit() {
- this.abort();
- }
- abort() {
- this.done = this.aborted = true;
- this.fire();
- this.render();
- this.out.write('\n');
- this.close();
- }
- submit() {
- this.done = true;
- this.aborted = false;
- this.fire();
- this.render();
- this.out.write('\n');
- this.close();
- }
- deactivate() {
- if (this.value === false) return this.bell();
- this.value = false;
- this.render();
- }
- activate() {
- if (this.value === true) return this.bell();
- this.value = true;
- this.render();
- }
- delete() {
- this.deactivate();
- }
- left() {
- this.deactivate();
- }
- right() {
- this.activate();
- }
- down() {
- this.deactivate();
- }
- up() {
- this.activate();
- }
- next() {
- this.value = !this.value;
- this.fire();
- this.render();
- }
- _(c, key) {
- if (c === ' ') {
- this.value = !this.value;
- } else if (c === '1') {
- this.value = true;
- } else if (c === '0') {
- this.value = false;
- } else return this.bell();
- this.render();
- }
- render() {
- if (this.closed) return;
- if (this.firstRender) this.out.write(cursor.hide);
- else this.out.write(clear(this.outputText, this.out.columns));
- super.render();
- this.outputText = [
- style.symbol(this.done, this.aborted),
- color.bold(this.msg),
- style.delimiter(this.done),
- this.value ? this.inactive : color.cyan().underline(this.inactive),
- color.gray('/'),
- this.value ? color.cyan().underline(this.active) : this.active
- ].join(' ');
- this.out.write(erase.line + cursor.to(0) + this.outputText);
- }
- }
- toggle = TogglePrompt;
- return toggle;
- }
- var datepart;
- var hasRequiredDatepart;
- function requireDatepart () {
- if (hasRequiredDatepart) return datepart;
- hasRequiredDatepart = 1;
- class DatePart {
- constructor({token, date, parts, locales}) {
- this.token = token;
- this.date = date || new Date();
- this.parts = parts || [this];
- this.locales = locales || {};
- }
- up() {}
- down() {}
- next() {
- const currentIdx = this.parts.indexOf(this);
- return this.parts.find((part, idx) => idx > currentIdx && part instanceof DatePart);
- }
- setTo(val) {}
- prev() {
- let parts = [].concat(this.parts).reverse();
- const currentIdx = parts.indexOf(this);
- return parts.find((part, idx) => idx > currentIdx && part instanceof DatePart);
- }
- toString() {
- return String(this.date);
- }
- }
- datepart = DatePart;
- return datepart;
- }
- var meridiem;
- var hasRequiredMeridiem;
- function requireMeridiem () {
- if (hasRequiredMeridiem) return meridiem;
- hasRequiredMeridiem = 1;
- const DatePart = requireDatepart();
- class Meridiem extends DatePart {
- constructor(opts={}) {
- super(opts);
- }
- up() {
- this.date.setHours((this.date.getHours() + 12) % 24);
- }
- down() {
- this.up();
- }
- toString() {
- let meridiem = this.date.getHours() > 12 ? 'pm' : 'am';
- return /\A/.test(this.token) ? meridiem.toUpperCase() : meridiem;
- }
- }
- meridiem = Meridiem;
- return meridiem;
- }
- var day;
- var hasRequiredDay;
- function requireDay () {
- if (hasRequiredDay) return day;
- hasRequiredDay = 1;
- const DatePart = requireDatepart();
- const pos = n => {
- n = n % 10;
- return n === 1 ? 'st'
- : n === 2 ? 'nd'
- : n === 3 ? 'rd'
- : 'th';
- };
- class Day extends DatePart {
- constructor(opts={}) {
- super(opts);
- }
- up() {
- this.date.setDate(this.date.getDate() + 1);
- }
- down() {
- this.date.setDate(this.date.getDate() - 1);
- }
- setTo(val) {
- this.date.setDate(parseInt(val.substr(-2)));
- }
- toString() {
- let date = this.date.getDate();
- let day = this.date.getDay();
- return this.token === 'DD' ? String(date).padStart(2, '0')
- : this.token === 'Do' ? date + pos(date)
- : this.token === 'd' ? day + 1
- : this.token === 'ddd' ? this.locales.weekdaysShort[day]
- : this.token === 'dddd' ? this.locales.weekdays[day]
- : date;
- }
- }
- day = Day;
- return day;
- }
- var hours;
- var hasRequiredHours;
- function requireHours () {
- if (hasRequiredHours) return hours;
- hasRequiredHours = 1;
- const DatePart = requireDatepart();
- class Hours extends DatePart {
- constructor(opts={}) {
- super(opts);
- }
- up() {
- this.date.setHours(this.date.getHours() + 1);
- }
- down() {
- this.date.setHours(this.date.getHours() - 1);
- }
- setTo(val) {
- this.date.setHours(parseInt(val.substr(-2)));
- }
- toString() {
- let hours = this.date.getHours();
- if (/h/.test(this.token))
- hours = (hours % 12) || 12;
- return this.token.length > 1 ? String(hours).padStart(2, '0') : hours;
- }
- }
- hours = Hours;
- return hours;
- }
- var milliseconds;
- var hasRequiredMilliseconds;
- function requireMilliseconds () {
- if (hasRequiredMilliseconds) return milliseconds;
- hasRequiredMilliseconds = 1;
- const DatePart = requireDatepart();
- class Milliseconds extends DatePart {
- constructor(opts={}) {
- super(opts);
- }
- up() {
- this.date.setMilliseconds(this.date.getMilliseconds() + 1);
- }
- down() {
- this.date.setMilliseconds(this.date.getMilliseconds() - 1);
- }
- setTo(val) {
- this.date.setMilliseconds(parseInt(val.substr(-(this.token.length))));
- }
- toString() {
- return String(this.date.getMilliseconds()).padStart(4, '0')
- .substr(0, this.token.length);
- }
- }
- milliseconds = Milliseconds;
- return milliseconds;
- }
- var minutes;
- var hasRequiredMinutes;
- function requireMinutes () {
- if (hasRequiredMinutes) return minutes;
- hasRequiredMinutes = 1;
- const DatePart = requireDatepart();
- class Minutes extends DatePart {
- constructor(opts={}) {
- super(opts);
- }
- up() {
- this.date.setMinutes(this.date.getMinutes() + 1);
- }
- down() {
- this.date.setMinutes(this.date.getMinutes() - 1);
- }
- setTo(val) {
- this.date.setMinutes(parseInt(val.substr(-2)));
- }
- toString() {
- let m = this.date.getMinutes();
- return this.token.length > 1 ? String(m).padStart(2, '0') : m;
- }
- }
- minutes = Minutes;
- return minutes;
- }
- var month;
- var hasRequiredMonth;
- function requireMonth () {
- if (hasRequiredMonth) return month;
- hasRequiredMonth = 1;
- const DatePart = requireDatepart();
- class Month extends DatePart {
- constructor(opts={}) {
- super(opts);
- }
- up() {
- this.date.setMonth(this.date.getMonth() + 1);
- }
- down() {
- this.date.setMonth(this.date.getMonth() - 1);
- }
- setTo(val) {
- val = parseInt(val.substr(-2)) - 1;
- this.date.setMonth(val < 0 ? 0 : val);
- }
- toString() {
- let month = this.date.getMonth();
- let tl = this.token.length;
- return tl === 2 ? String(month + 1).padStart(2, '0')
- : tl === 3 ? this.locales.monthsShort[month]
- : tl === 4 ? this.locales.months[month]
- : String(month + 1);
- }
- }
- month = Month;
- return month;
- }
- var seconds;
- var hasRequiredSeconds;
- function requireSeconds () {
- if (hasRequiredSeconds) return seconds;
- hasRequiredSeconds = 1;
- const DatePart = requireDatepart();
- class Seconds extends DatePart {
- constructor(opts={}) {
- super(opts);
- }
- up() {
- this.date.setSeconds(this.date.getSeconds() + 1);
- }
- down() {
- this.date.setSeconds(this.date.getSeconds() - 1);
- }
- setTo(val) {
- this.date.setSeconds(parseInt(val.substr(-2)));
- }
- toString() {
- let s = this.date.getSeconds();
- return this.token.length > 1 ? String(s).padStart(2, '0') : s;
- }
- }
- seconds = Seconds;
- return seconds;
- }
- var year;
- var hasRequiredYear;
- function requireYear () {
- if (hasRequiredYear) return year;
- hasRequiredYear = 1;
- const DatePart = requireDatepart();
- class Year extends DatePart {
- constructor(opts={}) {
- super(opts);
- }
- up() {
- this.date.setFullYear(this.date.getFullYear() + 1);
- }
- down() {
- this.date.setFullYear(this.date.getFullYear() - 1);
- }
- setTo(val) {
- this.date.setFullYear(val.substr(-4));
- }
- toString() {
- let year = String(this.date.getFullYear()).padStart(4, '0');
- return this.token.length === 2 ? year.substr(-2) : year;
- }
- }
- year = Year;
- return year;
- }
- var dateparts;
- var hasRequiredDateparts;
- function requireDateparts () {
- if (hasRequiredDateparts) return dateparts;
- hasRequiredDateparts = 1;
- dateparts = {
- DatePart: requireDatepart(),
- Meridiem: requireMeridiem(),
- Day: requireDay(),
- Hours: requireHours(),
- Milliseconds: requireMilliseconds(),
- Minutes: requireMinutes(),
- Month: requireMonth(),
- Seconds: requireSeconds(),
- Year: requireYear(),
- };
- return dateparts;
- }
- var date;
- var hasRequiredDate;
- function requireDate () {
- if (hasRequiredDate) return date;
- hasRequiredDate = 1;
- const color = requireKleur();
- const Prompt = requirePrompt();
- const { style, clear, figures } = requireUtil();
- const { erase, cursor } = requireSrc();
- const { DatePart, Meridiem, Day, Hours, Milliseconds, Minutes, Month, Seconds, Year } = requireDateparts();
- const regex = /\\(.)|"((?:\\["\\]|[^"])+)"|(D[Do]?|d{3,4}|d)|(M{1,4})|(YY(?:YY)?)|([aA])|([Hh]{1,2})|(m{1,2})|(s{1,2})|(S{1,4})|./g;
- const regexGroups = {
- 1: ({token}) => token.replace(/\\(.)/g, '$1'),
- 2: (opts) => new Day(opts), // Day // TODO
- 3: (opts) => new Month(opts), // Month
- 4: (opts) => new Year(opts), // Year
- 5: (opts) => new Meridiem(opts), // AM/PM // TODO (special)
- 6: (opts) => new Hours(opts), // Hours
- 7: (opts) => new Minutes(opts), // Minutes
- 8: (opts) => new Seconds(opts), // Seconds
- 9: (opts) => new Milliseconds(opts), // Fractional seconds
- };
- const dfltLocales = {
- months: 'January,February,March,April,May,June,July,August,September,October,November,December'.split(','),
- monthsShort: 'Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec'.split(','),
- weekdays: 'Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday'.split(','),
- weekdaysShort: 'Sun,Mon,Tue,Wed,Thu,Fri,Sat'.split(',')
- };
- /**
- * DatePrompt Base Element
- * @param {Object} opts Options
- * @param {String} opts.message Message
- * @param {Number} [opts.initial] Index of default value
- * @param {String} [opts.mask] The format mask
- * @param {object} [opts.locales] The date locales
- * @param {String} [opts.error] The error message shown on invalid value
- * @param {Function} [opts.validate] Function to validate the submitted value
- * @param {Stream} [opts.stdin] The Readable stream to listen to
- * @param {Stream} [opts.stdout] The Writable stream to write readline data to
- */
- class DatePrompt extends Prompt {
- constructor(opts={}) {
- super(opts);
- this.msg = opts.message;
- this.cursor = 0;
- this.typed = '';
- this.locales = Object.assign(dfltLocales, opts.locales);
- this._date = opts.initial || new Date();
- this.errorMsg = opts.error || 'Please Enter A Valid Value';
- this.validator = opts.validate || (() => true);
- this.mask = opts.mask || 'YYYY-MM-DD HH:mm:ss';
- this.clear = clear('', this.out.columns);
- this.render();
- }
- get value() {
- return this.date
- }
- get date() {
- return this._date;
- }
- set date(date) {
- if (date) this._date.setTime(date.getTime());
- }
- set mask(mask) {
- let result;
- this.parts = [];
- while(result = regex.exec(mask)) {
- let match = result.shift();
- let idx = result.findIndex(gr => gr != null);
- this.parts.push(idx in regexGroups
- ? regexGroups[idx]({ token: result[idx] || match, date: this.date, parts: this.parts, locales: this.locales })
- : result[idx] || match);
- }
- let parts = this.parts.reduce((arr, i) => {
- if (typeof i === 'string' && typeof arr[arr.length - 1] === 'string')
- arr[arr.length - 1] += i;
- else arr.push(i);
- return arr;
- }, []);
- this.parts.splice(0);
- this.parts.push(...parts);
- this.reset();
- }
- moveCursor(n) {
- this.typed = '';
- this.cursor = n;
- this.fire();
- }
- reset() {
- this.moveCursor(this.parts.findIndex(p => p instanceof DatePart));
- this.fire();
- this.render();
- }
- exit() {
- this.abort();
- }
- abort() {
- this.done = this.aborted = true;
- this.error = false;
- this.fire();
- this.render();
- this.out.write('\n');
- this.close();
- }
- async validate() {
- let valid = await this.validator(this.value);
- if (typeof valid === 'string') {
- this.errorMsg = valid;
- valid = false;
- }
- this.error = !valid;
- }
- async submit() {
- await this.validate();
- if (this.error) {
- this.color = 'red';
- this.fire();
- this.render();
- return;
- }
- this.done = true;
- this.aborted = false;
- this.fire();
- this.render();
- this.out.write('\n');
- this.close();
- }
- up() {
- this.typed = '';
- this.parts[this.cursor].up();
- this.render();
- }
- down() {
- this.typed = '';
- this.parts[this.cursor].down();
- this.render();
- }
- left() {
- let prev = this.parts[this.cursor].prev();
- if (prev == null) return this.bell();
- this.moveCursor(this.parts.indexOf(prev));
- this.render();
- }
- right() {
- let next = this.parts[this.cursor].next();
- if (next == null) return this.bell();
- this.moveCursor(this.parts.indexOf(next));
- this.render();
- }
- next() {
- let next = this.parts[this.cursor].next();
- this.moveCursor(next
- ? this.parts.indexOf(next)
- : this.parts.findIndex((part) => part instanceof DatePart));
- this.render();
- }
- _(c) {
- if (/\d/.test(c)) {
- this.typed += c;
- this.parts[this.cursor].setTo(this.typed);
- this.render();
- }
- }
- render() {
- if (this.closed) return;
- if (this.firstRender) this.out.write(cursor.hide);
- else this.out.write(clear(this.outputText, this.out.columns));
- super.render();
- // Print prompt
- this.outputText = [
- style.symbol(this.done, this.aborted),
- color.bold(this.msg),
- style.delimiter(false),
- this.parts.reduce((arr, p, idx) => arr.concat(idx === this.cursor && !this.done ? color.cyan().underline(p.toString()) : p), [])
- .join('')
- ].join(' ');
- // Print error
- if (this.error) {
- this.outputText += this.errorMsg.split('\n').reduce(
- (a, l, i) => a + `\n${i ? ` ` : figures.pointerSmall} ${color.red().italic(l)}`, ``);
- }
- this.out.write(erase.line + cursor.to(0) + this.outputText);
- }
- }
- date = DatePrompt;
- return date;
- }
- var number;
- var hasRequiredNumber;
- function requireNumber () {
- if (hasRequiredNumber) return number;
- hasRequiredNumber = 1;
- const color = requireKleur();
- const Prompt = requirePrompt();
- const { cursor, erase } = requireSrc();
- const { style, figures, clear, lines } = requireUtil();
- const isNumber = /[0-9]/;
- const isDef = any => any !== undefined;
- const round = (number, precision) => {
- let factor = Math.pow(10, precision);
- return Math.round(number * factor) / factor;
- };
- /**
- * NumberPrompt Base Element
- * @param {Object} opts Options
- * @param {String} opts.message Message
- * @param {String} [opts.style='default'] Render style
- * @param {Number} [opts.initial] Default value
- * @param {Number} [opts.max=+Infinity] Max value
- * @param {Number} [opts.min=-Infinity] Min value
- * @param {Boolean} [opts.float=false] Parse input as floats
- * @param {Number} [opts.round=2] Round floats to x decimals
- * @param {Number} [opts.increment=1] Number to increment by when using arrow-keys
- * @param {Function} [opts.validate] Validate function
- * @param {Stream} [opts.stdin] The Readable stream to listen to
- * @param {Stream} [opts.stdout] The Writable stream to write readline data to
- * @param {String} [opts.error] The invalid error label
- */
- class NumberPrompt extends Prompt {
- constructor(opts={}) {
- super(opts);
- this.transform = style.render(opts.style);
- this.msg = opts.message;
- this.initial = isDef(opts.initial) ? opts.initial : '';
- this.float = !!opts.float;
- this.round = opts.round || 2;
- this.inc = opts.increment || 1;
- this.min = isDef(opts.min) ? opts.min : -Infinity;
- this.max = isDef(opts.max) ? opts.max : Infinity;
- this.errorMsg = opts.error || `Please Enter A Valid Value`;
- this.validator = opts.validate || (() => true);
- this.color = `cyan`;
- this.value = ``;
- this.typed = ``;
- this.lastHit = 0;
- this.render();
- }
- set value(v) {
- if (!v && v !== 0) {
- this.placeholder = true;
- this.rendered = color.gray(this.transform.render(`${this.initial}`));
- this._value = ``;
- } else {
- this.placeholder = false;
- this.rendered = this.transform.render(`${round(v, this.round)}`);
- this._value = round(v, this.round);
- }
- this.fire();
- }
- get value() {
- return this._value;
- }
- parse(x) {
- return this.float ? parseFloat(x) : parseInt(x);
- }
- valid(c) {
- return c === `-` || c === `.` && this.float || isNumber.test(c)
- }
- reset() {
- this.typed = ``;
- this.value = ``;
- this.fire();
- this.render();
- }
- exit() {
- this.abort();
- }
- abort() {
- let x = this.value;
- this.value = x !== `` ? x : this.initial;
- this.done = this.aborted = true;
- this.error = false;
- this.fire();
- this.render();
- this.out.write(`\n`);
- this.close();
- }
- async validate() {
- let valid = await this.validator(this.value);
- if (typeof valid === `string`) {
- this.errorMsg = valid;
- valid = false;
- }
- this.error = !valid;
- }
- async submit() {
- await this.validate();
- if (this.error) {
- this.color = `red`;
- this.fire();
- this.render();
- return;
- }
- let x = this.value;
- this.value = x !== `` ? x : this.initial;
- this.done = true;
- this.aborted = false;
- this.error = false;
- this.fire();
- this.render();
- this.out.write(`\n`);
- this.close();
- }
- up() {
- this.typed = ``;
- if(this.value === '') {
- this.value = this.min - this.inc;
- }
- if (this.value >= this.max) return this.bell();
- this.value += this.inc;
- this.color = `cyan`;
- this.fire();
- this.render();
- }
- down() {
- this.typed = ``;
- if(this.value === '') {
- this.value = this.min + this.inc;
- }
- if (this.value <= this.min) return this.bell();
- this.value -= this.inc;
- this.color = `cyan`;
- this.fire();
- this.render();
- }
- delete() {
- let val = this.value.toString();
- if (val.length === 0) return this.bell();
- this.value = this.parse((val = val.slice(0, -1))) || ``;
- if (this.value !== '' && this.value < this.min) {
- this.value = this.min;
- }
- this.color = `cyan`;
- this.fire();
- this.render();
- }
- next() {
- this.value = this.initial;
- this.fire();
- this.render();
- }
- _(c, key) {
- if (!this.valid(c)) return this.bell();
- const now = Date.now();
- if (now - this.lastHit > 1000) this.typed = ``; // 1s elapsed
- this.typed += c;
- this.lastHit = now;
- this.color = `cyan`;
- if (c === `.`) return this.fire();
- this.value = Math.min(this.parse(this.typed), this.max);
- if (this.value > this.max) this.value = this.max;
- if (this.value < this.min) this.value = this.min;
- this.fire();
- this.render();
- }
- render() {
- if (this.closed) return;
- if (!this.firstRender) {
- if (this.outputError)
- this.out.write(cursor.down(lines(this.outputError, this.out.columns) - 1) + clear(this.outputError, this.out.columns));
- this.out.write(clear(this.outputText, this.out.columns));
- }
- super.render();
- this.outputError = '';
- // Print prompt
- this.outputText = [
- style.symbol(this.done, this.aborted),
- color.bold(this.msg),
- style.delimiter(this.done),
- !this.done || (!this.done && !this.placeholder)
- ? color[this.color]().underline(this.rendered) : this.rendered
- ].join(` `);
- // Print error
- if (this.error) {
- this.outputError += this.errorMsg.split(`\n`)
- .reduce((a, l, i) => a + `\n${i ? ` ` : figures.pointerSmall} ${color.red().italic(l)}`, ``);
- }
- this.out.write(erase.line + cursor.to(0) + this.outputText + cursor.save + this.outputError + cursor.restore);
- }
- }
- number = NumberPrompt;
- return number;
- }
- var multiselect;
- var hasRequiredMultiselect;
- function requireMultiselect () {
- if (hasRequiredMultiselect) return multiselect;
- hasRequiredMultiselect = 1;
- const color = requireKleur();
- const { cursor } = requireSrc();
- const Prompt = requirePrompt();
- const { clear, figures, style, wrap, entriesToDisplay } = requireUtil();
- /**
- * MultiselectPrompt Base Element
- * @param {Object} opts Options
- * @param {String} opts.message Message
- * @param {Array} opts.choices Array of choice objects
- * @param {String} [opts.hint] Hint to display
- * @param {String} [opts.warn] Hint shown for disabled choices
- * @param {Number} [opts.max] Max choices
- * @param {Number} [opts.cursor=0] Cursor start position
- * @param {Number} [opts.optionsPerPage=10] Max options to display at once
- * @param {Stream} [opts.stdin] The Readable stream to listen to
- * @param {Stream} [opts.stdout] The Writable stream to write readline data to
- */
- class MultiselectPrompt extends Prompt {
- constructor(opts={}) {
- super(opts);
- this.msg = opts.message;
- this.cursor = opts.cursor || 0;
- this.scrollIndex = opts.cursor || 0;
- this.hint = opts.hint || '';
- this.warn = opts.warn || '- This option is disabled -';
- this.minSelected = opts.min;
- this.showMinError = false;
- this.maxChoices = opts.max;
- this.instructions = opts.instructions;
- this.optionsPerPage = opts.optionsPerPage || 10;
- this.value = opts.choices.map((ch, idx) => {
- if (typeof ch === 'string')
- ch = {title: ch, value: idx};
- return {
- title: ch && (ch.title || ch.value || ch),
- description: ch && ch.description,
- value: ch && (ch.value === undefined ? idx : ch.value),
- selected: ch && ch.selected,
- disabled: ch && ch.disabled
- };
- });
- this.clear = clear('', this.out.columns);
- if (!opts.overrideRender) {
- this.render();
- }
- }
- reset() {
- this.value.map(v => !v.selected);
- this.cursor = 0;
- this.fire();
- this.render();
- }
- selected() {
- return this.value.filter(v => v.selected);
- }
- exit() {
- this.abort();
- }
- abort() {
- this.done = this.aborted = true;
- this.fire();
- this.render();
- this.out.write('\n');
- this.close();
- }
- submit() {
- const selected = this.value
- .filter(e => e.selected);
- if (this.minSelected && selected.length < this.minSelected) {
- this.showMinError = true;
- this.render();
- } else {
- this.done = true;
- this.aborted = false;
- this.fire();
- this.render();
- this.out.write('\n');
- this.close();
- }
- }
- first() {
- this.cursor = 0;
- this.render();
- }
- last() {
- this.cursor = this.value.length - 1;
- this.render();
- }
- next() {
- this.cursor = (this.cursor + 1) % this.value.length;
- this.render();
- }
- up() {
- if (this.cursor === 0) {
- this.cursor = this.value.length - 1;
- } else {
- this.cursor--;
- }
- this.render();
- }
- down() {
- if (this.cursor === this.value.length - 1) {
- this.cursor = 0;
- } else {
- this.cursor++;
- }
- this.render();
- }
- left() {
- this.value[this.cursor].selected = false;
- this.render();
- }
- right() {
- if (this.value.filter(e => e.selected).length >= this.maxChoices) return this.bell();
- this.value[this.cursor].selected = true;
- this.render();
- }
- handleSpaceToggle() {
- const v = this.value[this.cursor];
- if (v.selected) {
- v.selected = false;
- this.render();
- } else if (v.disabled || this.value.filter(e => e.selected).length >= this.maxChoices) {
- return this.bell();
- } else {
- v.selected = true;
- this.render();
- }
- }
- toggleAll() {
- if (this.maxChoices !== undefined || this.value[this.cursor].disabled) {
- return this.bell();
- }
- const newSelected = !this.value[this.cursor].selected;
- this.value.filter(v => !v.disabled).forEach(v => v.selected = newSelected);
- this.render();
- }
- _(c, key) {
- if (c === ' ') {
- this.handleSpaceToggle();
- } else if (c === 'a') {
- this.toggleAll();
- } else {
- return this.bell();
- }
- }
- renderInstructions() {
- if (this.instructions === undefined || this.instructions) {
- if (typeof this.instructions === 'string') {
- return this.instructions;
- }
- return '\nInstructions:\n'
- + ` ${figures.arrowUp}/${figures.arrowDown}: Highlight option\n`
- + ` ${figures.arrowLeft}/${figures.arrowRight}/[space]: Toggle selection\n`
- + (this.maxChoices === undefined ? ` a: Toggle all\n` : '')
- + ` enter/return: Complete answer`;
- }
- return '';
- }
- renderOption(cursor, v, i, arrowIndicator) {
- const prefix = (v.selected ? color.green(figures.radioOn) : figures.radioOff) + ' ' + arrowIndicator + ' ';
- let title, desc;
- if (v.disabled) {
- title = cursor === i ? color.gray().underline(v.title) : color.strikethrough().gray(v.title);
- } else {
- title = cursor === i ? color.cyan().underline(v.title) : v.title;
- if (cursor === i && v.description) {
- desc = ` - ${v.description}`;
- if (prefix.length + title.length + desc.length >= this.out.columns
- || v.description.split(/\r?\n/).length > 1) {
- desc = '\n' + wrap(v.description, { margin: prefix.length, width: this.out.columns });
- }
- }
- }
- return prefix + title + color.gray(desc || '');
- }
- // shared with autocompleteMultiselect
- paginateOptions(options) {
- if (options.length === 0) {
- return color.red('No matches for this query.');
- }
- let { startIndex, endIndex } = entriesToDisplay(this.cursor, options.length, this.optionsPerPage);
- let prefix, styledOptions = [];
- for (let i = startIndex; i < endIndex; i++) {
- if (i === startIndex && startIndex > 0) {
- prefix = figures.arrowUp;
- } else if (i === endIndex - 1 && endIndex < options.length) {
- prefix = figures.arrowDown;
- } else {
- prefix = ' ';
- }
- styledOptions.push(this.renderOption(this.cursor, options[i], i, prefix));
- }
- return '\n' + styledOptions.join('\n');
- }
- // shared with autocomleteMultiselect
- renderOptions(options) {
- if (!this.done) {
- return this.paginateOptions(options);
- }
- return '';
- }
- renderDoneOrInstructions() {
- if (this.done) {
- return this.value
- .filter(e => e.selected)
- .map(v => v.title)
- .join(', ');
- }
- const output = [color.gray(this.hint), this.renderInstructions()];
- if (this.value[this.cursor].disabled) {
- output.push(color.yellow(this.warn));
- }
- return output.join(' ');
- }
- render() {
- if (this.closed) return;
- if (this.firstRender) this.out.write(cursor.hide);
- super.render();
- // print prompt
- let prompt = [
- style.symbol(this.done, this.aborted),
- color.bold(this.msg),
- style.delimiter(false),
- this.renderDoneOrInstructions()
- ].join(' ');
- if (this.showMinError) {
- prompt += color.red(`You must select a minimum of ${this.minSelected} choices.`);
- this.showMinError = false;
- }
- prompt += this.renderOptions(this.value);
- this.out.write(this.clear + prompt);
- this.clear = clear(prompt, this.out.columns);
- }
- }
- multiselect = MultiselectPrompt;
- return multiselect;
- }
- var autocomplete;
- var hasRequiredAutocomplete;
- function requireAutocomplete () {
- if (hasRequiredAutocomplete) return autocomplete;
- hasRequiredAutocomplete = 1;
- const color = requireKleur();
- const Prompt = requirePrompt();
- const { erase, cursor } = requireSrc();
- const { style, clear, figures, wrap, entriesToDisplay } = requireUtil();
- const getVal = (arr, i) => arr[i] && (arr[i].value || arr[i].title || arr[i]);
- const getTitle = (arr, i) => arr[i] && (arr[i].title || arr[i].value || arr[i]);
- const getIndex = (arr, valOrTitle) => {
- const index = arr.findIndex(el => el.value === valOrTitle || el.title === valOrTitle);
- return index > -1 ? index : undefined;
- };
- /**
- * TextPrompt Base Element
- * @param {Object} opts Options
- * @param {String} opts.message Message
- * @param {Array} opts.choices Array of auto-complete choices objects
- * @param {Function} [opts.suggest] Filter function. Defaults to sort by title
- * @param {Number} [opts.limit=10] Max number of results to show
- * @param {Number} [opts.cursor=0] Cursor start position
- * @param {String} [opts.style='default'] Render style
- * @param {String} [opts.fallback] Fallback message - initial to default value
- * @param {String} [opts.initial] Index of the default value
- * @param {Boolean} [opts.clearFirst] The first ESCAPE keypress will clear the input
- * @param {Stream} [opts.stdin] The Readable stream to listen to
- * @param {Stream} [opts.stdout] The Writable stream to write readline data to
- * @param {String} [opts.noMatches] The no matches found label
- */
- class AutocompletePrompt extends Prompt {
- constructor(opts={}) {
- super(opts);
- this.msg = opts.message;
- this.suggest = opts.suggest;
- this.choices = opts.choices;
- this.initial = typeof opts.initial === 'number'
- ? opts.initial
- : getIndex(opts.choices, opts.initial);
- this.select = this.initial || opts.cursor || 0;
- this.i18n = { noMatches: opts.noMatches || 'no matches found' };
- this.fallback = opts.fallback || this.initial;
- this.clearFirst = opts.clearFirst || false;
- this.suggestions = [];
- this.input = '';
- this.limit = opts.limit || 10;
- this.cursor = 0;
- this.transform = style.render(opts.style);
- this.scale = this.transform.scale;
- this.render = this.render.bind(this);
- this.complete = this.complete.bind(this);
- this.clear = clear('', this.out.columns);
- this.complete(this.render);
- this.render();
- }
- set fallback(fb) {
- this._fb = Number.isSafeInteger(parseInt(fb)) ? parseInt(fb) : fb;
- }
- get fallback() {
- let choice;
- if (typeof this._fb === 'number')
- choice = this.choices[this._fb];
- else if (typeof this._fb === 'string')
- choice = { title: this._fb };
- return choice || this._fb || { title: this.i18n.noMatches };
- }
- moveSelect(i) {
- this.select = i;
- if (this.suggestions.length > 0)
- this.value = getVal(this.suggestions, i);
- else this.value = this.fallback.value;
- this.fire();
- }
- async complete(cb) {
- const p = (this.completing = this.suggest(this.input, this.choices));
- const suggestions = await p;
- if (this.completing !== p) return;
- this.suggestions = suggestions
- .map((s, i, arr) => ({ title: getTitle(arr, i), value: getVal(arr, i), description: s.description }));
- this.completing = false;
- const l = Math.max(suggestions.length - 1, 0);
- this.moveSelect(Math.min(l, this.select));
- cb && cb();
- }
- reset() {
- this.input = '';
- this.complete(() => {
- this.moveSelect(this.initial !== void 0 ? this.initial : 0);
- this.render();
- });
- this.render();
- }
- exit() {
- if (this.clearFirst && this.input.length > 0) {
- this.reset();
- } else {
- this.done = this.exited = true;
- this.aborted = false;
- this.fire();
- this.render();
- this.out.write('\n');
- this.close();
- }
- }
- abort() {
- this.done = this.aborted = true;
- this.exited = false;
- this.fire();
- this.render();
- this.out.write('\n');
- this.close();
- }
- submit() {
- this.done = true;
- this.aborted = this.exited = false;
- this.fire();
- this.render();
- this.out.write('\n');
- this.close();
- }
- _(c, key) {
- let s1 = this.input.slice(0, this.cursor);
- let s2 = this.input.slice(this.cursor);
- this.input = `${s1}${c}${s2}`;
- this.cursor = s1.length+1;
- this.complete(this.render);
- this.render();
- }
- delete() {
- if (this.cursor === 0) return this.bell();
- let s1 = this.input.slice(0, this.cursor-1);
- let s2 = this.input.slice(this.cursor);
- this.input = `${s1}${s2}`;
- this.complete(this.render);
- this.cursor = this.cursor-1;
- this.render();
- }
- deleteForward() {
- if(this.cursor*this.scale >= this.rendered.length) return this.bell();
- let s1 = this.input.slice(0, this.cursor);
- let s2 = this.input.slice(this.cursor+1);
- this.input = `${s1}${s2}`;
- this.complete(this.render);
- this.render();
- }
- first() {
- this.moveSelect(0);
- this.render();
- }
- last() {
- this.moveSelect(this.suggestions.length - 1);
- this.render();
- }
- up() {
- if (this.select === 0) {
- this.moveSelect(this.suggestions.length - 1);
- } else {
- this.moveSelect(this.select - 1);
- }
- this.render();
- }
- down() {
- if (this.select === this.suggestions.length - 1) {
- this.moveSelect(0);
- } else {
- this.moveSelect(this.select + 1);
- }
- this.render();
- }
- next() {
- if (this.select === this.suggestions.length - 1) {
- this.moveSelect(0);
- } else this.moveSelect(this.select + 1);
- this.render();
- }
- nextPage() {
- this.moveSelect(Math.min(this.select + this.limit, this.suggestions.length - 1));
- this.render();
- }
- prevPage() {
- this.moveSelect(Math.max(this.select - this.limit, 0));
- this.render();
- }
- left() {
- if (this.cursor <= 0) return this.bell();
- this.cursor = this.cursor-1;
- this.render();
- }
- right() {
- if (this.cursor*this.scale >= this.rendered.length) return this.bell();
- this.cursor = this.cursor+1;
- this.render();
- }
- renderOption(v, hovered, isStart, isEnd) {
- let desc;
- let prefix = isStart ? figures.arrowUp : isEnd ? figures.arrowDown : ' ';
- let title = hovered ? color.cyan().underline(v.title) : v.title;
- prefix = (hovered ? color.cyan(figures.pointer) + ' ' : ' ') + prefix;
- if (v.description) {
- desc = ` - ${v.description}`;
- if (prefix.length + title.length + desc.length >= this.out.columns
- || v.description.split(/\r?\n/).length > 1) {
- desc = '\n' + wrap(v.description, { margin: 3, width: this.out.columns });
- }
- }
- return prefix + ' ' + title + color.gray(desc || '');
- }
- render() {
- if (this.closed) return;
- if (this.firstRender) this.out.write(cursor.hide);
- else this.out.write(clear(this.outputText, this.out.columns));
- super.render();
- let { startIndex, endIndex } = entriesToDisplay(this.select, this.choices.length, this.limit);
- this.outputText = [
- style.symbol(this.done, this.aborted, this.exited),
- color.bold(this.msg),
- style.delimiter(this.completing),
- this.done && this.suggestions[this.select]
- ? this.suggestions[this.select].title
- : this.rendered = this.transform.render(this.input)
- ].join(' ');
- if (!this.done) {
- const suggestions = this.suggestions
- .slice(startIndex, endIndex)
- .map((item, i) => this.renderOption(item,
- this.select === i + startIndex,
- i === 0 && startIndex > 0,
- i + startIndex === endIndex - 1 && endIndex < this.choices.length))
- .join('\n');
- this.outputText += `\n` + (suggestions || color.gray(this.fallback.title));
- }
- this.out.write(erase.line + cursor.to(0) + this.outputText);
- }
- }
- autocomplete = AutocompletePrompt;
- return autocomplete;
- }
- var autocompleteMultiselect;
- var hasRequiredAutocompleteMultiselect;
- function requireAutocompleteMultiselect () {
- if (hasRequiredAutocompleteMultiselect) return autocompleteMultiselect;
- hasRequiredAutocompleteMultiselect = 1;
- const color = requireKleur();
- const { cursor } = requireSrc();
- const MultiselectPrompt = requireMultiselect();
- const { clear, style, figures } = requireUtil();
- /**
- * MultiselectPrompt Base Element
- * @param {Object} opts Options
- * @param {String} opts.message Message
- * @param {Array} opts.choices Array of choice objects
- * @param {String} [opts.hint] Hint to display
- * @param {String} [opts.warn] Hint shown for disabled choices
- * @param {Number} [opts.max] Max choices
- * @param {Number} [opts.cursor=0] Cursor start position
- * @param {Stream} [opts.stdin] The Readable stream to listen to
- * @param {Stream} [opts.stdout] The Writable stream to write readline data to
- */
- class AutocompleteMultiselectPrompt extends MultiselectPrompt {
- constructor(opts={}) {
- opts.overrideRender = true;
- super(opts);
- this.inputValue = '';
- this.clear = clear('', this.out.columns);
- this.filteredOptions = this.value;
- this.render();
- }
- last() {
- this.cursor = this.filteredOptions.length - 1;
- this.render();
- }
- next() {
- this.cursor = (this.cursor + 1) % this.filteredOptions.length;
- this.render();
- }
- up() {
- if (this.cursor === 0) {
- this.cursor = this.filteredOptions.length - 1;
- } else {
- this.cursor--;
- }
- this.render();
- }
- down() {
- if (this.cursor === this.filteredOptions.length - 1) {
- this.cursor = 0;
- } else {
- this.cursor++;
- }
- this.render();
- }
- left() {
- this.filteredOptions[this.cursor].selected = false;
- this.render();
- }
- right() {
- if (this.value.filter(e => e.selected).length >= this.maxChoices) return this.bell();
- this.filteredOptions[this.cursor].selected = true;
- this.render();
- }
- delete() {
- if (this.inputValue.length) {
- this.inputValue = this.inputValue.substr(0, this.inputValue.length - 1);
- this.updateFilteredOptions();
- }
- }
- updateFilteredOptions() {
- const currentHighlight = this.filteredOptions[this.cursor];
- this.filteredOptions = this.value
- .filter(v => {
- if (this.inputValue) {
- if (typeof v.title === 'string') {
- if (v.title.toLowerCase().includes(this.inputValue.toLowerCase())) {
- return true;
- }
- }
- if (typeof v.value === 'string') {
- if (v.value.toLowerCase().includes(this.inputValue.toLowerCase())) {
- return true;
- }
- }
- return false;
- }
- return true;
- });
- const newHighlightIndex = this.filteredOptions.findIndex(v => v === currentHighlight);
- this.cursor = newHighlightIndex < 0 ? 0 : newHighlightIndex;
- this.render();
- }
- handleSpaceToggle() {
- const v = this.filteredOptions[this.cursor];
- if (v.selected) {
- v.selected = false;
- this.render();
- } else if (v.disabled || this.value.filter(e => e.selected).length >= this.maxChoices) {
- return this.bell();
- } else {
- v.selected = true;
- this.render();
- }
- }
- handleInputChange(c) {
- this.inputValue = this.inputValue + c;
- this.updateFilteredOptions();
- }
- _(c, key) {
- if (c === ' ') {
- this.handleSpaceToggle();
- } else {
- this.handleInputChange(c);
- }
- }
- renderInstructions() {
- if (this.instructions === undefined || this.instructions) {
- if (typeof this.instructions === 'string') {
- return this.instructions;
- }
- return `
- Instructions:
- ${figures.arrowUp}/${figures.arrowDown}: Highlight option
- ${figures.arrowLeft}/${figures.arrowRight}/[space]: Toggle selection
- [a,b,c]/delete: Filter choices
- enter/return: Complete answer
- `;
- }
- return '';
- }
- renderCurrentInput() {
- return `
- Filtered results for: ${this.inputValue ? this.inputValue : color.gray('Enter something to filter')}\n`;
- }
- renderOption(cursor, v, i) {
- let title;
- if (v.disabled) title = cursor === i ? color.gray().underline(v.title) : color.strikethrough().gray(v.title);
- else title = cursor === i ? color.cyan().underline(v.title) : v.title;
- return (v.selected ? color.green(figures.radioOn) : figures.radioOff) + ' ' + title
- }
- renderDoneOrInstructions() {
- if (this.done) {
- return this.value
- .filter(e => e.selected)
- .map(v => v.title)
- .join(', ');
- }
- const output = [color.gray(this.hint), this.renderInstructions(), this.renderCurrentInput()];
- if (this.filteredOptions.length && this.filteredOptions[this.cursor].disabled) {
- output.push(color.yellow(this.warn));
- }
- return output.join(' ');
- }
- render() {
- if (this.closed) return;
- if (this.firstRender) this.out.write(cursor.hide);
- super.render();
- // print prompt
- let prompt = [
- style.symbol(this.done, this.aborted),
- color.bold(this.msg),
- style.delimiter(false),
- this.renderDoneOrInstructions()
- ].join(' ');
- if (this.showMinError) {
- prompt += color.red(`You must select a minimum of ${this.minSelected} choices.`);
- this.showMinError = false;
- }
- prompt += this.renderOptions(this.filteredOptions);
- this.out.write(this.clear + prompt);
- this.clear = clear(prompt, this.out.columns);
- }
- }
- autocompleteMultiselect = AutocompleteMultiselectPrompt;
- return autocompleteMultiselect;
- }
- var confirm;
- var hasRequiredConfirm;
- function requireConfirm () {
- if (hasRequiredConfirm) return confirm;
- hasRequiredConfirm = 1;
- const color = requireKleur();
- const Prompt = requirePrompt();
- const { style, clear } = requireUtil();
- const { erase, cursor } = requireSrc();
- /**
- * ConfirmPrompt Base Element
- * @param {Object} opts Options
- * @param {String} opts.message Message
- * @param {Boolean} [opts.initial] Default value (true/false)
- * @param {Stream} [opts.stdin] The Readable stream to listen to
- * @param {Stream} [opts.stdout] The Writable stream to write readline data to
- * @param {String} [opts.yes] The "Yes" label
- * @param {String} [opts.yesOption] The "Yes" option when choosing between yes/no
- * @param {String} [opts.no] The "No" label
- * @param {String} [opts.noOption] The "No" option when choosing between yes/no
- */
- class ConfirmPrompt extends Prompt {
- constructor(opts={}) {
- super(opts);
- this.msg = opts.message;
- this.value = opts.initial;
- this.initialValue = !!opts.initial;
- this.yesMsg = opts.yes || 'yes';
- this.yesOption = opts.yesOption || '(Y/n)';
- this.noMsg = opts.no || 'no';
- this.noOption = opts.noOption || '(y/N)';
- this.render();
- }
- reset() {
- this.value = this.initialValue;
- this.fire();
- this.render();
- }
- exit() {
- this.abort();
- }
- abort() {
- this.done = this.aborted = true;
- this.fire();
- this.render();
- this.out.write('\n');
- this.close();
- }
- submit() {
- this.value = this.value || false;
- this.done = true;
- this.aborted = false;
- this.fire();
- this.render();
- this.out.write('\n');
- this.close();
- }
- _(c, key) {
- if (c.toLowerCase() === 'y') {
- this.value = true;
- return this.submit();
- }
- if (c.toLowerCase() === 'n') {
- this.value = false;
- return this.submit();
- }
- return this.bell();
- }
- render() {
- if (this.closed) return;
- if (this.firstRender) this.out.write(cursor.hide);
- else this.out.write(clear(this.outputText, this.out.columns));
- super.render();
- this.outputText = [
- style.symbol(this.done, this.aborted),
- color.bold(this.msg),
- style.delimiter(this.done),
- this.done ? (this.value ? this.yesMsg : this.noMsg)
- : color.gray(this.initialValue ? this.yesOption : this.noOption)
- ].join(' ');
- this.out.write(erase.line + cursor.to(0) + this.outputText);
- }
- }
- confirm = ConfirmPrompt;
- return confirm;
- }
- var elements;
- var hasRequiredElements;
- function requireElements () {
- if (hasRequiredElements) return elements;
- hasRequiredElements = 1;
- elements = {
- TextPrompt: requireText(),
- SelectPrompt: requireSelect(),
- TogglePrompt: requireToggle(),
- DatePrompt: requireDate(),
- NumberPrompt: requireNumber(),
- MultiselectPrompt: requireMultiselect(),
- AutocompletePrompt: requireAutocomplete(),
- AutocompleteMultiselectPrompt: requireAutocompleteMultiselect(),
- ConfirmPrompt: requireConfirm()
- };
- return elements;
- }
- var hasRequiredPrompts;
- function requirePrompts () {
- if (hasRequiredPrompts) return prompts$1;
- hasRequiredPrompts = 1;
- (function (exports) {
- const $ = exports;
- const el = requireElements();
- const noop = v => v;
- function toPrompt(type, args, opts={}) {
- return new Promise((res, rej) => {
- const p = new el[type](args);
- const onAbort = opts.onAbort || noop;
- const onSubmit = opts.onSubmit || noop;
- const onExit = opts.onExit || noop;
- p.on('state', args.onState || noop);
- p.on('submit', x => res(onSubmit(x)));
- p.on('exit', x => res(onExit(x)));
- p.on('abort', x => rej(onAbort(x)));
- });
- }
- /**
- * Text prompt
- * @param {string} args.message Prompt message to display
- * @param {string} [args.initial] Default string value
- * @param {string} [args.style="default"] Render style ('default', 'password', 'invisible')
- * @param {function} [args.onState] On state change callback
- * @param {function} [args.validate] Function to validate user input
- * @param {Stream} [args.stdin] The Readable stream to listen to
- * @param {Stream} [args.stdout] The Writable stream to write readline data to
- * @returns {Promise} Promise with user input
- */
- $.text = args => toPrompt('TextPrompt', args);
- /**
- * Password prompt with masked input
- * @param {string} args.message Prompt message to display
- * @param {string} [args.initial] Default string value
- * @param {function} [args.onState] On state change callback
- * @param {function} [args.validate] Function to validate user input
- * @param {Stream} [args.stdin] The Readable stream to listen to
- * @param {Stream} [args.stdout] The Writable stream to write readline data to
- * @returns {Promise} Promise with user input
- */
- $.password = args => {
- args.style = 'password';
- return $.text(args);
- };
- /**
- * Prompt where input is invisible, like sudo
- * @param {string} args.message Prompt message to display
- * @param {string} [args.initial] Default string value
- * @param {function} [args.onState] On state change callback
- * @param {function} [args.validate] Function to validate user input
- * @param {Stream} [args.stdin] The Readable stream to listen to
- * @param {Stream} [args.stdout] The Writable stream to write readline data to
- * @returns {Promise} Promise with user input
- */
- $.invisible = args => {
- args.style = 'invisible';
- return $.text(args);
- };
- /**
- * Number prompt
- * @param {string} args.message Prompt message to display
- * @param {number} args.initial Default number value
- * @param {function} [args.onState] On state change callback
- * @param {number} [args.max] Max value
- * @param {number} [args.min] Min value
- * @param {string} [args.style="default"] Render style ('default', 'password', 'invisible')
- * @param {Boolean} [opts.float=false] Parse input as floats
- * @param {Number} [opts.round=2] Round floats to x decimals
- * @param {Number} [opts.increment=1] Number to increment by when using arrow-keys
- * @param {function} [args.validate] Function to validate user input
- * @param {Stream} [args.stdin] The Readable stream to listen to
- * @param {Stream} [args.stdout] The Writable stream to write readline data to
- * @returns {Promise} Promise with user input
- */
- $.number = args => toPrompt('NumberPrompt', args);
- /**
- * Date prompt
- * @param {string} args.message Prompt message to display
- * @param {number} args.initial Default number value
- * @param {function} [args.onState] On state change callback
- * @param {number} [args.max] Max value
- * @param {number} [args.min] Min value
- * @param {string} [args.style="default"] Render style ('default', 'password', 'invisible')
- * @param {Boolean} [opts.float=false] Parse input as floats
- * @param {Number} [opts.round=2] Round floats to x decimals
- * @param {Number} [opts.increment=1] Number to increment by when using arrow-keys
- * @param {function} [args.validate] Function to validate user input
- * @param {Stream} [args.stdin] The Readable stream to listen to
- * @param {Stream} [args.stdout] The Writable stream to write readline data to
- * @returns {Promise} Promise with user input
- */
- $.date = args => toPrompt('DatePrompt', args);
- /**
- * Classic yes/no prompt
- * @param {string} args.message Prompt message to display
- * @param {boolean} [args.initial=false] Default value
- * @param {function} [args.onState] On state change callback
- * @param {Stream} [args.stdin] The Readable stream to listen to
- * @param {Stream} [args.stdout] The Writable stream to write readline data to
- * @returns {Promise} Promise with user input
- */
- $.confirm = args => toPrompt('ConfirmPrompt', args);
- /**
- * List prompt, split intput string by `seperator`
- * @param {string} args.message Prompt message to display
- * @param {string} [args.initial] Default string value
- * @param {string} [args.style="default"] Render style ('default', 'password', 'invisible')
- * @param {string} [args.separator] String separator
- * @param {function} [args.onState] On state change callback
- * @param {Stream} [args.stdin] The Readable stream to listen to
- * @param {Stream} [args.stdout] The Writable stream to write readline data to
- * @returns {Promise} Promise with user input, in form of an `Array`
- */
- $.list = args => {
- const sep = args.separator || ',';
- return toPrompt('TextPrompt', args, {
- onSubmit: str => str.split(sep).map(s => s.trim())
- });
- };
- /**
- * Toggle/switch prompt
- * @param {string} args.message Prompt message to display
- * @param {boolean} [args.initial=false] Default value
- * @param {string} [args.active="on"] Text for `active` state
- * @param {string} [args.inactive="off"] Text for `inactive` state
- * @param {function} [args.onState] On state change callback
- * @param {Stream} [args.stdin] The Readable stream to listen to
- * @param {Stream} [args.stdout] The Writable stream to write readline data to
- * @returns {Promise} Promise with user input
- */
- $.toggle = args => toPrompt('TogglePrompt', args);
- /**
- * Interactive select prompt
- * @param {string} args.message Prompt message to display
- * @param {Array} args.choices Array of choices objects `[{ title, value }, ...]`
- * @param {number} [args.initial] Index of default value
- * @param {String} [args.hint] Hint to display
- * @param {function} [args.onState] On state change callback
- * @param {Stream} [args.stdin] The Readable stream to listen to
- * @param {Stream} [args.stdout] The Writable stream to write readline data to
- * @returns {Promise} Promise with user input
- */
- $.select = args => toPrompt('SelectPrompt', args);
- /**
- * Interactive multi-select / autocompleteMultiselect prompt
- * @param {string} args.message Prompt message to display
- * @param {Array} args.choices Array of choices objects `[{ title, value, [selected] }, ...]`
- * @param {number} [args.max] Max select
- * @param {string} [args.hint] Hint to display user
- * @param {Number} [args.cursor=0] Cursor start position
- * @param {function} [args.onState] On state change callback
- * @param {Stream} [args.stdin] The Readable stream to listen to
- * @param {Stream} [args.stdout] The Writable stream to write readline data to
- * @returns {Promise} Promise with user input
- */
- $.multiselect = args => {
- args.choices = [].concat(args.choices || []);
- const toSelected = items => items.filter(item => item.selected).map(item => item.value);
- return toPrompt('MultiselectPrompt', args, {
- onAbort: toSelected,
- onSubmit: toSelected
- });
- };
- $.autocompleteMultiselect = args => {
- args.choices = [].concat(args.choices || []);
- const toSelected = items => items.filter(item => item.selected).map(item => item.value);
- return toPrompt('AutocompleteMultiselectPrompt', args, {
- onAbort: toSelected,
- onSubmit: toSelected
- });
- };
- const byTitle = (input, choices) => Promise.resolve(
- choices.filter(item => item.title.slice(0, input.length).toLowerCase() === input.toLowerCase())
- );
- /**
- * Interactive auto-complete prompt
- * @param {string} args.message Prompt message to display
- * @param {Array} args.choices Array of auto-complete choices objects `[{ title, value }, ...]`
- * @param {Function} [args.suggest] Function to filter results based on user input. Defaults to sort by `title`
- * @param {number} [args.limit=10] Max number of results to show
- * @param {string} [args.style="default"] Render style ('default', 'password', 'invisible')
- * @param {String} [args.initial] Index of the default value
- * @param {boolean} [opts.clearFirst] The first ESCAPE keypress will clear the input
- * @param {String} [args.fallback] Fallback message - defaults to initial value
- * @param {function} [args.onState] On state change callback
- * @param {Stream} [args.stdin] The Readable stream to listen to
- * @param {Stream} [args.stdout] The Writable stream to write readline data to
- * @returns {Promise} Promise with user input
- */
- $.autocomplete = args => {
- args.suggest = args.suggest || byTitle;
- args.choices = [].concat(args.choices || []);
- return toPrompt('AutocompletePrompt', args);
- };
- } (prompts$1));
- return prompts$1;
- }
- var lib;
- var hasRequiredLib;
- function requireLib () {
- if (hasRequiredLib) return lib;
- hasRequiredLib = 1;
- const prompts = requirePrompts();
- const passOn = ['suggest', 'format', 'onState', 'validate', 'onRender', 'type'];
- const noop = () => {};
- /**
- * Prompt for a series of questions
- * @param {Array|Object} questions Single question object or Array of question objects
- * @param {Function} [onSubmit] Callback function called on prompt submit
- * @param {Function} [onCancel] Callback function called on cancel/abort
- * @returns {Object} Object with values from user input
- */
- async function prompt(questions=[], { onSubmit=noop, onCancel=noop }={}) {
- const answers = {};
- const override = prompt._override || {};
- questions = [].concat(questions);
- let answer, question, quit, name, type, lastPrompt;
- const getFormattedAnswer = async (question, answer, skipValidation = false) => {
- if (!skipValidation && question.validate && question.validate(answer) !== true) {
- return;
- }
- return question.format ? await question.format(answer, answers) : answer
- };
- for (question of questions) {
- ({ name, type } = question);
- // evaluate type first and skip if type is a falsy value
- if (typeof type === 'function') {
- type = await type(answer, { ...answers }, question);
- question['type'] = type;
- }
- if (!type) continue;
- // if property is a function, invoke it unless it's a special function
- for (let key in question) {
- if (passOn.includes(key)) continue;
- let value = question[key];
- question[key] = typeof value === 'function' ? await value(answer, { ...answers }, lastPrompt) : value;
- }
- lastPrompt = question;
- if (typeof question.message !== 'string') {
- throw new Error('prompt message is required');
- }
- // update vars in case they changed
- ({ name, type } = question);
- if (prompts[type] === void 0) {
- throw new Error(`prompt type (${type}) is not defined`);
- }
- if (override[question.name] !== undefined) {
- answer = await getFormattedAnswer(question, override[question.name]);
- if (answer !== undefined) {
- answers[name] = answer;
- continue;
- }
- }
- try {
- // Get the injected answer if there is one or prompt the user
- answer = prompt._injected ? getInjectedAnswer(prompt._injected, question.initial) : await prompts[type](question);
- answers[name] = answer = await getFormattedAnswer(question, answer, true);
- quit = await onSubmit(question, answer, answers);
- } catch (err) {
- quit = !(await onCancel(question, answers));
- }
- if (quit) return answers;
- }
- return answers;
- }
- function getInjectedAnswer(injected, deafultValue) {
- const answer = injected.shift();
- if (answer instanceof Error) {
- throw answer;
- }
- return (answer === undefined) ? deafultValue : answer;
- }
- function inject(answers) {
- prompt._injected = (prompt._injected || []).concat(answers);
- }
- function override(answers) {
- prompt._override = Object.assign({}, answers);
- }
- lib = Object.assign(prompt, { prompt, prompts, inject, override });
- return lib;
- }
- function isNodeLT(tar) {
- tar = (Array.isArray(tar) ? tar : tar.split('.')).map(Number);
- let i=0, src=process.versions.node.split('.').map(Number);
- for (; i < tar.length; i++) {
- if (src[i] > tar[i]) return false;
- if (tar[i] > src[i]) return true;
- }
- return false;
- }
- var prompts =
- isNodeLT('8.6.0')
- ? requireDist()
- : requireLib();
- var index = /*#__PURE__*/_mergeNamespaces({
- __proto__: null,
- 'default': prompts
- }, [prompts]);
- export { index as i, prompts as p };
|