31.index.js 131 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407
  1. exports.id = 31;
  2. exports.ids = [31];
  3. exports.modules = {
  4. /***/ 53692:
  5. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  6. "use strict";
  7. const isObject = val => val !== null && typeof val === 'object' && !Array.isArray(val);
  8. const identity = val => val;
  9. /* eslint-disable no-control-regex */
  10. // this is a modified version of https://github.com/chalk/ansi-regex (MIT License)
  11. const ANSI_REGEX = /[\u001b\u009b][[\]#;?()]*(?:(?:(?:[^\W_]*;?[^\W_]*)\u0007)|(?:(?:[0-9]{1,4}(;[0-9]{0,4})*)?[~0-9=<>cf-nqrtyA-PRZ]))/g;
  12. const create = () => {
  13. const colors = { enabled: true, visible: true, styles: {}, keys: {} };
  14. if ('FORCE_COLOR' in process.env) {
  15. colors.enabled = process.env.FORCE_COLOR !== '0';
  16. }
  17. const ansi = style => {
  18. let open = style.open = `\u001b[${style.codes[0]}m`;
  19. let close = style.close = `\u001b[${style.codes[1]}m`;
  20. let regex = style.regex = new RegExp(`\\u001b\\[${style.codes[1]}m`, 'g');
  21. style.wrap = (input, newline) => {
  22. if (input.includes(close)) input = input.replace(regex, close + open);
  23. let output = open + input + close;
  24. // see https://github.com/chalk/chalk/pull/92, thanks to the
  25. // chalk contributors for this fix. However, we've confirmed that
  26. // this issue is also present in Windows terminals
  27. return newline ? output.replace(/\r*\n/g, `${close}$&${open}`) : output;
  28. };
  29. return style;
  30. };
  31. const wrap = (style, input, newline) => {
  32. return typeof style === 'function' ? style(input) : style.wrap(input, newline);
  33. };
  34. const style = (input, stack) => {
  35. if (input === '' || input == null) return '';
  36. if (colors.enabled === false) return input;
  37. if (colors.visible === false) return '';
  38. let str = '' + input;
  39. let nl = str.includes('\n');
  40. let n = stack.length;
  41. if (n > 0 && stack.includes('unstyle')) {
  42. stack = [...new Set(['unstyle', ...stack])].reverse();
  43. }
  44. while (n-- > 0) str = wrap(colors.styles[stack[n]], str, nl);
  45. return str;
  46. };
  47. const define = (name, codes, type) => {
  48. colors.styles[name] = ansi({ name, codes });
  49. let keys = colors.keys[type] || (colors.keys[type] = []);
  50. keys.push(name);
  51. Reflect.defineProperty(colors, name, {
  52. configurable: true,
  53. enumerable: true,
  54. set(value) {
  55. colors.alias(name, value);
  56. },
  57. get() {
  58. let color = input => style(input, color.stack);
  59. Reflect.setPrototypeOf(color, colors);
  60. color.stack = this.stack ? this.stack.concat(name) : [name];
  61. return color;
  62. }
  63. });
  64. };
  65. define('reset', [0, 0], 'modifier');
  66. define('bold', [1, 22], 'modifier');
  67. define('dim', [2, 22], 'modifier');
  68. define('italic', [3, 23], 'modifier');
  69. define('underline', [4, 24], 'modifier');
  70. define('inverse', [7, 27], 'modifier');
  71. define('hidden', [8, 28], 'modifier');
  72. define('strikethrough', [9, 29], 'modifier');
  73. define('black', [30, 39], 'color');
  74. define('red', [31, 39], 'color');
  75. define('green', [32, 39], 'color');
  76. define('yellow', [33, 39], 'color');
  77. define('blue', [34, 39], 'color');
  78. define('magenta', [35, 39], 'color');
  79. define('cyan', [36, 39], 'color');
  80. define('white', [37, 39], 'color');
  81. define('gray', [90, 39], 'color');
  82. define('grey', [90, 39], 'color');
  83. define('bgBlack', [40, 49], 'bg');
  84. define('bgRed', [41, 49], 'bg');
  85. define('bgGreen', [42, 49], 'bg');
  86. define('bgYellow', [43, 49], 'bg');
  87. define('bgBlue', [44, 49], 'bg');
  88. define('bgMagenta', [45, 49], 'bg');
  89. define('bgCyan', [46, 49], 'bg');
  90. define('bgWhite', [47, 49], 'bg');
  91. define('blackBright', [90, 39], 'bright');
  92. define('redBright', [91, 39], 'bright');
  93. define('greenBright', [92, 39], 'bright');
  94. define('yellowBright', [93, 39], 'bright');
  95. define('blueBright', [94, 39], 'bright');
  96. define('magentaBright', [95, 39], 'bright');
  97. define('cyanBright', [96, 39], 'bright');
  98. define('whiteBright', [97, 39], 'bright');
  99. define('bgBlackBright', [100, 49], 'bgBright');
  100. define('bgRedBright', [101, 49], 'bgBright');
  101. define('bgGreenBright', [102, 49], 'bgBright');
  102. define('bgYellowBright', [103, 49], 'bgBright');
  103. define('bgBlueBright', [104, 49], 'bgBright');
  104. define('bgMagentaBright', [105, 49], 'bgBright');
  105. define('bgCyanBright', [106, 49], 'bgBright');
  106. define('bgWhiteBright', [107, 49], 'bgBright');
  107. colors.ansiRegex = ANSI_REGEX;
  108. colors.hasColor = colors.hasAnsi = str => {
  109. colors.ansiRegex.lastIndex = 0;
  110. return typeof str === 'string' && str !== '' && colors.ansiRegex.test(str);
  111. };
  112. colors.alias = (name, color) => {
  113. let fn = typeof color === 'string' ? colors[color] : color;
  114. if (typeof fn !== 'function') {
  115. throw new TypeError('Expected alias to be the name of an existing color (string) or a function');
  116. }
  117. if (!fn.stack) {
  118. Reflect.defineProperty(fn, 'name', { value: name });
  119. colors.styles[name] = fn;
  120. fn.stack = [name];
  121. }
  122. Reflect.defineProperty(colors, name, {
  123. configurable: true,
  124. enumerable: true,
  125. set(value) {
  126. colors.alias(name, value);
  127. },
  128. get() {
  129. let color = input => style(input, color.stack);
  130. Reflect.setPrototypeOf(color, colors);
  131. color.stack = this.stack ? this.stack.concat(fn.stack) : fn.stack;
  132. return color;
  133. }
  134. });
  135. };
  136. colors.theme = custom => {
  137. if (!isObject(custom)) throw new TypeError('Expected theme to be an object');
  138. for (let name of Object.keys(custom)) {
  139. colors.alias(name, custom[name]);
  140. }
  141. return colors;
  142. };
  143. colors.alias('unstyle', str => {
  144. if (typeof str === 'string' && str !== '') {
  145. colors.ansiRegex.lastIndex = 0;
  146. return str.replace(colors.ansiRegex, '');
  147. }
  148. return '';
  149. });
  150. colors.alias('noop', str => str);
  151. colors.none = colors.clear = colors.noop;
  152. colors.stripColor = colors.unstyle;
  153. colors.symbols = __webpack_require__(17142);
  154. colors.define = define;
  155. return colors;
  156. };
  157. module.exports = create();
  158. module.exports.create = create;
  159. /***/ }),
  160. /***/ 17142:
  161. /***/ ((module) => {
  162. "use strict";
  163. const isHyper = process.env.TERM_PROGRAM === 'Hyper';
  164. const isWindows = process.platform === 'win32';
  165. const isLinux = process.platform === 'linux';
  166. const common = {
  167. ballotDisabled: '☒',
  168. ballotOff: '☐',
  169. ballotOn: '☑',
  170. bullet: '•',
  171. bulletWhite: '◦',
  172. fullBlock: '█',
  173. heart: '❤',
  174. identicalTo: '≡',
  175. line: '─',
  176. mark: '※',
  177. middot: '·',
  178. minus: '-',
  179. multiplication: '×',
  180. obelus: '÷',
  181. pencilDownRight: '✎',
  182. pencilRight: '✏',
  183. pencilUpRight: '✐',
  184. percent: '%',
  185. pilcrow2: '❡',
  186. pilcrow: '¶',
  187. plusMinus: '±',
  188. section: '§',
  189. starsOff: '☆',
  190. starsOn: '★',
  191. upDownArrow: '↕'
  192. };
  193. const windows = Object.assign({}, common, {
  194. check: '√',
  195. cross: '×',
  196. ellipsisLarge: '...',
  197. ellipsis: '...',
  198. info: 'i',
  199. question: '?',
  200. questionSmall: '?',
  201. pointer: '>',
  202. pointerSmall: '»',
  203. radioOff: '( )',
  204. radioOn: '(*)',
  205. warning: '‼'
  206. });
  207. const other = Object.assign({}, common, {
  208. ballotCross: '✘',
  209. check: '✔',
  210. cross: '✖',
  211. ellipsisLarge: '⋯',
  212. ellipsis: '…',
  213. info: 'ℹ',
  214. question: '?',
  215. questionFull: '?',
  216. questionSmall: '﹖',
  217. pointer: isLinux ? '▸' : '❯',
  218. pointerSmall: isLinux ? '‣' : '›',
  219. radioOff: '◯',
  220. radioOn: '◉',
  221. warning: '⚠'
  222. });
  223. module.exports = (isWindows && !isHyper) ? windows : other;
  224. Reflect.defineProperty(module.exports, 'common', { enumerable: false, value: common });
  225. Reflect.defineProperty(module.exports, 'windows', { enumerable: false, value: windows });
  226. Reflect.defineProperty(module.exports, 'other', { enumerable: false, value: other });
  227. /***/ }),
  228. /***/ 84031:
  229. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  230. "use strict";
  231. const assert = __webpack_require__(42357);
  232. const Events = __webpack_require__(28614);
  233. const utils = __webpack_require__(83546);
  234. /**
  235. * Create an instance of `Enquirer`.
  236. *
  237. * ```js
  238. * const Enquirer = require('enquirer');
  239. * const enquirer = new Enquirer();
  240. * ```
  241. * @name Enquirer
  242. * @param {Object} `options` (optional) Options to use with all prompts.
  243. * @param {Object} `answers` (optional) Answers object to initialize with.
  244. * @api public
  245. */
  246. class Enquirer extends Events {
  247. constructor(options, answers) {
  248. super();
  249. this.options = utils.merge({}, options);
  250. this.answers = { ...answers };
  251. }
  252. /**
  253. * Register a custom prompt type.
  254. *
  255. * ```js
  256. * const Enquirer = require('enquirer');
  257. * const enquirer = new Enquirer();
  258. * enquirer.register('customType', require('./custom-prompt'));
  259. * ```
  260. * @name register()
  261. * @param {String} `type`
  262. * @param {Function|Prompt} `fn` `Prompt` class, or a function that returns a `Prompt` class.
  263. * @return {Object} Returns the Enquirer instance
  264. * @api public
  265. */
  266. register(type, fn) {
  267. if (utils.isObject(type)) {
  268. for (let key of Object.keys(type)) this.register(key, type[key]);
  269. return this;
  270. }
  271. assert.equal(typeof fn, 'function', 'expected a function');
  272. let name = type.toLowerCase();
  273. if (fn.prototype instanceof this.Prompt) {
  274. this.prompts[name] = fn;
  275. } else {
  276. this.prompts[name] = fn(this.Prompt, this);
  277. }
  278. return this;
  279. }
  280. /**
  281. * Prompt function that takes a "question" object or array of question objects,
  282. * and returns an object with responses from the user.
  283. *
  284. * ```js
  285. * const Enquirer = require('enquirer');
  286. * const enquirer = new Enquirer();
  287. *
  288. * const response = await enquirer.prompt({
  289. * type: 'input',
  290. * name: 'username',
  291. * message: 'What is your username?'
  292. * });
  293. * console.log(response);
  294. * ```
  295. * @name prompt()
  296. * @param {Array|Object} `questions` Options objects for one or more prompts to run.
  297. * @return {Promise} Promise that returns an "answers" object with the user's responses.
  298. * @api public
  299. */
  300. async prompt(questions = []) {
  301. for (let question of [].concat(questions)) {
  302. try {
  303. if (typeof question === 'function') question = await question.call(this);
  304. await this.ask(utils.merge({}, this.options, question));
  305. } catch (err) {
  306. return Promise.reject(err);
  307. }
  308. }
  309. return this.answers;
  310. }
  311. async ask(question) {
  312. if (typeof question === 'function') {
  313. question = await question.call(this);
  314. }
  315. let opts = utils.merge({}, this.options, question);
  316. let { type, name } = question;
  317. let { set, get } = utils;
  318. if (typeof type === 'function') {
  319. type = await type.call(this, question, this.answers);
  320. }
  321. if (!type) return this.answers[name];
  322. assert(this.prompts[type], `Prompt "${type}" is not registered`);
  323. let prompt = new this.prompts[type](opts);
  324. let value = get(this.answers, name);
  325. prompt.state.answers = this.answers;
  326. prompt.enquirer = this;
  327. if (name) {
  328. prompt.on('submit', value => {
  329. this.emit('answer', name, value, prompt);
  330. set(this.answers, name, value);
  331. });
  332. }
  333. // bubble events
  334. let emit = prompt.emit.bind(prompt);
  335. prompt.emit = (...args) => {
  336. this.emit.call(this, ...args);
  337. return emit(...args);
  338. };
  339. this.emit('prompt', prompt, this);
  340. if (opts.autofill && value != null) {
  341. prompt.value = prompt.input = value;
  342. // if "autofill=show" render the prompt, otherwise stay "silent"
  343. if (opts.autofill === 'show') {
  344. await prompt.submit();
  345. }
  346. } else {
  347. value = prompt.value = await prompt.run();
  348. }
  349. return value;
  350. }
  351. /**
  352. * Use an enquirer plugin.
  353. *
  354. * ```js
  355. * const Enquirer = require('enquirer');
  356. * const enquirer = new Enquirer();
  357. * const plugin = enquirer => {
  358. * // do stuff to enquire instance
  359. * };
  360. * enquirer.use(plugin);
  361. * ```
  362. * @name use()
  363. * @param {Function} `plugin` Plugin function that takes an instance of Enquirer.
  364. * @return {Object} Returns the Enquirer instance.
  365. * @api public
  366. */
  367. use(plugin) {
  368. plugin.call(this, this);
  369. return this;
  370. }
  371. set Prompt(value) {
  372. this._Prompt = value;
  373. }
  374. get Prompt() {
  375. return this._Prompt || this.constructor.Prompt;
  376. }
  377. get prompts() {
  378. return this.constructor.prompts;
  379. }
  380. static set Prompt(value) {
  381. this._Prompt = value;
  382. }
  383. static get Prompt() {
  384. return this._Prompt || __webpack_require__(232);
  385. }
  386. static get prompts() {
  387. return __webpack_require__(29594);
  388. }
  389. static get types() {
  390. return __webpack_require__(29920);
  391. }
  392. /**
  393. * Prompt function that takes a "question" object or array of question objects,
  394. * and returns an object with responses from the user.
  395. *
  396. * ```js
  397. * const { prompt } = require('enquirer');
  398. * const response = await prompt({
  399. * type: 'input',
  400. * name: 'username',
  401. * message: 'What is your username?'
  402. * });
  403. * console.log(response);
  404. * ```
  405. * @name Enquirer#prompt
  406. * @param {Array|Object} `questions` Options objects for one or more prompts to run.
  407. * @return {Promise} Promise that returns an "answers" object with the user's responses.
  408. * @api public
  409. */
  410. static get prompt() {
  411. const fn = (questions, ...rest) => {
  412. let enquirer = new this(...rest);
  413. let emit = enquirer.emit.bind(enquirer);
  414. enquirer.emit = (...args) => {
  415. fn.emit(...args);
  416. return emit(...args);
  417. };
  418. return enquirer.prompt(questions);
  419. };
  420. utils.mixinEmitter(fn, new Events());
  421. return fn;
  422. }
  423. }
  424. utils.mixinEmitter(Enquirer, new Events());
  425. const prompts = Enquirer.prompts;
  426. for (let name of Object.keys(prompts)) {
  427. let key = name.toLowerCase();
  428. let run = options => new prompts[name](options).run();
  429. Enquirer.prompt[key] = run;
  430. Enquirer[key] = run;
  431. if (!Enquirer[name]) {
  432. Reflect.defineProperty(Enquirer, name, { get: () => prompts[name] });
  433. }
  434. }
  435. const exp = name => {
  436. utils.defineExport(Enquirer, name, () => Enquirer.types[name]);
  437. };
  438. exp('ArrayPrompt');
  439. exp('AuthPrompt');
  440. exp('BooleanPrompt');
  441. exp('NumberPrompt');
  442. exp('StringPrompt');
  443. module.exports = Enquirer;
  444. /***/ }),
  445. /***/ 94907:
  446. /***/ ((module, exports, __webpack_require__) => {
  447. "use strict";
  448. const isTerm = process.env.TERM_PROGRAM === 'Apple_Terminal';
  449. const colors = __webpack_require__(53692);
  450. const utils = __webpack_require__(83546);
  451. const ansi = module.exports = exports;
  452. const ESC = '\u001b[';
  453. const BEL = '\u0007';
  454. let hidden = false;
  455. const code = ansi.code = {
  456. bell: BEL,
  457. beep: BEL,
  458. beginning: `${ESC}G`,
  459. down: `${ESC}J`,
  460. esc: ESC,
  461. getPosition: `${ESC}6n`,
  462. hide: `${ESC}?25l`,
  463. line: `${ESC}2K`,
  464. lineEnd: `${ESC}K`,
  465. lineStart: `${ESC}1K`,
  466. restorePosition: ESC + (isTerm ? '8' : 'u'),
  467. savePosition: ESC + (isTerm ? '7' : 's'),
  468. screen: `${ESC}2J`,
  469. show: `${ESC}?25h`,
  470. up: `${ESC}1J`
  471. };
  472. const cursor = ansi.cursor = {
  473. get hidden() {
  474. return hidden;
  475. },
  476. hide() {
  477. hidden = true;
  478. return code.hide;
  479. },
  480. show() {
  481. hidden = false;
  482. return code.show;
  483. },
  484. forward: (count = 1) => `${ESC}${count}C`,
  485. backward: (count = 1) => `${ESC}${count}D`,
  486. nextLine: (count = 1) => `${ESC}E`.repeat(count),
  487. prevLine: (count = 1) => `${ESC}F`.repeat(count),
  488. up: (count = 1) => count ? `${ESC}${count}A` : '',
  489. down: (count = 1) => count ? `${ESC}${count}B` : '',
  490. right: (count = 1) => count ? `${ESC}${count}C` : '',
  491. left: (count = 1) => count ? `${ESC}${count}D` : '',
  492. to(x, y) {
  493. return y ? `${ESC}${y + 1};${x + 1}H` : `${ESC}${x + 1}G`;
  494. },
  495. move(x = 0, y = 0) {
  496. let res = '';
  497. res += (x < 0) ? cursor.left(-x) : (x > 0) ? cursor.right(x) : '';
  498. res += (y < 0) ? cursor.up(-y) : (y > 0) ? cursor.down(y) : '';
  499. return res;
  500. },
  501. restore(state = {}) {
  502. let { after, cursor, initial, input, prompt, size, value } = state;
  503. initial = utils.isPrimitive(initial) ? String(initial) : '';
  504. input = utils.isPrimitive(input) ? String(input) : '';
  505. value = utils.isPrimitive(value) ? String(value) : '';
  506. if (size) {
  507. let codes = ansi.cursor.up(size) + ansi.cursor.to(prompt.length);
  508. let diff = input.length - cursor;
  509. if (diff > 0) {
  510. codes += ansi.cursor.left(diff);
  511. }
  512. return codes;
  513. }
  514. if (value || after) {
  515. let pos = (!input && !!initial) ? -initial.length : -input.length + cursor;
  516. if (after) pos -= after.length;
  517. if (input === '' && initial && !prompt.includes(initial)) {
  518. pos += initial.length;
  519. }
  520. return ansi.cursor.move(pos);
  521. }
  522. }
  523. };
  524. const erase = ansi.erase = {
  525. screen: code.screen,
  526. up: code.up,
  527. down: code.down,
  528. line: code.line,
  529. lineEnd: code.lineEnd,
  530. lineStart: code.lineStart,
  531. lines(n) {
  532. let str = '';
  533. for (let i = 0; i < n; i++) {
  534. str += ansi.erase.line + (i < n - 1 ? ansi.cursor.up(1) : '');
  535. }
  536. if (n) str += ansi.code.beginning;
  537. return str;
  538. }
  539. };
  540. ansi.clear = (input = '', columns = process.stdout.columns) => {
  541. if (!columns) return erase.line + cursor.to(0);
  542. let width = str => [...colors.unstyle(str)].length;
  543. let lines = input.split(/\r?\n/);
  544. let rows = 0;
  545. for (let line of lines) {
  546. rows += 1 + Math.floor(Math.max(width(line) - 1, 0) / columns);
  547. }
  548. return (erase.line + cursor.prevLine()).repeat(rows - 1) + erase.line + cursor.to(0);
  549. };
  550. /***/ }),
  551. /***/ 64726:
  552. /***/ ((__unused_webpack_module, exports) => {
  553. "use strict";
  554. /**
  555. * Actions are mappings from keypress event names to method names
  556. * in the prompts.
  557. */
  558. exports.ctrl = {
  559. a: 'first',
  560. b: 'backward',
  561. c: 'cancel',
  562. d: 'deleteForward',
  563. e: 'last',
  564. f: 'forward',
  565. g: 'reset',
  566. i: 'tab',
  567. k: 'cutForward',
  568. l: 'reset',
  569. n: 'newItem',
  570. m: 'cancel',
  571. j: 'submit',
  572. p: 'search',
  573. r: 'remove',
  574. s: 'save',
  575. u: 'undo',
  576. w: 'cutLeft',
  577. x: 'toggleCursor',
  578. v: 'paste'
  579. };
  580. exports.shift = {
  581. up: 'shiftUp',
  582. down: 'shiftDown',
  583. left: 'shiftLeft',
  584. right: 'shiftRight',
  585. tab: 'prev'
  586. };
  587. exports.fn = {
  588. up: 'pageUp',
  589. down: 'pageDown',
  590. left: 'pageLeft',
  591. right: 'pageRight',
  592. delete: 'deleteForward'
  593. };
  594. // <alt> on Windows
  595. exports.option = {
  596. b: 'backward',
  597. f: 'forward',
  598. d: 'cutRight',
  599. left: 'cutLeft',
  600. up: 'altUp',
  601. down: 'altDown'
  602. };
  603. exports.keys = {
  604. pageup: 'pageUp', // <fn>+<up> (mac), <Page Up> (windows)
  605. pagedown: 'pageDown', // <fn>+<down> (mac), <Page Down> (windows)
  606. home: 'home', // <fn>+<left> (mac), <home> (windows)
  607. end: 'end', // <fn>+<right> (mac), <end> (windows)
  608. cancel: 'cancel',
  609. delete: 'deleteForward',
  610. backspace: 'delete',
  611. down: 'down',
  612. enter: 'submit',
  613. escape: 'cancel',
  614. left: 'left',
  615. space: 'space',
  616. number: 'number',
  617. return: 'submit',
  618. right: 'right',
  619. tab: 'next',
  620. up: 'up'
  621. };
  622. /***/ }),
  623. /***/ 73736:
  624. /***/ ((module) => {
  625. "use strict";
  626. const unique = arr => arr.filter((v, i) => arr.lastIndexOf(v) === i);
  627. const compact = arr => unique(arr).filter(Boolean);
  628. module.exports = (action, data = {}, value = '') => {
  629. let { past = [], present = '' } = data;
  630. let rest, prev;
  631. switch (action) {
  632. case 'prev':
  633. case 'undo':
  634. rest = past.slice(0, past.length - 1);
  635. prev = past[past.length - 1] || '';
  636. return {
  637. past: compact([value, ...rest]),
  638. present: prev
  639. };
  640. case 'next':
  641. case 'redo':
  642. rest = past.slice(1);
  643. prev = past[0] || '';
  644. return {
  645. past: compact([...rest, value]),
  646. present: prev
  647. };
  648. case 'save':
  649. return {
  650. past: compact([...past, value]),
  651. present: ''
  652. };
  653. case 'remove':
  654. prev = compact(past.filter(v => v !== value));
  655. present = '';
  656. if (prev.length) {
  657. present = prev.pop();
  658. }
  659. return {
  660. past: prev,
  661. present
  662. };
  663. default: {
  664. throw new Error(`Invalid action: "${action}"`);
  665. }
  666. }
  667. };
  668. /***/ }),
  669. /***/ 27189:
  670. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  671. "use strict";
  672. const colors = __webpack_require__(53692);
  673. const clean = (str = '') => {
  674. return typeof str === 'string' ? str.replace(/^['"]|['"]$/g, '') : '';
  675. };
  676. /**
  677. * This file contains the interpolation and rendering logic for
  678. * the Snippet prompt.
  679. */
  680. class Item {
  681. constructor(token) {
  682. this.name = token.key;
  683. this.field = token.field || {};
  684. this.value = clean(token.initial || this.field.initial || '');
  685. this.message = token.message || this.name;
  686. this.cursor = 0;
  687. this.input = '';
  688. this.lines = [];
  689. }
  690. }
  691. const tokenize = async(options = {}, defaults = {}, fn = token => token) => {
  692. let unique = new Set();
  693. let fields = options.fields || [];
  694. let input = options.template;
  695. let tabstops = [];
  696. let items = [];
  697. let keys = [];
  698. let line = 1;
  699. if (typeof input === 'function') {
  700. input = await input();
  701. }
  702. let i = -1;
  703. let next = () => input[++i];
  704. let peek = () => input[i + 1];
  705. let push = token => {
  706. token.line = line;
  707. tabstops.push(token);
  708. };
  709. push({ type: 'bos', value: '' });
  710. while (i < input.length - 1) {
  711. let value = next();
  712. if (/^[^\S\n ]$/.test(value)) {
  713. push({ type: 'text', value });
  714. continue;
  715. }
  716. if (value === '\n') {
  717. push({ type: 'newline', value });
  718. line++;
  719. continue;
  720. }
  721. if (value === '\\') {
  722. value += next();
  723. push({ type: 'text', value });
  724. continue;
  725. }
  726. if ((value === '$' || value === '#' || value === '{') && peek() === '{') {
  727. let n = next();
  728. value += n;
  729. let token = { type: 'template', open: value, inner: '', close: '', value };
  730. let ch;
  731. while ((ch = next())) {
  732. if (ch === '}') {
  733. if (peek() === '}') ch += next();
  734. token.value += ch;
  735. token.close = ch;
  736. break;
  737. }
  738. if (ch === ':') {
  739. token.initial = '';
  740. token.key = token.inner;
  741. } else if (token.initial !== void 0) {
  742. token.initial += ch;
  743. }
  744. token.value += ch;
  745. token.inner += ch;
  746. }
  747. token.template = token.open + (token.initial || token.inner) + token.close;
  748. token.key = token.key || token.inner;
  749. if (defaults.hasOwnProperty(token.key)) {
  750. token.initial = defaults[token.key];
  751. }
  752. token = fn(token);
  753. push(token);
  754. keys.push(token.key);
  755. unique.add(token.key);
  756. let item = items.find(item => item.name === token.key);
  757. token.field = fields.find(ch => ch.name === token.key);
  758. if (!item) {
  759. item = new Item(token);
  760. items.push(item);
  761. }
  762. item.lines.push(token.line - 1);
  763. continue;
  764. }
  765. let last = tabstops[tabstops.length - 1];
  766. if (last.type === 'text' && last.line === line) {
  767. last.value += value;
  768. } else {
  769. push({ type: 'text', value });
  770. }
  771. }
  772. push({ type: 'eos', value: '' });
  773. return { input, tabstops, unique, keys, items };
  774. };
  775. module.exports = async prompt => {
  776. let options = prompt.options;
  777. let required = new Set(options.required === true ? [] : (options.required || []));
  778. let defaults = { ...options.values, ...options.initial };
  779. let { tabstops, items, keys } = await tokenize(options, defaults);
  780. let result = createFn('result', prompt, options);
  781. let format = createFn('format', prompt, options);
  782. let isValid = createFn('validate', prompt, options, true);
  783. let isVal = prompt.isValue.bind(prompt);
  784. return async(state = {}, submitted = false) => {
  785. let index = 0;
  786. state.required = required;
  787. state.items = items;
  788. state.keys = keys;
  789. state.output = '';
  790. let validate = async(value, state, item, index) => {
  791. let error = await isValid(value, state, item, index);
  792. if (error === false) {
  793. return 'Invalid field ' + item.name;
  794. }
  795. return error;
  796. };
  797. for (let token of tabstops) {
  798. let value = token.value;
  799. let key = token.key;
  800. if (token.type !== 'template') {
  801. if (value) state.output += value;
  802. continue;
  803. }
  804. if (token.type === 'template') {
  805. let item = items.find(ch => ch.name === key);
  806. if (options.required === true) {
  807. state.required.add(item.name);
  808. }
  809. let val = [item.input, state.values[item.value], item.value, value].find(isVal);
  810. let field = item.field || {};
  811. let message = field.message || token.inner;
  812. if (submitted) {
  813. let error = await validate(state.values[key], state, item, index);
  814. if ((error && typeof error === 'string') || error === false) {
  815. state.invalid.set(key, error);
  816. continue;
  817. }
  818. state.invalid.delete(key);
  819. let res = await result(state.values[key], state, item, index);
  820. state.output += colors.unstyle(res);
  821. continue;
  822. }
  823. item.placeholder = false;
  824. let before = value;
  825. value = await format(value, state, item, index);
  826. if (val !== value) {
  827. state.values[key] = val;
  828. value = prompt.styles.typing(val);
  829. state.missing.delete(message);
  830. } else {
  831. state.values[key] = void 0;
  832. val = `<${message}>`;
  833. value = prompt.styles.primary(val);
  834. item.placeholder = true;
  835. if (state.required.has(key)) {
  836. state.missing.add(message);
  837. }
  838. }
  839. if (state.missing.has(message) && state.validating) {
  840. value = prompt.styles.warning(val);
  841. }
  842. if (state.invalid.has(key) && state.validating) {
  843. value = prompt.styles.danger(val);
  844. }
  845. if (index === state.index) {
  846. if (before !== value) {
  847. value = prompt.styles.underline(value);
  848. } else {
  849. value = prompt.styles.heading(colors.unstyle(value));
  850. }
  851. }
  852. index++;
  853. }
  854. if (value) {
  855. state.output += value;
  856. }
  857. }
  858. let lines = state.output.split('\n').map(l => ' ' + l);
  859. let len = items.length;
  860. let done = 0;
  861. for (let item of items) {
  862. if (state.invalid.has(item.name)) {
  863. item.lines.forEach(i => {
  864. if (lines[i][0] !== ' ') return;
  865. lines[i] = state.styles.danger(state.symbols.bullet) + lines[i].slice(1);
  866. });
  867. }
  868. if (prompt.isValue(state.values[item.name])) {
  869. done++;
  870. }
  871. }
  872. state.completed = ((done / len) * 100).toFixed(0);
  873. state.output = lines.join('\n');
  874. return state.output;
  875. };
  876. };
  877. function createFn(prop, prompt, options, fallback) {
  878. return (value, state, item, index) => {
  879. if (typeof item.field[prop] === 'function') {
  880. return item.field[prop].call(prompt, value, state, item, index);
  881. }
  882. return [fallback, value].find(v => prompt.isValue(v));
  883. };
  884. }
  885. /***/ }),
  886. /***/ 28914:
  887. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  888. "use strict";
  889. const readline = __webpack_require__(51058);
  890. const combos = __webpack_require__(64726);
  891. /* eslint-disable no-control-regex */
  892. const metaKeyCodeRe = /^(?:\x1b)([a-zA-Z0-9])$/;
  893. const fnKeyRe = /^(?:\x1b+)(O|N|\[|\[\[)(?:(\d+)(?:;(\d+))?([~^$])|(?:1;)?(\d+)?([a-zA-Z]))/;
  894. const keyName = {
  895. /* xterm/gnome ESC O letter */
  896. 'OP': 'f1',
  897. 'OQ': 'f2',
  898. 'OR': 'f3',
  899. 'OS': 'f4',
  900. /* xterm/rxvt ESC [ number ~ */
  901. '[11~': 'f1',
  902. '[12~': 'f2',
  903. '[13~': 'f3',
  904. '[14~': 'f4',
  905. /* from Cygwin and used in libuv */
  906. '[[A': 'f1',
  907. '[[B': 'f2',
  908. '[[C': 'f3',
  909. '[[D': 'f4',
  910. '[[E': 'f5',
  911. /* common */
  912. '[15~': 'f5',
  913. '[17~': 'f6',
  914. '[18~': 'f7',
  915. '[19~': 'f8',
  916. '[20~': 'f9',
  917. '[21~': 'f10',
  918. '[23~': 'f11',
  919. '[24~': 'f12',
  920. /* xterm ESC [ letter */
  921. '[A': 'up',
  922. '[B': 'down',
  923. '[C': 'right',
  924. '[D': 'left',
  925. '[E': 'clear',
  926. '[F': 'end',
  927. '[H': 'home',
  928. /* xterm/gnome ESC O letter */
  929. 'OA': 'up',
  930. 'OB': 'down',
  931. 'OC': 'right',
  932. 'OD': 'left',
  933. 'OE': 'clear',
  934. 'OF': 'end',
  935. 'OH': 'home',
  936. /* xterm/rxvt ESC [ number ~ */
  937. '[1~': 'home',
  938. '[2~': 'insert',
  939. '[3~': 'delete',
  940. '[4~': 'end',
  941. '[5~': 'pageup',
  942. '[6~': 'pagedown',
  943. /* putty */
  944. '[[5~': 'pageup',
  945. '[[6~': 'pagedown',
  946. /* rxvt */
  947. '[7~': 'home',
  948. '[8~': 'end',
  949. /* rxvt keys with modifiers */
  950. '[a': 'up',
  951. '[b': 'down',
  952. '[c': 'right',
  953. '[d': 'left',
  954. '[e': 'clear',
  955. '[2$': 'insert',
  956. '[3$': 'delete',
  957. '[5$': 'pageup',
  958. '[6$': 'pagedown',
  959. '[7$': 'home',
  960. '[8$': 'end',
  961. 'Oa': 'up',
  962. 'Ob': 'down',
  963. 'Oc': 'right',
  964. 'Od': 'left',
  965. 'Oe': 'clear',
  966. '[2^': 'insert',
  967. '[3^': 'delete',
  968. '[5^': 'pageup',
  969. '[6^': 'pagedown',
  970. '[7^': 'home',
  971. '[8^': 'end',
  972. /* misc. */
  973. '[Z': 'tab',
  974. }
  975. function isShiftKey(code) {
  976. return ['[a', '[b', '[c', '[d', '[e', '[2$', '[3$', '[5$', '[6$', '[7$', '[8$', '[Z'].includes(code)
  977. }
  978. function isCtrlKey(code) {
  979. return [ 'Oa', 'Ob', 'Oc', 'Od', 'Oe', '[2^', '[3^', '[5^', '[6^', '[7^', '[8^'].includes(code)
  980. }
  981. const keypress = (s = '', event = {}) => {
  982. let parts;
  983. let key = {
  984. name: event.name,
  985. ctrl: false,
  986. meta: false,
  987. shift: false,
  988. option: false,
  989. sequence: s,
  990. raw: s,
  991. ...event
  992. };
  993. if (Buffer.isBuffer(s)) {
  994. if (s[0] > 127 && s[1] === void 0) {
  995. s[0] -= 128;
  996. s = '\x1b' + String(s);
  997. } else {
  998. s = String(s);
  999. }
  1000. } else if (s !== void 0 && typeof s !== 'string') {
  1001. s = String(s);
  1002. } else if (!s) {
  1003. s = key.sequence || '';
  1004. }
  1005. key.sequence = key.sequence || s || key.name;
  1006. if (s === '\r') {
  1007. // carriage return
  1008. key.raw = void 0;
  1009. key.name = 'return';
  1010. } else if (s === '\n') {
  1011. // enter, should have been called linefeed
  1012. key.name = 'enter';
  1013. } else if (s === '\t') {
  1014. // tab
  1015. key.name = 'tab';
  1016. } else if (s === '\b' || s === '\x7f' || s === '\x1b\x7f' || s === '\x1b\b') {
  1017. // backspace or ctrl+h
  1018. key.name = 'backspace';
  1019. key.meta = s.charAt(0) === '\x1b';
  1020. } else if (s === '\x1b' || s === '\x1b\x1b') {
  1021. // escape key
  1022. key.name = 'escape';
  1023. key.meta = s.length === 2;
  1024. } else if (s === ' ' || s === '\x1b ') {
  1025. key.name = 'space';
  1026. key.meta = s.length === 2;
  1027. } else if (s <= '\x1a') {
  1028. // ctrl+letter
  1029. key.name = String.fromCharCode(s.charCodeAt(0) + 'a'.charCodeAt(0) - 1);
  1030. key.ctrl = true;
  1031. } else if (s.length === 1 && s >= '0' && s <= '9') {
  1032. // number
  1033. key.name = 'number';
  1034. } else if (s.length === 1 && s >= 'a' && s <= 'z') {
  1035. // lowercase letter
  1036. key.name = s;
  1037. } else if (s.length === 1 && s >= 'A' && s <= 'Z') {
  1038. // shift+letter
  1039. key.name = s.toLowerCase();
  1040. key.shift = true;
  1041. } else if ((parts = metaKeyCodeRe.exec(s))) {
  1042. // meta+character key
  1043. key.meta = true;
  1044. key.shift = /^[A-Z]$/.test(parts[1]);
  1045. } else if ((parts = fnKeyRe.exec(s))) {
  1046. let segs = [...s];
  1047. if (segs[0] === '\u001b' && segs[1] === '\u001b') {
  1048. key.option = true;
  1049. }
  1050. // ansi escape sequence
  1051. // reassemble the key code leaving out leading \x1b's,
  1052. // the modifier key bitflag and any meaningless "1;" sequence
  1053. let code = [parts[1], parts[2], parts[4], parts[6]].filter(Boolean).join('');
  1054. let modifier = (parts[3] || parts[5] || 1) - 1;
  1055. // Parse the key modifier
  1056. key.ctrl = !!(modifier & 4);
  1057. key.meta = !!(modifier & 10);
  1058. key.shift = !!(modifier & 1);
  1059. key.code = code;
  1060. key.name = keyName[code];
  1061. key.shift = isShiftKey(code) || key.shift;
  1062. key.ctrl = isCtrlKey(code) || key.ctrl;
  1063. }
  1064. return key;
  1065. };
  1066. keypress.listen = (options = {}, onKeypress) => {
  1067. let { stdin } = options;
  1068. if (!stdin || (stdin !== process.stdin && !stdin.isTTY)) {
  1069. throw new Error('Invalid stream passed');
  1070. }
  1071. let rl = readline.createInterface({ terminal: true, input: stdin });
  1072. readline.emitKeypressEvents(stdin, rl);
  1073. let on = (buf, key) => onKeypress(buf, keypress(buf, key), rl);
  1074. let isRaw = stdin.isRaw;
  1075. if (stdin.isTTY) stdin.setRawMode(true);
  1076. stdin.on('keypress', on);
  1077. rl.resume();
  1078. let off = () => {
  1079. if (stdin.isTTY) stdin.setRawMode(isRaw);
  1080. stdin.removeListener('keypress', on);
  1081. rl.pause();
  1082. rl.close();
  1083. };
  1084. return off;
  1085. };
  1086. keypress.action = (buf, key, customActions) => {
  1087. let obj = { ...combos, ...customActions };
  1088. if (key.ctrl) {
  1089. key.action = obj.ctrl[key.name];
  1090. return key;
  1091. }
  1092. if (key.option && obj.option) {
  1093. key.action = obj.option[key.name];
  1094. return key;
  1095. }
  1096. if (key.shift) {
  1097. key.action = obj.shift[key.name];
  1098. return key;
  1099. }
  1100. key.action = obj.keys[key.name];
  1101. return key;
  1102. };
  1103. module.exports = keypress;
  1104. /***/ }),
  1105. /***/ 12786:
  1106. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1107. "use strict";
  1108. const utils = __webpack_require__(83546);
  1109. /**
  1110. * Render a placeholder value with cursor and styling based on the
  1111. * position of the cursor.
  1112. *
  1113. * @param {Object} `prompt` Prompt instance.
  1114. * @param {String} `input` Input string.
  1115. * @param {String} `initial` The initial user-provided value.
  1116. * @param {Number} `pos` Current cursor position.
  1117. * @param {Boolean} `showCursor` Render a simulated cursor using the inverse primary style.
  1118. * @return {String} Returns the styled placeholder string.
  1119. * @api public
  1120. */
  1121. module.exports = (prompt, options = {}) => {
  1122. prompt.cursorHide();
  1123. let { input = '', initial = '', pos, showCursor = true, color } = options;
  1124. let style = color || prompt.styles.placeholder;
  1125. let inverse = utils.inverse(prompt.styles.primary);
  1126. let blinker = str => inverse(prompt.styles.black(str));
  1127. let output = input;
  1128. let char = ' ';
  1129. let reverse = blinker(char);
  1130. if (prompt.blink && prompt.blink.off === true) {
  1131. blinker = str => str;
  1132. reverse = '';
  1133. }
  1134. if (showCursor && pos === 0 && initial === '' && input === '') {
  1135. return blinker(char);
  1136. }
  1137. if (showCursor && pos === 0 && (input === initial || input === '')) {
  1138. return blinker(initial[0]) + style(initial.slice(1));
  1139. }
  1140. initial = utils.isPrimitive(initial) ? `${initial}` : '';
  1141. input = utils.isPrimitive(input) ? `${input}` : '';
  1142. let placeholder = initial && initial.startsWith(input) && initial !== input;
  1143. let cursor = placeholder ? blinker(initial[input.length]) : reverse;
  1144. if (pos !== input.length && showCursor === true) {
  1145. output = input.slice(0, pos) + blinker(input[pos]) + input.slice(pos + 1);
  1146. cursor = '';
  1147. }
  1148. if (showCursor === false) {
  1149. cursor = '';
  1150. }
  1151. if (placeholder) {
  1152. let raw = prompt.styles.unstyle(output + cursor);
  1153. return output + cursor + style(initial.slice(raw.length));
  1154. }
  1155. return output + cursor;
  1156. };
  1157. /***/ }),
  1158. /***/ 232:
  1159. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1160. "use strict";
  1161. const Events = __webpack_require__(28614);
  1162. const colors = __webpack_require__(53692);
  1163. const keypress = __webpack_require__(28914);
  1164. const timer = __webpack_require__(33940);
  1165. const State = __webpack_require__(36873);
  1166. const theme = __webpack_require__(39227);
  1167. const utils = __webpack_require__(83546);
  1168. const ansi = __webpack_require__(94907);
  1169. /**
  1170. * Base class for creating a new Prompt.
  1171. * @param {Object} `options` Question object.
  1172. */
  1173. class Prompt extends Events {
  1174. constructor(options = {}) {
  1175. super();
  1176. this.name = options.name;
  1177. this.type = options.type;
  1178. this.options = options;
  1179. theme(this);
  1180. timer(this);
  1181. this.state = new State(this);
  1182. this.initial = [options.initial, options.default].find(v => v != null);
  1183. this.stdout = options.stdout || process.stdout;
  1184. this.stdin = options.stdin || process.stdin;
  1185. this.scale = options.scale || 1;
  1186. this.term = this.options.term || process.env.TERM_PROGRAM;
  1187. this.margin = margin(this.options.margin);
  1188. this.setMaxListeners(0);
  1189. setOptions(this);
  1190. }
  1191. async keypress(input, event = {}) {
  1192. this.keypressed = true;
  1193. let key = keypress.action(input, keypress(input, event), this.options.actions);
  1194. this.state.keypress = key;
  1195. this.emit('keypress', input, key);
  1196. this.emit('state', this.state.clone());
  1197. let fn = this.options[key.action] || this[key.action] || this.dispatch;
  1198. if (typeof fn === 'function') {
  1199. return await fn.call(this, input, key);
  1200. }
  1201. this.alert();
  1202. }
  1203. alert() {
  1204. delete this.state.alert;
  1205. if (this.options.show === false) {
  1206. this.emit('alert');
  1207. } else {
  1208. this.stdout.write(ansi.code.beep);
  1209. }
  1210. }
  1211. cursorHide() {
  1212. this.stdout.write(ansi.cursor.hide());
  1213. utils.onExit(() => this.cursorShow());
  1214. }
  1215. cursorShow() {
  1216. this.stdout.write(ansi.cursor.show());
  1217. }
  1218. write(str) {
  1219. if (!str) return;
  1220. if (this.stdout && this.state.show !== false) {
  1221. this.stdout.write(str);
  1222. }
  1223. this.state.buffer += str;
  1224. }
  1225. clear(lines = 0) {
  1226. let buffer = this.state.buffer;
  1227. this.state.buffer = '';
  1228. if ((!buffer && !lines) || this.options.show === false) return;
  1229. this.stdout.write(ansi.cursor.down(lines) + ansi.clear(buffer, this.width));
  1230. }
  1231. restore() {
  1232. if (this.state.closed || this.options.show === false) return;
  1233. let { prompt, after, rest } = this.sections();
  1234. let { cursor, initial = '', input = '', value = '' } = this;
  1235. let size = this.state.size = rest.length;
  1236. let state = { after, cursor, initial, input, prompt, size, value };
  1237. let codes = ansi.cursor.restore(state);
  1238. if (codes) {
  1239. this.stdout.write(codes);
  1240. }
  1241. }
  1242. sections() {
  1243. let { buffer, input, prompt } = this.state;
  1244. prompt = colors.unstyle(prompt);
  1245. let buf = colors.unstyle(buffer);
  1246. let idx = buf.indexOf(prompt);
  1247. let header = buf.slice(0, idx);
  1248. let rest = buf.slice(idx);
  1249. let lines = rest.split('\n');
  1250. let first = lines[0];
  1251. let last = lines[lines.length - 1];
  1252. let promptLine = prompt + (input ? ' ' + input : '');
  1253. let len = promptLine.length;
  1254. let after = len < first.length ? first.slice(len + 1) : '';
  1255. return { header, prompt: first, after, rest: lines.slice(1), last };
  1256. }
  1257. async submit() {
  1258. this.state.submitted = true;
  1259. this.state.validating = true;
  1260. // this will only be called when the prompt is directly submitted
  1261. // without initializing, i.e. when the prompt is skipped, etc. Otherwize,
  1262. // "options.onSubmit" is will be handled by the "initialize()" method.
  1263. if (this.options.onSubmit) {
  1264. await this.options.onSubmit.call(this, this.name, this.value, this);
  1265. }
  1266. let result = this.state.error || await this.validate(this.value, this.state);
  1267. if (result !== true) {
  1268. let error = '\n' + this.symbols.pointer + ' ';
  1269. if (typeof result === 'string') {
  1270. error += result.trim();
  1271. } else {
  1272. error += 'Invalid input';
  1273. }
  1274. this.state.error = '\n' + this.styles.danger(error);
  1275. this.state.submitted = false;
  1276. await this.render();
  1277. await this.alert();
  1278. this.state.validating = false;
  1279. this.state.error = void 0;
  1280. return;
  1281. }
  1282. this.state.validating = false;
  1283. await this.render();
  1284. await this.close();
  1285. this.value = await this.result(this.value);
  1286. this.emit('submit', this.value);
  1287. }
  1288. async cancel(err) {
  1289. this.state.cancelled = this.state.submitted = true;
  1290. await this.render();
  1291. await this.close();
  1292. if (typeof this.options.onCancel === 'function') {
  1293. await this.options.onCancel.call(this, this.name, this.value, this);
  1294. }
  1295. this.emit('cancel', await this.error(err));
  1296. }
  1297. async close() {
  1298. this.state.closed = true;
  1299. try {
  1300. let sections = this.sections();
  1301. let lines = Math.ceil(sections.prompt.length / this.width);
  1302. if (sections.rest) {
  1303. this.write(ansi.cursor.down(sections.rest.length));
  1304. }
  1305. this.write('\n'.repeat(lines));
  1306. } catch (err) { /* do nothing */ }
  1307. this.emit('close');
  1308. }
  1309. start() {
  1310. if (!this.stop && this.options.show !== false) {
  1311. this.stop = keypress.listen(this, this.keypress.bind(this));
  1312. this.once('close', this.stop);
  1313. }
  1314. }
  1315. async skip() {
  1316. this.skipped = this.options.skip === true;
  1317. if (typeof this.options.skip === 'function') {
  1318. this.skipped = await this.options.skip.call(this, this.name, this.value);
  1319. }
  1320. return this.skipped;
  1321. }
  1322. async initialize() {
  1323. let { format, options, result } = this;
  1324. this.format = () => format.call(this, this.value);
  1325. this.result = () => result.call(this, this.value);
  1326. if (typeof options.initial === 'function') {
  1327. this.initial = await options.initial.call(this, this);
  1328. }
  1329. if (typeof options.onRun === 'function') {
  1330. await options.onRun.call(this, this);
  1331. }
  1332. // if "options.onSubmit" is defined, we wrap the "submit" method to guarantee
  1333. // that "onSubmit" will always called first thing inside the submit
  1334. // method, regardless of how it's handled in inheriting prompts.
  1335. if (typeof options.onSubmit === 'function') {
  1336. let onSubmit = options.onSubmit.bind(this);
  1337. let submit = this.submit.bind(this);
  1338. delete this.options.onSubmit;
  1339. this.submit = async() => {
  1340. await onSubmit(this.name, this.value, this);
  1341. return submit();
  1342. };
  1343. }
  1344. await this.start();
  1345. await this.render();
  1346. }
  1347. render() {
  1348. throw new Error('expected prompt to have a custom render method');
  1349. }
  1350. run() {
  1351. return new Promise(async(resolve, reject) => {
  1352. this.once('submit', resolve);
  1353. this.once('cancel', reject);
  1354. if (await this.skip()) {
  1355. this.render = () => {};
  1356. return this.submit();
  1357. }
  1358. await this.initialize();
  1359. this.emit('run');
  1360. });
  1361. }
  1362. async element(name, choice, i) {
  1363. let { options, state, symbols, timers } = this;
  1364. let timer = timers && timers[name];
  1365. state.timer = timer;
  1366. let value = options[name] || state[name] || symbols[name];
  1367. let val = choice && choice[name] != null ? choice[name] : await value;
  1368. if (val === '') return val;
  1369. let res = await this.resolve(val, state, choice, i);
  1370. if (!res && choice && choice[name]) {
  1371. return this.resolve(value, state, choice, i);
  1372. }
  1373. return res;
  1374. }
  1375. async prefix() {
  1376. let element = await this.element('prefix') || this.symbols;
  1377. let timer = this.timers && this.timers.prefix;
  1378. let state = this.state;
  1379. state.timer = timer;
  1380. if (utils.isObject(element)) element = element[state.status] || element.pending;
  1381. if (!utils.hasColor(element)) {
  1382. let style = this.styles[state.status] || this.styles.pending;
  1383. return style(element);
  1384. }
  1385. return element;
  1386. }
  1387. async message() {
  1388. let message = await this.element('message');
  1389. if (!utils.hasColor(message)) {
  1390. return this.styles.strong(message);
  1391. }
  1392. return message;
  1393. }
  1394. async separator() {
  1395. let element = await this.element('separator') || this.symbols;
  1396. let timer = this.timers && this.timers.separator;
  1397. let state = this.state;
  1398. state.timer = timer;
  1399. let value = element[state.status] || element.pending || state.separator;
  1400. let ele = await this.resolve(value, state);
  1401. if (utils.isObject(ele)) ele = ele[state.status] || ele.pending;
  1402. if (!utils.hasColor(ele)) {
  1403. return this.styles.muted(ele);
  1404. }
  1405. return ele;
  1406. }
  1407. async pointer(choice, i) {
  1408. let val = await this.element('pointer', choice, i);
  1409. if (typeof val === 'string' && utils.hasColor(val)) {
  1410. return val;
  1411. }
  1412. if (val) {
  1413. let styles = this.styles;
  1414. let focused = this.index === i;
  1415. let style = focused ? styles.primary : val => val;
  1416. let ele = await this.resolve(val[focused ? 'on' : 'off'] || val, this.state);
  1417. let styled = !utils.hasColor(ele) ? style(ele) : ele;
  1418. return focused ? styled : ' '.repeat(ele.length);
  1419. }
  1420. }
  1421. async indicator(choice, i) {
  1422. let val = await this.element('indicator', choice, i);
  1423. if (typeof val === 'string' && utils.hasColor(val)) {
  1424. return val;
  1425. }
  1426. if (val) {
  1427. let styles = this.styles;
  1428. let enabled = choice.enabled === true;
  1429. let style = enabled ? styles.success : styles.dark;
  1430. let ele = val[enabled ? 'on' : 'off'] || val;
  1431. return !utils.hasColor(ele) ? style(ele) : ele;
  1432. }
  1433. return '';
  1434. }
  1435. body() {
  1436. return null;
  1437. }
  1438. footer() {
  1439. if (this.state.status === 'pending') {
  1440. return this.element('footer');
  1441. }
  1442. }
  1443. header() {
  1444. if (this.state.status === 'pending') {
  1445. return this.element('header');
  1446. }
  1447. }
  1448. async hint() {
  1449. if (this.state.status === 'pending' && !this.isValue(this.state.input)) {
  1450. let hint = await this.element('hint');
  1451. if (!utils.hasColor(hint)) {
  1452. return this.styles.muted(hint);
  1453. }
  1454. return hint;
  1455. }
  1456. }
  1457. error(err) {
  1458. return !this.state.submitted ? (err || this.state.error) : '';
  1459. }
  1460. format(value) {
  1461. return value;
  1462. }
  1463. result(value) {
  1464. return value;
  1465. }
  1466. validate(value) {
  1467. if (this.options.required === true) {
  1468. return this.isValue(value);
  1469. }
  1470. return true;
  1471. }
  1472. isValue(value) {
  1473. return value != null && value !== '';
  1474. }
  1475. resolve(value, ...args) {
  1476. return utils.resolve(this, value, ...args);
  1477. }
  1478. get base() {
  1479. return Prompt.prototype;
  1480. }
  1481. get style() {
  1482. return this.styles[this.state.status];
  1483. }
  1484. get height() {
  1485. return this.options.rows || utils.height(this.stdout, 25);
  1486. }
  1487. get width() {
  1488. return this.options.columns || utils.width(this.stdout, 80);
  1489. }
  1490. get size() {
  1491. return { width: this.width, height: this.height };
  1492. }
  1493. set cursor(value) {
  1494. this.state.cursor = value;
  1495. }
  1496. get cursor() {
  1497. return this.state.cursor;
  1498. }
  1499. set input(value) {
  1500. this.state.input = value;
  1501. }
  1502. get input() {
  1503. return this.state.input;
  1504. }
  1505. set value(value) {
  1506. this.state.value = value;
  1507. }
  1508. get value() {
  1509. let { input, value } = this.state;
  1510. let result = [value, input].find(this.isValue.bind(this));
  1511. return this.isValue(result) ? result : this.initial;
  1512. }
  1513. static get prompt() {
  1514. return options => new this(options).run();
  1515. }
  1516. }
  1517. function setOptions(prompt) {
  1518. let isValidKey = key => {
  1519. return prompt[key] === void 0 || typeof prompt[key] === 'function';
  1520. };
  1521. let ignore = [
  1522. 'actions',
  1523. 'choices',
  1524. 'initial',
  1525. 'margin',
  1526. 'roles',
  1527. 'styles',
  1528. 'symbols',
  1529. 'theme',
  1530. 'timers',
  1531. 'value'
  1532. ];
  1533. let ignoreFn = [
  1534. 'body',
  1535. 'footer',
  1536. 'error',
  1537. 'header',
  1538. 'hint',
  1539. 'indicator',
  1540. 'message',
  1541. 'prefix',
  1542. 'separator',
  1543. 'skip'
  1544. ];
  1545. for (let key of Object.keys(prompt.options)) {
  1546. if (ignore.includes(key)) continue;
  1547. if (/^on[A-Z]/.test(key)) continue;
  1548. let option = prompt.options[key];
  1549. if (typeof option === 'function' && isValidKey(key)) {
  1550. if (!ignoreFn.includes(key)) {
  1551. prompt[key] = option.bind(prompt);
  1552. }
  1553. } else if (typeof prompt[key] !== 'function') {
  1554. prompt[key] = option;
  1555. }
  1556. }
  1557. }
  1558. function margin(value) {
  1559. if (typeof value === 'number') {
  1560. value = [value, value, value, value];
  1561. }
  1562. let arr = [].concat(value || []);
  1563. let pad = i => i % 2 === 0 ? '\n' : ' ';
  1564. let res = [];
  1565. for (let i = 0; i < 4; i++) {
  1566. let char = pad(i);
  1567. if (arr[i]) {
  1568. res.push(char.repeat(arr[i]));
  1569. } else {
  1570. res.push('');
  1571. }
  1572. }
  1573. return res;
  1574. }
  1575. module.exports = Prompt;
  1576. /***/ }),
  1577. /***/ 89317:
  1578. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1579. "use strict";
  1580. const Select = __webpack_require__(13466);
  1581. const highlight = (input, color) => {
  1582. let val = input.toLowerCase();
  1583. return str => {
  1584. let s = str.toLowerCase();
  1585. let i = s.indexOf(val);
  1586. let colored = color(str.slice(i, i + val.length));
  1587. return i >= 0 ? str.slice(0, i) + colored + str.slice(i + val.length) : str;
  1588. };
  1589. };
  1590. class AutoComplete extends Select {
  1591. constructor(options) {
  1592. super(options);
  1593. this.cursorShow();
  1594. }
  1595. moveCursor(n) {
  1596. this.state.cursor += n;
  1597. }
  1598. dispatch(ch) {
  1599. return this.append(ch);
  1600. }
  1601. space(ch) {
  1602. return this.options.multiple ? super.space(ch) : this.append(ch);
  1603. }
  1604. append(ch) {
  1605. let { cursor, input } = this.state;
  1606. this.input = input.slice(0, cursor) + ch + input.slice(cursor);
  1607. this.moveCursor(1);
  1608. return this.complete();
  1609. }
  1610. delete() {
  1611. let { cursor, input } = this.state;
  1612. if (!input) return this.alert();
  1613. this.input = input.slice(0, cursor - 1) + input.slice(cursor);
  1614. this.moveCursor(-1);
  1615. return this.complete();
  1616. }
  1617. deleteForward() {
  1618. let { cursor, input } = this.state;
  1619. if (input[cursor] === void 0) return this.alert();
  1620. this.input = `${input}`.slice(0, cursor) + `${input}`.slice(cursor + 1);
  1621. return this.complete();
  1622. }
  1623. number(ch) {
  1624. return this.append(ch);
  1625. }
  1626. async complete() {
  1627. this.completing = true;
  1628. this.choices = await this.suggest(this.input, this.state._choices);
  1629. this.state.limit = void 0; // allow getter/setter to reset limit
  1630. this.index = Math.min(Math.max(this.visible.length - 1, 0), this.index);
  1631. await this.render();
  1632. this.completing = false;
  1633. }
  1634. suggest(input = this.input, choices = this.state._choices) {
  1635. if (typeof this.options.suggest === 'function') {
  1636. return this.options.suggest.call(this, input, choices);
  1637. }
  1638. let str = input.toLowerCase();
  1639. return choices.filter(ch => ch.message.toLowerCase().includes(str));
  1640. }
  1641. pointer() {
  1642. return '';
  1643. }
  1644. format() {
  1645. if (!this.focused) return this.input;
  1646. if (this.options.multiple && this.state.submitted) {
  1647. return this.selected.map(ch => this.styles.primary(ch.message)).join(', ');
  1648. }
  1649. if (this.state.submitted) {
  1650. let value = this.value = this.input = this.focused.value;
  1651. return this.styles.primary(value);
  1652. }
  1653. return this.input;
  1654. }
  1655. async render() {
  1656. if (this.state.status !== 'pending') return super.render();
  1657. let style = this.options.highlight
  1658. ? this.options.highlight.bind(this)
  1659. : this.styles.placeholder;
  1660. let color = highlight(this.input, style);
  1661. let choices = this.choices;
  1662. this.choices = choices.map(ch => ({ ...ch, message: color(ch.message) }));
  1663. await super.render();
  1664. this.choices = choices;
  1665. }
  1666. submit() {
  1667. if (this.options.multiple) {
  1668. this.value = this.selected.map(ch => ch.name);
  1669. }
  1670. return super.submit();
  1671. }
  1672. }
  1673. module.exports = AutoComplete;
  1674. /***/ }),
  1675. /***/ 7186:
  1676. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1677. "use strict";
  1678. const AuthPrompt = __webpack_require__(66926);
  1679. function defaultAuthenticate(value, state) {
  1680. if (value.username === this.options.username && value.password === this.options.password) {
  1681. return true;
  1682. }
  1683. return false;
  1684. }
  1685. const factory = (authenticate = defaultAuthenticate) => {
  1686. const choices = [
  1687. { name: 'username', message: 'username' },
  1688. {
  1689. name: 'password',
  1690. message: 'password',
  1691. format(input) {
  1692. if (this.options.showPassword) {
  1693. return input;
  1694. }
  1695. let color = this.state.submitted ? this.styles.primary : this.styles.muted;
  1696. return color(this.symbols.asterisk.repeat(input.length));
  1697. }
  1698. }
  1699. ];
  1700. class BasicAuthPrompt extends AuthPrompt.create(authenticate) {
  1701. constructor(options) {
  1702. super({ ...options, choices });
  1703. }
  1704. static create(authenticate) {
  1705. return factory(authenticate);
  1706. }
  1707. }
  1708. return BasicAuthPrompt;
  1709. };
  1710. module.exports = factory();
  1711. /***/ }),
  1712. /***/ 31291:
  1713. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1714. "use strict";
  1715. const BooleanPrompt = __webpack_require__(23838);
  1716. class ConfirmPrompt extends BooleanPrompt {
  1717. constructor(options) {
  1718. super(options);
  1719. this.default = this.options.default || (this.initial ? '(Y/n)' : '(y/N)');
  1720. }
  1721. }
  1722. module.exports = ConfirmPrompt;
  1723. /***/ }),
  1724. /***/ 50848:
  1725. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1726. "use strict";
  1727. const Select = __webpack_require__(13466);
  1728. const Form = __webpack_require__(21826);
  1729. const form = Form.prototype;
  1730. class Editable extends Select {
  1731. constructor(options) {
  1732. super({ ...options, multiple: true });
  1733. this.align = [this.options.align, 'left'].find(v => v != null);
  1734. this.emptyError = '';
  1735. this.values = {};
  1736. }
  1737. dispatch(char, key) {
  1738. let choice = this.focused;
  1739. let parent = choice.parent || {};
  1740. if (!choice.editable && !parent.editable) {
  1741. if (char === 'a' || char === 'i') return super[char]();
  1742. }
  1743. return form.dispatch.call(this, char, key);
  1744. }
  1745. append(char, key) {
  1746. return form.append.call(this, char, key);
  1747. }
  1748. delete(char, key) {
  1749. return form.delete.call(this, char, key);
  1750. }
  1751. space(char) {
  1752. return this.focused.editable ? this.append(char) : super.space();
  1753. }
  1754. number(char) {
  1755. return this.focused.editable ? this.append(char) : super.number(char);
  1756. }
  1757. next() {
  1758. return this.focused.editable ? form.next.call(this) : super.next();
  1759. }
  1760. prev() {
  1761. return this.focused.editable ? form.prev.call(this) : super.prev();
  1762. }
  1763. async indicator(choice, i) {
  1764. let symbol = choice.indicator || '';
  1765. let value = choice.editable ? symbol : super.indicator(choice, i);
  1766. return await this.resolve(value, this.state, choice, i) || '';
  1767. }
  1768. indent(choice) {
  1769. return choice.role === 'heading' ? '' : (choice.editable ? ' ' : ' ');
  1770. }
  1771. async renderChoice(choice, i) {
  1772. choice.indent = '';
  1773. if (choice.editable) return form.renderChoice.call(this, choice, i);
  1774. return super.renderChoice(choice, i);
  1775. }
  1776. error() {
  1777. return '';
  1778. }
  1779. footer() {
  1780. return this.state.error;
  1781. }
  1782. async validate() {
  1783. let result = true;
  1784. for (let choice of this.choices) {
  1785. if (typeof choice.validate !== 'function') {
  1786. continue;
  1787. }
  1788. if (choice.role === 'heading') {
  1789. continue;
  1790. }
  1791. let val = choice.parent ? this.value[choice.parent.name] : this.value;
  1792. if (choice.editable) {
  1793. val = choice.value === choice.name ? choice.initial || '' : choice.value;
  1794. } else if (!this.isDisabled(choice)) {
  1795. val = choice.enabled === true;
  1796. }
  1797. result = await choice.validate(val, this.state);
  1798. if (result !== true) {
  1799. break;
  1800. }
  1801. }
  1802. if (result !== true) {
  1803. this.state.error = typeof result === 'string' ? result : 'Invalid Input';
  1804. }
  1805. return result;
  1806. }
  1807. submit() {
  1808. if (this.focused.newChoice === true) return super.submit();
  1809. if (this.choices.some(ch => ch.newChoice)) {
  1810. return this.alert();
  1811. }
  1812. this.value = {};
  1813. for (let choice of this.choices) {
  1814. let val = choice.parent ? this.value[choice.parent.name] : this.value;
  1815. if (choice.role === 'heading') {
  1816. this.value[choice.name] = {};
  1817. continue;
  1818. }
  1819. if (choice.editable) {
  1820. val[choice.name] = choice.value === choice.name
  1821. ? (choice.initial || '')
  1822. : choice.value;
  1823. } else if (!this.isDisabled(choice)) {
  1824. val[choice.name] = choice.enabled === true;
  1825. }
  1826. }
  1827. return this.base.submit.call(this);
  1828. }
  1829. }
  1830. module.exports = Editable;
  1831. /***/ }),
  1832. /***/ 21826:
  1833. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1834. "use strict";
  1835. const colors = __webpack_require__(53692);
  1836. const SelectPrompt = __webpack_require__(13466);
  1837. const placeholder = __webpack_require__(12786);
  1838. class FormPrompt extends SelectPrompt {
  1839. constructor(options) {
  1840. super({ ...options, multiple: true });
  1841. this.type = 'form';
  1842. this.initial = this.options.initial;
  1843. this.align = [this.options.align, 'right'].find(v => v != null);
  1844. this.emptyError = '';
  1845. this.values = {};
  1846. }
  1847. async reset(first) {
  1848. await super.reset();
  1849. if (first === true) this._index = this.index;
  1850. this.index = this._index;
  1851. this.values = {};
  1852. this.choices.forEach(choice => choice.reset && choice.reset());
  1853. return this.render();
  1854. }
  1855. dispatch(char) {
  1856. return !!char && this.append(char);
  1857. }
  1858. append(char) {
  1859. let choice = this.focused;
  1860. if (!choice) return this.alert();
  1861. let { cursor, input } = choice;
  1862. choice.value = choice.input = input.slice(0, cursor) + char + input.slice(cursor);
  1863. choice.cursor++;
  1864. return this.render();
  1865. }
  1866. delete() {
  1867. let choice = this.focused;
  1868. if (!choice || choice.cursor <= 0) return this.alert();
  1869. let { cursor, input } = choice;
  1870. choice.value = choice.input = input.slice(0, cursor - 1) + input.slice(cursor);
  1871. choice.cursor--;
  1872. return this.render();
  1873. }
  1874. deleteForward() {
  1875. let choice = this.focused;
  1876. if (!choice) return this.alert();
  1877. let { cursor, input } = choice;
  1878. if (input[cursor] === void 0) return this.alert();
  1879. let str = `${input}`.slice(0, cursor) + `${input}`.slice(cursor + 1);
  1880. choice.value = choice.input = str;
  1881. return this.render();
  1882. }
  1883. right() {
  1884. let choice = this.focused;
  1885. if (!choice) return this.alert();
  1886. if (choice.cursor >= choice.input.length) return this.alert();
  1887. choice.cursor++;
  1888. return this.render();
  1889. }
  1890. left() {
  1891. let choice = this.focused;
  1892. if (!choice) return this.alert();
  1893. if (choice.cursor <= 0) return this.alert();
  1894. choice.cursor--;
  1895. return this.render();
  1896. }
  1897. space(ch, key) {
  1898. return this.dispatch(ch, key);
  1899. }
  1900. number(ch, key) {
  1901. return this.dispatch(ch, key);
  1902. }
  1903. next() {
  1904. let ch = this.focused;
  1905. if (!ch) return this.alert();
  1906. let { initial, input } = ch;
  1907. if (initial && initial.startsWith(input) && input !== initial) {
  1908. ch.value = ch.input = initial;
  1909. ch.cursor = ch.value.length;
  1910. return this.render();
  1911. }
  1912. return super.next();
  1913. }
  1914. prev() {
  1915. let ch = this.focused;
  1916. if (!ch) return this.alert();
  1917. if (ch.cursor === 0) return super.prev();
  1918. ch.value = ch.input = '';
  1919. ch.cursor = 0;
  1920. return this.render();
  1921. }
  1922. separator() {
  1923. return '';
  1924. }
  1925. format(value) {
  1926. return !this.state.submitted ? super.format(value) : '';
  1927. }
  1928. pointer() {
  1929. return '';
  1930. }
  1931. indicator(choice) {
  1932. return choice.input ? '⦿' : '⊙';
  1933. }
  1934. async choiceSeparator(choice, i) {
  1935. let sep = await this.resolve(choice.separator, this.state, choice, i) || ':';
  1936. return sep ? ' ' + this.styles.disabled(sep) : '';
  1937. }
  1938. async renderChoice(choice, i) {
  1939. await this.onChoice(choice, i);
  1940. let { state, styles } = this;
  1941. let { cursor, initial = '', name, hint, input = '' } = choice;
  1942. let { muted, submitted, primary, danger } = styles;
  1943. let help = hint;
  1944. let focused = this.index === i;
  1945. let validate = choice.validate || (() => true);
  1946. let sep = await this.choiceSeparator(choice, i);
  1947. let msg = choice.message;
  1948. if (this.align === 'right') msg = msg.padStart(this.longest + 1, ' ');
  1949. if (this.align === 'left') msg = msg.padEnd(this.longest + 1, ' ');
  1950. // re-populate the form values (answers) object
  1951. let value = this.values[name] = (input || initial);
  1952. let color = input ? 'success' : 'dark';
  1953. if ((await validate.call(choice, value, this.state)) !== true) {
  1954. color = 'danger';
  1955. }
  1956. let style = styles[color];
  1957. let indicator = style(await this.indicator(choice, i)) + (choice.pad || '');
  1958. let indent = this.indent(choice);
  1959. let line = () => [indent, indicator, msg + sep, input, help].filter(Boolean).join(' ');
  1960. if (state.submitted) {
  1961. msg = colors.unstyle(msg);
  1962. input = submitted(input);
  1963. help = '';
  1964. return line();
  1965. }
  1966. if (choice.format) {
  1967. input = await choice.format.call(this, input, choice, i);
  1968. } else {
  1969. let color = this.styles.muted;
  1970. let options = { input, initial, pos: cursor, showCursor: focused, color };
  1971. input = placeholder(this, options);
  1972. }
  1973. if (!this.isValue(input)) {
  1974. input = this.styles.muted(this.symbols.ellipsis);
  1975. }
  1976. if (choice.result) {
  1977. this.values[name] = await choice.result.call(this, value, choice, i);
  1978. }
  1979. if (focused) {
  1980. msg = primary(msg);
  1981. }
  1982. if (choice.error) {
  1983. input += (input ? ' ' : '') + danger(choice.error.trim());
  1984. } else if (choice.hint) {
  1985. input += (input ? ' ' : '') + muted(choice.hint.trim());
  1986. }
  1987. return line();
  1988. }
  1989. async submit() {
  1990. this.value = this.values;
  1991. return super.base.submit.call(this);
  1992. }
  1993. }
  1994. module.exports = FormPrompt;
  1995. /***/ }),
  1996. /***/ 29594:
  1997. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  1998. "use strict";
  1999. const utils = __webpack_require__(83546);
  2000. const define = (key, fn) => {
  2001. utils.defineExport(exports, key, fn);
  2002. utils.defineExport(exports, key.toLowerCase(), fn);
  2003. };
  2004. define('AutoComplete', () => __webpack_require__(89317));
  2005. define('BasicAuth', () => __webpack_require__(7186));
  2006. define('Confirm', () => __webpack_require__(31291));
  2007. define('Editable', () => __webpack_require__(50848));
  2008. define('Form', () => __webpack_require__(21826));
  2009. define('Input', () => __webpack_require__(66719));
  2010. define('Invisible', () => __webpack_require__(99822));
  2011. define('List', () => __webpack_require__(16795));
  2012. define('MultiSelect', () => __webpack_require__(91056));
  2013. define('Numeral', () => __webpack_require__(17403));
  2014. define('Password', () => __webpack_require__(46847));
  2015. define('Scale', () => __webpack_require__(17813));
  2016. define('Select', () => __webpack_require__(13466));
  2017. define('Snippet', () => __webpack_require__(19451));
  2018. define('Sort', () => __webpack_require__(7144));
  2019. define('Survey', () => __webpack_require__(83755));
  2020. define('Text', () => __webpack_require__(5781));
  2021. define('Toggle', () => __webpack_require__(10653));
  2022. define('Quiz', () => __webpack_require__(92249));
  2023. /***/ }),
  2024. /***/ 66719:
  2025. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  2026. "use strict";
  2027. const Prompt = __webpack_require__(43391);
  2028. const completer = __webpack_require__(73736);
  2029. class Input extends Prompt {
  2030. constructor(options) {
  2031. super(options);
  2032. let history = this.options.history;
  2033. if (history && history.store) {
  2034. let initial = history.values || this.initial;
  2035. this.autosave = !!history.autosave;
  2036. this.store = history.store;
  2037. this.data = this.store.get('values') || { past: [], present: initial };
  2038. this.initial = this.data.present || this.data.past[this.data.past.length - 1];
  2039. }
  2040. }
  2041. completion(action) {
  2042. if (!this.store) return this.alert();
  2043. this.data = completer(action, this.data, this.input);
  2044. if (!this.data.present) return this.alert();
  2045. this.input = this.data.present;
  2046. this.cursor = this.input.length;
  2047. return this.render();
  2048. }
  2049. altUp() {
  2050. return this.completion('prev');
  2051. }
  2052. altDown() {
  2053. return this.completion('next');
  2054. }
  2055. prev() {
  2056. this.save();
  2057. return super.prev();
  2058. }
  2059. save() {
  2060. if (!this.store) return;
  2061. this.data = completer('save', this.data, this.input);
  2062. this.store.set('values', this.data);
  2063. }
  2064. submit() {
  2065. if (this.store && this.autosave === true) {
  2066. this.save();
  2067. }
  2068. return super.submit();
  2069. }
  2070. }
  2071. module.exports = Input;
  2072. /***/ }),
  2073. /***/ 99822:
  2074. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  2075. "use strict";
  2076. const StringPrompt = __webpack_require__(43391);
  2077. class InvisiblePrompt extends StringPrompt {
  2078. format() {
  2079. return '';
  2080. }
  2081. }
  2082. module.exports = InvisiblePrompt;
  2083. /***/ }),
  2084. /***/ 16795:
  2085. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  2086. "use strict";
  2087. const StringPrompt = __webpack_require__(43391);
  2088. class ListPrompt extends StringPrompt {
  2089. constructor(options = {}) {
  2090. super(options);
  2091. this.sep = this.options.separator || /, */;
  2092. this.initial = options.initial || '';
  2093. }
  2094. split(input = this.value) {
  2095. return input ? String(input).split(this.sep) : [];
  2096. }
  2097. format() {
  2098. let style = this.state.submitted ? this.styles.primary : val => val;
  2099. return this.list.map(style).join(', ');
  2100. }
  2101. async submit(value) {
  2102. let result = this.state.error || await this.validate(this.list, this.state);
  2103. if (result !== true) {
  2104. this.state.error = result;
  2105. return super.submit();
  2106. }
  2107. this.value = this.list;
  2108. return super.submit();
  2109. }
  2110. get list() {
  2111. return this.split();
  2112. }
  2113. }
  2114. module.exports = ListPrompt;
  2115. /***/ }),
  2116. /***/ 91056:
  2117. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  2118. "use strict";
  2119. const Select = __webpack_require__(13466);
  2120. class MultiSelect extends Select {
  2121. constructor(options) {
  2122. super({ ...options, multiple: true });
  2123. }
  2124. }
  2125. module.exports = MultiSelect;
  2126. /***/ }),
  2127. /***/ 17403:
  2128. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  2129. module.exports = __webpack_require__(45376);
  2130. /***/ }),
  2131. /***/ 46847:
  2132. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  2133. "use strict";
  2134. const StringPrompt = __webpack_require__(43391);
  2135. class PasswordPrompt extends StringPrompt {
  2136. constructor(options) {
  2137. super(options);
  2138. this.cursorShow();
  2139. }
  2140. format(input = this.input) {
  2141. if (!this.keypressed) return '';
  2142. let color = this.state.submitted ? this.styles.primary : this.styles.muted;
  2143. return color(this.symbols.asterisk.repeat(input.length));
  2144. }
  2145. }
  2146. module.exports = PasswordPrompt;
  2147. /***/ }),
  2148. /***/ 92249:
  2149. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  2150. "use strict";
  2151. const SelectPrompt = __webpack_require__(13466);
  2152. class Quiz extends SelectPrompt {
  2153. constructor(options) {
  2154. super(options);
  2155. if (typeof this.options.correctChoice !== 'number' || this.options.correctChoice < 0) {
  2156. throw new Error('Please specify the index of the correct answer from the list of choices');
  2157. }
  2158. }
  2159. async toChoices(value, parent) {
  2160. let choices = await super.toChoices(value, parent);
  2161. if (choices.length < 2) {
  2162. throw new Error('Please give at least two choices to the user');
  2163. }
  2164. if (this.options.correctChoice > choices.length) {
  2165. throw new Error('Please specify the index of the correct answer from the list of choices');
  2166. }
  2167. return choices;
  2168. }
  2169. check(state) {
  2170. return state.index === this.options.correctChoice;
  2171. }
  2172. async result(selected) {
  2173. return {
  2174. selectedAnswer: selected,
  2175. correctAnswer: this.options.choices[this.options.correctChoice].value,
  2176. correct: await this.check(this.state)
  2177. };
  2178. }
  2179. }
  2180. module.exports = Quiz;
  2181. /***/ }),
  2182. /***/ 17813:
  2183. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  2184. "use strict";
  2185. const colors = __webpack_require__(53692);
  2186. const ArrayPrompt = __webpack_require__(98575);
  2187. const utils = __webpack_require__(83546);
  2188. class LikertScale extends ArrayPrompt {
  2189. constructor(options = {}) {
  2190. super(options);
  2191. this.widths = [].concat(options.messageWidth || 50);
  2192. this.align = [].concat(options.align || 'left');
  2193. this.linebreak = options.linebreak || false;
  2194. this.edgeLength = options.edgeLength || 3;
  2195. this.newline = options.newline || '\n ';
  2196. let start = options.startNumber || 1;
  2197. if (typeof this.scale === 'number') {
  2198. this.scaleKey = false;
  2199. this.scale = Array(this.scale).fill(0).map((v, i) => ({ name: i + start }));
  2200. }
  2201. }
  2202. async reset() {
  2203. this.tableized = false;
  2204. await super.reset();
  2205. return this.render();
  2206. }
  2207. tableize() {
  2208. if (this.tableized === true) return;
  2209. this.tableized = true;
  2210. let longest = 0;
  2211. for (let ch of this.choices) {
  2212. longest = Math.max(longest, ch.message.length);
  2213. ch.scaleIndex = ch.initial || 2;
  2214. ch.scale = [];
  2215. for (let i = 0; i < this.scale.length; i++) {
  2216. ch.scale.push({ index: i });
  2217. }
  2218. }
  2219. this.widths[0] = Math.min(this.widths[0], longest + 3);
  2220. }
  2221. async dispatch(s, key) {
  2222. if (this.multiple) {
  2223. return this[key.name] ? await this[key.name](s, key) : await super.dispatch(s, key);
  2224. }
  2225. this.alert();
  2226. }
  2227. heading(msg, item, i) {
  2228. return this.styles.strong(msg);
  2229. }
  2230. separator() {
  2231. return this.styles.muted(this.symbols.ellipsis);
  2232. }
  2233. right() {
  2234. let choice = this.focused;
  2235. if (choice.scaleIndex >= this.scale.length - 1) return this.alert();
  2236. choice.scaleIndex++;
  2237. return this.render();
  2238. }
  2239. left() {
  2240. let choice = this.focused;
  2241. if (choice.scaleIndex <= 0) return this.alert();
  2242. choice.scaleIndex--;
  2243. return this.render();
  2244. }
  2245. indent() {
  2246. return '';
  2247. }
  2248. format() {
  2249. if (this.state.submitted) {
  2250. let values = this.choices.map(ch => this.styles.info(ch.index));
  2251. return values.join(', ');
  2252. }
  2253. return '';
  2254. }
  2255. pointer() {
  2256. return '';
  2257. }
  2258. /**
  2259. * Render the scale "Key". Something like:
  2260. * @return {String}
  2261. */
  2262. renderScaleKey() {
  2263. if (this.scaleKey === false) return '';
  2264. if (this.state.submitted) return '';
  2265. let scale = this.scale.map(item => ` ${item.name} - ${item.message}`);
  2266. let key = ['', ...scale].map(item => this.styles.muted(item));
  2267. return key.join('\n');
  2268. }
  2269. /**
  2270. * Render the heading row for the scale.
  2271. * @return {String}
  2272. */
  2273. renderScaleHeading(max) {
  2274. let keys = this.scale.map(ele => ele.name);
  2275. if (typeof this.options.renderScaleHeading === 'function') {
  2276. keys = this.options.renderScaleHeading.call(this, max);
  2277. }
  2278. let diff = this.scaleLength - keys.join('').length;
  2279. let spacing = Math.round(diff / (keys.length - 1));
  2280. let names = keys.map(key => this.styles.strong(key));
  2281. let headings = names.join(' '.repeat(spacing));
  2282. let padding = ' '.repeat(this.widths[0]);
  2283. return this.margin[3] + padding + this.margin[1] + headings;
  2284. }
  2285. /**
  2286. * Render a scale indicator => ◯ or ◉ by default
  2287. */
  2288. scaleIndicator(choice, item, i) {
  2289. if (typeof this.options.scaleIndicator === 'function') {
  2290. return this.options.scaleIndicator.call(this, choice, item, i);
  2291. }
  2292. let enabled = choice.scaleIndex === item.index;
  2293. if (item.disabled) return this.styles.hint(this.symbols.radio.disabled);
  2294. if (enabled) return this.styles.success(this.symbols.radio.on);
  2295. return this.symbols.radio.off;
  2296. }
  2297. /**
  2298. * Render the actual scale => ◯────◯────◉────◯────◯
  2299. */
  2300. renderScale(choice, i) {
  2301. let scale = choice.scale.map(item => this.scaleIndicator(choice, item, i));
  2302. let padding = this.term === 'Hyper' ? '' : ' ';
  2303. return scale.join(padding + this.symbols.line.repeat(this.edgeLength));
  2304. }
  2305. /**
  2306. * Render a choice, including scale =>
  2307. * "The website is easy to navigate. ◯───◯───◉───◯───◯"
  2308. */
  2309. async renderChoice(choice, i) {
  2310. await this.onChoice(choice, i);
  2311. let focused = this.index === i;
  2312. let pointer = await this.pointer(choice, i);
  2313. let hint = await choice.hint;
  2314. if (hint && !utils.hasColor(hint)) {
  2315. hint = this.styles.muted(hint);
  2316. }
  2317. let pad = str => this.margin[3] + str.replace(/\s+$/, '').padEnd(this.widths[0], ' ');
  2318. let newline = this.newline;
  2319. let ind = this.indent(choice);
  2320. let message = await this.resolve(choice.message, this.state, choice, i);
  2321. let scale = await this.renderScale(choice, i);
  2322. let margin = this.margin[1] + this.margin[3];
  2323. this.scaleLength = colors.unstyle(scale).length;
  2324. this.widths[0] = Math.min(this.widths[0], this.width - this.scaleLength - margin.length);
  2325. let msg = utils.wordWrap(message, { width: this.widths[0], newline });
  2326. let lines = msg.split('\n').map(line => pad(line) + this.margin[1]);
  2327. if (focused) {
  2328. scale = this.styles.info(scale);
  2329. lines = lines.map(line => this.styles.info(line));
  2330. }
  2331. lines[0] += scale;
  2332. if (this.linebreak) lines.push('');
  2333. return [ind + pointer, lines.join('\n')].filter(Boolean);
  2334. }
  2335. async renderChoices() {
  2336. if (this.state.submitted) return '';
  2337. this.tableize();
  2338. let choices = this.visible.map(async(ch, i) => await this.renderChoice(ch, i));
  2339. let visible = await Promise.all(choices);
  2340. let heading = await this.renderScaleHeading();
  2341. return this.margin[0] + [heading, ...visible.map(v => v.join(' '))].join('\n');
  2342. }
  2343. async render() {
  2344. let { submitted, size } = this.state;
  2345. let prefix = await this.prefix();
  2346. let separator = await this.separator();
  2347. let message = await this.message();
  2348. let prompt = '';
  2349. if (this.options.promptLine !== false) {
  2350. prompt = [prefix, message, separator, ''].join(' ');
  2351. this.state.prompt = prompt;
  2352. }
  2353. let header = await this.header();
  2354. let output = await this.format();
  2355. let key = await this.renderScaleKey();
  2356. let help = await this.error() || await this.hint();
  2357. let body = await this.renderChoices();
  2358. let footer = await this.footer();
  2359. let err = this.emptyError;
  2360. if (output) prompt += output;
  2361. if (help && !prompt.includes(help)) prompt += ' ' + help;
  2362. if (submitted && !output && !body.trim() && this.multiple && err != null) {
  2363. prompt += this.styles.danger(err);
  2364. }
  2365. this.clear(size);
  2366. this.write([header, prompt, key, body, footer].filter(Boolean).join('\n'));
  2367. if (!this.state.submitted) {
  2368. this.write(this.margin[2]);
  2369. }
  2370. this.restore();
  2371. }
  2372. submit() {
  2373. this.value = {};
  2374. for (let choice of this.choices) {
  2375. this.value[choice.name] = choice.scaleIndex;
  2376. }
  2377. return this.base.submit.call(this);
  2378. }
  2379. }
  2380. module.exports = LikertScale;
  2381. /***/ }),
  2382. /***/ 13466:
  2383. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  2384. "use strict";
  2385. const ArrayPrompt = __webpack_require__(98575);
  2386. const utils = __webpack_require__(83546);
  2387. class SelectPrompt extends ArrayPrompt {
  2388. constructor(options) {
  2389. super(options);
  2390. this.emptyError = this.options.emptyError || 'No items were selected';
  2391. }
  2392. async dispatch(s, key) {
  2393. if (this.multiple) {
  2394. return this[key.name] ? await this[key.name](s, key) : await super.dispatch(s, key);
  2395. }
  2396. this.alert();
  2397. }
  2398. separator() {
  2399. if (this.options.separator) return super.separator();
  2400. let sep = this.styles.muted(this.symbols.ellipsis);
  2401. return this.state.submitted ? super.separator() : sep;
  2402. }
  2403. pointer(choice, i) {
  2404. return (!this.multiple || this.options.pointer) ? super.pointer(choice, i) : '';
  2405. }
  2406. indicator(choice, i) {
  2407. return this.multiple ? super.indicator(choice, i) : '';
  2408. }
  2409. choiceMessage(choice, i) {
  2410. let message = this.resolve(choice.message, this.state, choice, i);
  2411. if (choice.role === 'heading' && !utils.hasColor(message)) {
  2412. message = this.styles.strong(message);
  2413. }
  2414. return this.resolve(message, this.state, choice, i);
  2415. }
  2416. choiceSeparator() {
  2417. return ':';
  2418. }
  2419. async renderChoice(choice, i) {
  2420. await this.onChoice(choice, i);
  2421. let focused = this.index === i;
  2422. let pointer = await this.pointer(choice, i);
  2423. let check = await this.indicator(choice, i) + (choice.pad || '');
  2424. let hint = await this.resolve(choice.hint, this.state, choice, i);
  2425. if (hint && !utils.hasColor(hint)) {
  2426. hint = this.styles.muted(hint);
  2427. }
  2428. let ind = this.indent(choice);
  2429. let msg = await this.choiceMessage(choice, i);
  2430. let line = () => [this.margin[3], ind + pointer + check, msg, this.margin[1], hint].filter(Boolean).join(' ');
  2431. if (choice.role === 'heading') {
  2432. return line();
  2433. }
  2434. if (choice.disabled) {
  2435. if (!utils.hasColor(msg)) {
  2436. msg = this.styles.disabled(msg);
  2437. }
  2438. return line();
  2439. }
  2440. if (focused) {
  2441. msg = this.styles.em(msg);
  2442. }
  2443. return line();
  2444. }
  2445. async renderChoices() {
  2446. if (this.state.loading === 'choices') {
  2447. return this.styles.warning('Loading choices');
  2448. }
  2449. if (this.state.submitted) return '';
  2450. let choices = this.visible.map(async(ch, i) => await this.renderChoice(ch, i));
  2451. let visible = await Promise.all(choices);
  2452. if (!visible.length) visible.push(this.styles.danger('No matching choices'));
  2453. let result = this.margin[0] + visible.join('\n');
  2454. let header;
  2455. if (this.options.choicesHeader) {
  2456. header = await this.resolve(this.options.choicesHeader, this.state);
  2457. }
  2458. return [header, result].filter(Boolean).join('\n');
  2459. }
  2460. format() {
  2461. if (!this.state.submitted || this.state.cancelled) return '';
  2462. if (Array.isArray(this.selected)) {
  2463. return this.selected.map(choice => this.styles.primary(choice.name)).join(', ');
  2464. }
  2465. return this.styles.primary(this.selected.name);
  2466. }
  2467. async render() {
  2468. let { submitted, size } = this.state;
  2469. let prompt = '';
  2470. let header = await this.header();
  2471. let prefix = await this.prefix();
  2472. let separator = await this.separator();
  2473. let message = await this.message();
  2474. if (this.options.promptLine !== false) {
  2475. prompt = [prefix, message, separator, ''].join(' ');
  2476. this.state.prompt = prompt;
  2477. }
  2478. let output = await this.format();
  2479. let help = (await this.error()) || (await this.hint());
  2480. let body = await this.renderChoices();
  2481. let footer = await this.footer();
  2482. if (output) prompt += output;
  2483. if (help && !prompt.includes(help)) prompt += ' ' + help;
  2484. if (submitted && !output && !body.trim() && this.multiple && this.emptyError != null) {
  2485. prompt += this.styles.danger(this.emptyError);
  2486. }
  2487. this.clear(size);
  2488. this.write([header, prompt, body, footer].filter(Boolean).join('\n'));
  2489. this.write(this.margin[2]);
  2490. this.restore();
  2491. }
  2492. }
  2493. module.exports = SelectPrompt;
  2494. /***/ }),
  2495. /***/ 19451:
  2496. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  2497. "use strict";
  2498. const colors = __webpack_require__(53692);
  2499. const interpolate = __webpack_require__(27189);
  2500. const Prompt = __webpack_require__(232);
  2501. class SnippetPrompt extends Prompt {
  2502. constructor(options) {
  2503. super(options);
  2504. this.cursorHide();
  2505. this.reset(true);
  2506. }
  2507. async initialize() {
  2508. this.interpolate = await interpolate(this);
  2509. await super.initialize();
  2510. }
  2511. async reset(first) {
  2512. this.state.keys = [];
  2513. this.state.invalid = new Map();
  2514. this.state.missing = new Set();
  2515. this.state.completed = 0;
  2516. this.state.values = {};
  2517. if (first !== true) {
  2518. await this.initialize();
  2519. await this.render();
  2520. }
  2521. }
  2522. moveCursor(n) {
  2523. let item = this.getItem();
  2524. this.cursor += n;
  2525. item.cursor += n;
  2526. }
  2527. dispatch(ch, key) {
  2528. if (!key.code && !key.ctrl && ch != null && this.getItem()) {
  2529. this.append(ch, key);
  2530. return;
  2531. }
  2532. this.alert();
  2533. }
  2534. append(ch, key) {
  2535. let item = this.getItem();
  2536. let prefix = item.input.slice(0, this.cursor);
  2537. let suffix = item.input.slice(this.cursor);
  2538. this.input = item.input = `${prefix}${ch}${suffix}`;
  2539. this.moveCursor(1);
  2540. this.render();
  2541. }
  2542. delete() {
  2543. let item = this.getItem();
  2544. if (this.cursor <= 0 || !item.input) return this.alert();
  2545. let suffix = item.input.slice(this.cursor);
  2546. let prefix = item.input.slice(0, this.cursor - 1);
  2547. this.input = item.input = `${prefix}${suffix}`;
  2548. this.moveCursor(-1);
  2549. this.render();
  2550. }
  2551. increment(i) {
  2552. return i >= this.state.keys.length - 1 ? 0 : i + 1;
  2553. }
  2554. decrement(i) {
  2555. return i <= 0 ? this.state.keys.length - 1 : i - 1;
  2556. }
  2557. first() {
  2558. this.state.index = 0;
  2559. this.render();
  2560. }
  2561. last() {
  2562. this.state.index = this.state.keys.length - 1;
  2563. this.render();
  2564. }
  2565. right() {
  2566. if (this.cursor >= this.input.length) return this.alert();
  2567. this.moveCursor(1);
  2568. this.render();
  2569. }
  2570. left() {
  2571. if (this.cursor <= 0) return this.alert();
  2572. this.moveCursor(-1);
  2573. this.render();
  2574. }
  2575. prev() {
  2576. this.state.index = this.decrement(this.state.index);
  2577. this.getItem();
  2578. this.render();
  2579. }
  2580. next() {
  2581. this.state.index = this.increment(this.state.index);
  2582. this.getItem();
  2583. this.render();
  2584. }
  2585. up() {
  2586. this.prev();
  2587. }
  2588. down() {
  2589. this.next();
  2590. }
  2591. format(value) {
  2592. let color = this.state.completed < 100 ? this.styles.warning : this.styles.success;
  2593. if (this.state.submitted === true && this.state.completed !== 100) {
  2594. color = this.styles.danger;
  2595. }
  2596. return color(`${this.state.completed}% completed`);
  2597. }
  2598. async render() {
  2599. let { index, keys = [], submitted, size } = this.state;
  2600. let newline = [this.options.newline, '\n'].find(v => v != null);
  2601. let prefix = await this.prefix();
  2602. let separator = await this.separator();
  2603. let message = await this.message();
  2604. let prompt = [prefix, message, separator].filter(Boolean).join(' ');
  2605. this.state.prompt = prompt;
  2606. let header = await this.header();
  2607. let error = (await this.error()) || '';
  2608. let hint = (await this.hint()) || '';
  2609. let body = submitted ? '' : await this.interpolate(this.state);
  2610. let key = this.state.key = keys[index] || '';
  2611. let input = await this.format(key);
  2612. let footer = await this.footer();
  2613. if (input) prompt += ' ' + input;
  2614. if (hint && !input && this.state.completed === 0) prompt += ' ' + hint;
  2615. this.clear(size);
  2616. let lines = [header, prompt, body, footer, error.trim()];
  2617. this.write(lines.filter(Boolean).join(newline));
  2618. this.restore();
  2619. }
  2620. getItem(name) {
  2621. let { items, keys, index } = this.state;
  2622. let item = items.find(ch => ch.name === keys[index]);
  2623. if (item && item.input != null) {
  2624. this.input = item.input;
  2625. this.cursor = item.cursor;
  2626. }
  2627. return item;
  2628. }
  2629. async submit() {
  2630. if (typeof this.interpolate !== 'function') await this.initialize();
  2631. await this.interpolate(this.state, true);
  2632. let { invalid, missing, output, values } = this.state;
  2633. if (invalid.size) {
  2634. let err = '';
  2635. for (let [key, value] of invalid) err += `Invalid ${key}: ${value}\n`;
  2636. this.state.error = err;
  2637. return super.submit();
  2638. }
  2639. if (missing.size) {
  2640. this.state.error = 'Required: ' + [...missing.keys()].join(', ');
  2641. return super.submit();
  2642. }
  2643. let lines = colors.unstyle(output).split('\n');
  2644. let result = lines.map(v => v.slice(1)).join('\n');
  2645. this.value = { values, result };
  2646. return super.submit();
  2647. }
  2648. }
  2649. module.exports = SnippetPrompt;
  2650. /***/ }),
  2651. /***/ 7144:
  2652. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  2653. "use strict";
  2654. const hint = '(Use <shift>+<up/down> to sort)';
  2655. const Prompt = __webpack_require__(13466);
  2656. class Sort extends Prompt {
  2657. constructor(options) {
  2658. super({ ...options, reorder: false, sort: true, multiple: true });
  2659. this.state.hint = [this.options.hint, hint].find(this.isValue.bind(this));
  2660. }
  2661. indicator() {
  2662. return '';
  2663. }
  2664. async renderChoice(choice, i) {
  2665. let str = await super.renderChoice(choice, i);
  2666. let sym = this.symbols.identicalTo + ' ';
  2667. let pre = (this.index === i && this.sorting) ? this.styles.muted(sym) : ' ';
  2668. if (this.options.drag === false) pre = '';
  2669. if (this.options.numbered === true) {
  2670. return pre + `${i + 1} - ` + str;
  2671. }
  2672. return pre + str;
  2673. }
  2674. get selected() {
  2675. return this.choices;
  2676. }
  2677. submit() {
  2678. this.value = this.choices.map(choice => choice.value);
  2679. return super.submit();
  2680. }
  2681. }
  2682. module.exports = Sort;
  2683. /***/ }),
  2684. /***/ 83755:
  2685. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  2686. "use strict";
  2687. const ArrayPrompt = __webpack_require__(98575);
  2688. class Survey extends ArrayPrompt {
  2689. constructor(options = {}) {
  2690. super(options);
  2691. this.emptyError = options.emptyError || 'No items were selected';
  2692. this.term = process.env.TERM_PROGRAM;
  2693. if (!this.options.header) {
  2694. let header = ['', '4 - Strongly Agree', '3 - Agree', '2 - Neutral', '1 - Disagree', '0 - Strongly Disagree', ''];
  2695. header = header.map(ele => this.styles.muted(ele));
  2696. this.state.header = header.join('\n ');
  2697. }
  2698. }
  2699. async toChoices(...args) {
  2700. if (this.createdScales) return false;
  2701. this.createdScales = true;
  2702. let choices = await super.toChoices(...args);
  2703. for (let choice of choices) {
  2704. choice.scale = createScale(5, this.options);
  2705. choice.scaleIdx = 2;
  2706. }
  2707. return choices;
  2708. }
  2709. dispatch() {
  2710. this.alert();
  2711. }
  2712. space() {
  2713. let choice = this.focused;
  2714. let ele = choice.scale[choice.scaleIdx];
  2715. let selected = ele.selected;
  2716. choice.scale.forEach(e => (e.selected = false));
  2717. ele.selected = !selected;
  2718. return this.render();
  2719. }
  2720. indicator() {
  2721. return '';
  2722. }
  2723. pointer() {
  2724. return '';
  2725. }
  2726. separator() {
  2727. return this.styles.muted(this.symbols.ellipsis);
  2728. }
  2729. right() {
  2730. let choice = this.focused;
  2731. if (choice.scaleIdx >= choice.scale.length - 1) return this.alert();
  2732. choice.scaleIdx++;
  2733. return this.render();
  2734. }
  2735. left() {
  2736. let choice = this.focused;
  2737. if (choice.scaleIdx <= 0) return this.alert();
  2738. choice.scaleIdx--;
  2739. return this.render();
  2740. }
  2741. indent() {
  2742. return ' ';
  2743. }
  2744. async renderChoice(item, i) {
  2745. await this.onChoice(item, i);
  2746. let focused = this.index === i;
  2747. let isHyper = this.term === 'Hyper';
  2748. let n = !isHyper ? 8 : 9;
  2749. let s = !isHyper ? ' ' : '';
  2750. let ln = this.symbols.line.repeat(n);
  2751. let sp = ' '.repeat(n + (isHyper ? 0 : 1));
  2752. let dot = enabled => (enabled ? this.styles.success('◉') : '◯') + s;
  2753. let num = i + 1 + '.';
  2754. let color = focused ? this.styles.heading : this.styles.noop;
  2755. let msg = await this.resolve(item.message, this.state, item, i);
  2756. let indent = this.indent(item);
  2757. let scale = indent + item.scale.map((e, i) => dot(i === item.scaleIdx)).join(ln);
  2758. let val = i => i === item.scaleIdx ? color(i) : i;
  2759. let next = indent + item.scale.map((e, i) => val(i)).join(sp);
  2760. let line = () => [num, msg].filter(Boolean).join(' ');
  2761. let lines = () => [line(), scale, next, ' '].filter(Boolean).join('\n');
  2762. if (focused) {
  2763. scale = this.styles.cyan(scale);
  2764. next = this.styles.cyan(next);
  2765. }
  2766. return lines();
  2767. }
  2768. async renderChoices() {
  2769. if (this.state.submitted) return '';
  2770. let choices = this.visible.map(async(ch, i) => await this.renderChoice(ch, i));
  2771. let visible = await Promise.all(choices);
  2772. if (!visible.length) visible.push(this.styles.danger('No matching choices'));
  2773. return visible.join('\n');
  2774. }
  2775. format() {
  2776. if (this.state.submitted) {
  2777. let values = this.choices.map(ch => this.styles.info(ch.scaleIdx));
  2778. return values.join(', ');
  2779. }
  2780. return '';
  2781. }
  2782. async render() {
  2783. let { submitted, size } = this.state;
  2784. let prefix = await this.prefix();
  2785. let separator = await this.separator();
  2786. let message = await this.message();
  2787. let prompt = [prefix, message, separator].filter(Boolean).join(' ');
  2788. this.state.prompt = prompt;
  2789. let header = await this.header();
  2790. let output = await this.format();
  2791. let help = await this.error() || await this.hint();
  2792. let body = await this.renderChoices();
  2793. let footer = await this.footer();
  2794. if (output || !help) prompt += ' ' + output;
  2795. if (help && !prompt.includes(help)) prompt += ' ' + help;
  2796. if (submitted && !output && !body && this.multiple && this.type !== 'form') {
  2797. prompt += this.styles.danger(this.emptyError);
  2798. }
  2799. this.clear(size);
  2800. this.write([prompt, header, body, footer].filter(Boolean).join('\n'));
  2801. this.restore();
  2802. }
  2803. submit() {
  2804. this.value = {};
  2805. for (let choice of this.choices) {
  2806. this.value[choice.name] = choice.scaleIdx;
  2807. }
  2808. return this.base.submit.call(this);
  2809. }
  2810. }
  2811. function createScale(n, options = {}) {
  2812. if (Array.isArray(options.scale)) {
  2813. return options.scale.map(ele => ({ ...ele }));
  2814. }
  2815. let scale = [];
  2816. for (let i = 1; i < n + 1; i++) scale.push({ i, selected: false });
  2817. return scale;
  2818. }
  2819. module.exports = Survey;
  2820. /***/ }),
  2821. /***/ 5781:
  2822. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  2823. module.exports = __webpack_require__(66719);
  2824. /***/ }),
  2825. /***/ 10653:
  2826. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  2827. "use strict";
  2828. const BooleanPrompt = __webpack_require__(23838);
  2829. class TogglePrompt extends BooleanPrompt {
  2830. async initialize() {
  2831. await super.initialize();
  2832. this.value = this.initial = !!this.options.initial;
  2833. this.disabled = this.options.disabled || 'no';
  2834. this.enabled = this.options.enabled || 'yes';
  2835. await this.render();
  2836. }
  2837. reset() {
  2838. this.value = this.initial;
  2839. this.render();
  2840. }
  2841. delete() {
  2842. this.alert();
  2843. }
  2844. toggle() {
  2845. this.value = !this.value;
  2846. this.render();
  2847. }
  2848. enable() {
  2849. if (this.value === true) return this.alert();
  2850. this.value = true;
  2851. this.render();
  2852. }
  2853. disable() {
  2854. if (this.value === false) return this.alert();
  2855. this.value = false;
  2856. this.render();
  2857. }
  2858. up() {
  2859. this.toggle();
  2860. }
  2861. down() {
  2862. this.toggle();
  2863. }
  2864. right() {
  2865. this.toggle();
  2866. }
  2867. left() {
  2868. this.toggle();
  2869. }
  2870. next() {
  2871. this.toggle();
  2872. }
  2873. prev() {
  2874. this.toggle();
  2875. }
  2876. dispatch(ch = '', key) {
  2877. switch (ch.toLowerCase()) {
  2878. case ' ':
  2879. return this.toggle();
  2880. case '1':
  2881. case 'y':
  2882. case 't':
  2883. return this.enable();
  2884. case '0':
  2885. case 'n':
  2886. case 'f':
  2887. return this.disable();
  2888. default: {
  2889. return this.alert();
  2890. }
  2891. }
  2892. }
  2893. format() {
  2894. let active = str => this.styles.primary.underline(str);
  2895. let value = [
  2896. this.value ? this.disabled : active(this.disabled),
  2897. this.value ? active(this.enabled) : this.enabled
  2898. ];
  2899. return value.join(this.styles.muted(' / '));
  2900. }
  2901. async render() {
  2902. let { size } = this.state;
  2903. let header = await this.header();
  2904. let prefix = await this.prefix();
  2905. let separator = await this.separator();
  2906. let message = await this.message();
  2907. let output = await this.format();
  2908. let help = (await this.error()) || (await this.hint());
  2909. let footer = await this.footer();
  2910. let prompt = [prefix, message, separator, output].join(' ');
  2911. this.state.prompt = prompt;
  2912. if (help && !prompt.includes(help)) prompt += ' ' + help;
  2913. this.clear(size);
  2914. this.write([header, prompt, footer].filter(Boolean).join('\n'));
  2915. this.write(this.margin[2]);
  2916. this.restore();
  2917. }
  2918. }
  2919. module.exports = TogglePrompt;
  2920. /***/ }),
  2921. /***/ 31502:
  2922. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  2923. "use strict";
  2924. const utils = __webpack_require__(83546);
  2925. const roles = {
  2926. default(prompt, choice) {
  2927. return choice;
  2928. },
  2929. checkbox(prompt, choice) {
  2930. throw new Error('checkbox role is not implemented yet');
  2931. },
  2932. editable(prompt, choice) {
  2933. throw new Error('editable role is not implemented yet');
  2934. },
  2935. expandable(prompt, choice) {
  2936. throw new Error('expandable role is not implemented yet');
  2937. },
  2938. heading(prompt, choice) {
  2939. choice.disabled = '';
  2940. choice.indicator = [choice.indicator, ' '].find(v => v != null);
  2941. choice.message = choice.message || '';
  2942. return choice;
  2943. },
  2944. input(prompt, choice) {
  2945. throw new Error('input role is not implemented yet');
  2946. },
  2947. option(prompt, choice) {
  2948. return roles.default(prompt, choice);
  2949. },
  2950. radio(prompt, choice) {
  2951. throw new Error('radio role is not implemented yet');
  2952. },
  2953. separator(prompt, choice) {
  2954. choice.disabled = '';
  2955. choice.indicator = [choice.indicator, ' '].find(v => v != null);
  2956. choice.message = choice.message || prompt.symbols.line.repeat(5);
  2957. return choice;
  2958. },
  2959. spacer(prompt, choice) {
  2960. return choice;
  2961. }
  2962. };
  2963. module.exports = (name, options = {}) => {
  2964. let role = utils.merge({}, roles, options.roles);
  2965. return role[name] || role.default;
  2966. };
  2967. /***/ }),
  2968. /***/ 36873:
  2969. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  2970. "use strict";
  2971. const { define, width } = __webpack_require__(83546);
  2972. class State {
  2973. constructor(prompt) {
  2974. let options = prompt.options;
  2975. define(this, '_prompt', prompt);
  2976. this.type = prompt.type;
  2977. this.name = prompt.name;
  2978. this.message = '';
  2979. this.header = '';
  2980. this.footer = '';
  2981. this.error = '';
  2982. this.hint = '';
  2983. this.input = '';
  2984. this.cursor = 0;
  2985. this.index = 0;
  2986. this.lines = 0;
  2987. this.tick = 0;
  2988. this.prompt = '';
  2989. this.buffer = '';
  2990. this.width = width(options.stdout || process.stdout);
  2991. Object.assign(this, options);
  2992. this.name = this.name || this.message;
  2993. this.message = this.message || this.name;
  2994. this.symbols = prompt.symbols;
  2995. this.styles = prompt.styles;
  2996. this.required = new Set();
  2997. this.cancelled = false;
  2998. this.submitted = false;
  2999. }
  3000. clone() {
  3001. let state = { ...this };
  3002. state.status = this.status;
  3003. state.buffer = Buffer.from(state.buffer);
  3004. delete state.clone;
  3005. return state;
  3006. }
  3007. set color(val) {
  3008. this._color = val;
  3009. }
  3010. get color() {
  3011. let styles = this.prompt.styles;
  3012. if (this.cancelled) return styles.cancelled;
  3013. if (this.submitted) return styles.submitted;
  3014. let color = this._color || styles[this.status];
  3015. return typeof color === 'function' ? color : styles.pending;
  3016. }
  3017. set loading(value) {
  3018. this._loading = value;
  3019. }
  3020. get loading() {
  3021. if (typeof this._loading === 'boolean') return this._loading;
  3022. if (this.loadingChoices) return 'choices';
  3023. return false;
  3024. }
  3025. get status() {
  3026. if (this.cancelled) return 'cancelled';
  3027. if (this.submitted) return 'submitted';
  3028. return 'pending';
  3029. }
  3030. }
  3031. module.exports = State;
  3032. /***/ }),
  3033. /***/ 79217:
  3034. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  3035. "use strict";
  3036. const utils = __webpack_require__(83546);
  3037. const colors = __webpack_require__(53692);
  3038. const styles = {
  3039. default: colors.noop,
  3040. noop: colors.noop,
  3041. /**
  3042. * Modifiers
  3043. */
  3044. set inverse(custom) {
  3045. this._inverse = custom;
  3046. },
  3047. get inverse() {
  3048. return this._inverse || utils.inverse(this.primary);
  3049. },
  3050. set complement(custom) {
  3051. this._complement = custom;
  3052. },
  3053. get complement() {
  3054. return this._complement || utils.complement(this.primary);
  3055. },
  3056. /**
  3057. * Main color
  3058. */
  3059. primary: colors.cyan,
  3060. /**
  3061. * Main palette
  3062. */
  3063. success: colors.green,
  3064. danger: colors.magenta,
  3065. strong: colors.bold,
  3066. warning: colors.yellow,
  3067. muted: colors.dim,
  3068. disabled: colors.gray,
  3069. dark: colors.dim.gray,
  3070. underline: colors.underline,
  3071. set info(custom) {
  3072. this._info = custom;
  3073. },
  3074. get info() {
  3075. return this._info || this.primary;
  3076. },
  3077. set em(custom) {
  3078. this._em = custom;
  3079. },
  3080. get em() {
  3081. return this._em || this.primary.underline;
  3082. },
  3083. set heading(custom) {
  3084. this._heading = custom;
  3085. },
  3086. get heading() {
  3087. return this._heading || this.muted.underline;
  3088. },
  3089. /**
  3090. * Statuses
  3091. */
  3092. set pending(custom) {
  3093. this._pending = custom;
  3094. },
  3095. get pending() {
  3096. return this._pending || this.primary;
  3097. },
  3098. set submitted(custom) {
  3099. this._submitted = custom;
  3100. },
  3101. get submitted() {
  3102. return this._submitted || this.success;
  3103. },
  3104. set cancelled(custom) {
  3105. this._cancelled = custom;
  3106. },
  3107. get cancelled() {
  3108. return this._cancelled || this.danger;
  3109. },
  3110. /**
  3111. * Special styling
  3112. */
  3113. set typing(custom) {
  3114. this._typing = custom;
  3115. },
  3116. get typing() {
  3117. return this._typing || this.dim;
  3118. },
  3119. set placeholder(custom) {
  3120. this._placeholder = custom;
  3121. },
  3122. get placeholder() {
  3123. return this._placeholder || this.primary.dim;
  3124. },
  3125. set highlight(custom) {
  3126. this._highlight = custom;
  3127. },
  3128. get highlight() {
  3129. return this._highlight || this.inverse;
  3130. }
  3131. };
  3132. styles.merge = (options = {}) => {
  3133. if (options.styles && typeof options.styles.enabled === 'boolean') {
  3134. colors.enabled = options.styles.enabled;
  3135. }
  3136. if (options.styles && typeof options.styles.visible === 'boolean') {
  3137. colors.visible = options.styles.visible;
  3138. }
  3139. let result = utils.merge({}, styles, options.styles);
  3140. delete result.merge;
  3141. for (let key of Object.keys(colors)) {
  3142. if (!result.hasOwnProperty(key)) {
  3143. Reflect.defineProperty(result, key, { get: () => colors[key] });
  3144. }
  3145. }
  3146. for (let key of Object.keys(colors.styles)) {
  3147. if (!result.hasOwnProperty(key)) {
  3148. Reflect.defineProperty(result, key, { get: () => colors[key] });
  3149. }
  3150. }
  3151. return result;
  3152. };
  3153. module.exports = styles;
  3154. /***/ }),
  3155. /***/ 74739:
  3156. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  3157. "use strict";
  3158. const isWindows = process.platform === 'win32';
  3159. const colors = __webpack_require__(53692);
  3160. const utils = __webpack_require__(83546);
  3161. const symbols = {
  3162. ...colors.symbols,
  3163. upDownDoubleArrow: '⇕',
  3164. upDownDoubleArrow2: '⬍',
  3165. upDownArrow: '↕',
  3166. asterisk: '*',
  3167. asterism: '⁂',
  3168. bulletWhite: '◦',
  3169. electricArrow: '⌁',
  3170. ellipsisLarge: '⋯',
  3171. ellipsisSmall: '…',
  3172. fullBlock: '█',
  3173. identicalTo: '≡',
  3174. indicator: colors.symbols.check,
  3175. leftAngle: '‹',
  3176. mark: '※',
  3177. minus: '−',
  3178. multiplication: '×',
  3179. obelus: '÷',
  3180. percent: '%',
  3181. pilcrow: '¶',
  3182. pilcrow2: '❡',
  3183. pencilUpRight: '✐',
  3184. pencilDownRight: '✎',
  3185. pencilRight: '✏',
  3186. plus: '+',
  3187. plusMinus: '±',
  3188. pointRight: '☞',
  3189. rightAngle: '›',
  3190. section: '§',
  3191. hexagon: { off: '⬡', on: '⬢', disabled: '⬢' },
  3192. ballot: { on: '☑', off: '☐', disabled: '☒' },
  3193. stars: { on: '★', off: '☆', disabled: '☆' },
  3194. folder: { on: '▼', off: '▶', disabled: '▶' },
  3195. prefix: {
  3196. pending: colors.symbols.question,
  3197. submitted: colors.symbols.check,
  3198. cancelled: colors.symbols.cross
  3199. },
  3200. separator: {
  3201. pending: colors.symbols.pointerSmall,
  3202. submitted: colors.symbols.middot,
  3203. cancelled: colors.symbols.middot
  3204. },
  3205. radio: {
  3206. off: isWindows ? '( )' : '◯',
  3207. on: isWindows ? '(*)' : '◉',
  3208. disabled: isWindows ? '(|)' : 'Ⓘ'
  3209. },
  3210. numbers: ['⓪', '①', '②', '③', '④', '⑤', '⑥', '⑦', '⑧', '⑨', '⑩', '⑪', '⑫', '⑬', '⑭', '⑮', '⑯', '⑰', '⑱', '⑲', '⑳', '㉑', '㉒', '㉓', '㉔', '㉕', '㉖', '㉗', '㉘', '㉙', '㉚', '㉛', '㉜', '㉝', '㉞', '㉟', '㊱', '㊲', '㊳', '㊴', '㊵', '㊶', '㊷', '㊸', '㊹', '㊺', '㊻', '㊼', '㊽', '㊾', '㊿']
  3211. };
  3212. symbols.merge = options => {
  3213. let result = utils.merge({}, colors.symbols, symbols, options.symbols);
  3214. delete result.merge;
  3215. return result;
  3216. };
  3217. module.exports = symbols;
  3218. /***/ }),
  3219. /***/ 39227:
  3220. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  3221. "use strict";
  3222. const styles = __webpack_require__(79217);
  3223. const symbols = __webpack_require__(74739);
  3224. const utils = __webpack_require__(83546);
  3225. module.exports = prompt => {
  3226. prompt.options = utils.merge({}, prompt.options.theme, prompt.options);
  3227. prompt.symbols = symbols.merge(prompt.options);
  3228. prompt.styles = styles.merge(prompt.options);
  3229. };
  3230. /***/ }),
  3231. /***/ 33940:
  3232. /***/ ((module) => {
  3233. "use strict";
  3234. module.exports = prompt => {
  3235. prompt.timers = prompt.timers || {};
  3236. let timers = prompt.options.timers;
  3237. if (!timers) return;
  3238. for (let key of Object.keys(timers)) {
  3239. let opts = timers[key];
  3240. if (typeof opts === 'number') {
  3241. opts = { interval: opts };
  3242. }
  3243. create(prompt, key, opts);
  3244. }
  3245. };
  3246. function create(prompt, name, options = {}) {
  3247. let timer = prompt.timers[name] = { name, start: Date.now(), ms: 0, tick: 0 };
  3248. let ms = options.interval || 120;
  3249. timer.frames = options.frames || [];
  3250. timer.loading = true;
  3251. let interval = setInterval(() => {
  3252. timer.ms = Date.now() - timer.start;
  3253. timer.tick++;
  3254. prompt.render();
  3255. }, ms);
  3256. timer.stop = () => {
  3257. timer.loading = false;
  3258. clearInterval(interval);
  3259. };
  3260. Reflect.defineProperty(timer, 'interval', { value: interval });
  3261. prompt.once('close', () => timer.stop());
  3262. return timer.stop;
  3263. }
  3264. /***/ }),
  3265. /***/ 98575:
  3266. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  3267. "use strict";
  3268. const colors = __webpack_require__(53692);
  3269. const Prompt = __webpack_require__(232);
  3270. const roles = __webpack_require__(31502);
  3271. const utils = __webpack_require__(83546);
  3272. const { reorder, scrollUp, scrollDown, isObject, swap } = utils;
  3273. class ArrayPrompt extends Prompt {
  3274. constructor(options) {
  3275. super(options);
  3276. this.cursorHide();
  3277. this.maxSelected = options.maxSelected || Infinity;
  3278. this.multiple = options.multiple || false;
  3279. this.initial = options.initial || 0;
  3280. this.delay = options.delay || 0;
  3281. this.longest = 0;
  3282. this.num = '';
  3283. }
  3284. async initialize() {
  3285. if (typeof this.options.initial === 'function') {
  3286. this.initial = await this.options.initial.call(this);
  3287. }
  3288. await this.reset(true);
  3289. await super.initialize();
  3290. }
  3291. async reset() {
  3292. let { choices, initial, autofocus, suggest } = this.options;
  3293. this.state._choices = [];
  3294. this.state.choices = [];
  3295. this.choices = await Promise.all(await this.toChoices(choices));
  3296. this.choices.forEach(ch => (ch.enabled = false));
  3297. if (typeof suggest !== 'function' && this.selectable.length === 0) {
  3298. throw new Error('At least one choice must be selectable');
  3299. }
  3300. if (isObject(initial)) initial = Object.keys(initial);
  3301. if (Array.isArray(initial)) {
  3302. if (autofocus != null) this.index = this.findIndex(autofocus);
  3303. initial.forEach(v => this.enable(this.find(v)));
  3304. await this.render();
  3305. } else {
  3306. if (autofocus != null) initial = autofocus;
  3307. if (typeof initial === 'string') initial = this.findIndex(initial);
  3308. if (typeof initial === 'number' && initial > -1) {
  3309. this.index = Math.max(0, Math.min(initial, this.choices.length));
  3310. this.enable(this.find(this.index));
  3311. }
  3312. }
  3313. if (this.isDisabled(this.focused)) {
  3314. await this.down();
  3315. }
  3316. }
  3317. async toChoices(value, parent) {
  3318. this.state.loadingChoices = true;
  3319. let choices = [];
  3320. let index = 0;
  3321. let toChoices = async(items, parent) => {
  3322. if (typeof items === 'function') items = await items.call(this);
  3323. if (items instanceof Promise) items = await items;
  3324. for (let i = 0; i < items.length; i++) {
  3325. let choice = items[i] = await this.toChoice(items[i], index++, parent);
  3326. choices.push(choice);
  3327. if (choice.choices) {
  3328. await toChoices(choice.choices, choice);
  3329. }
  3330. }
  3331. return choices;
  3332. };
  3333. return toChoices(value, parent)
  3334. .then(choices => {
  3335. this.state.loadingChoices = false;
  3336. return choices;
  3337. });
  3338. }
  3339. async toChoice(ele, i, parent) {
  3340. if (typeof ele === 'function') ele = await ele.call(this, this);
  3341. if (ele instanceof Promise) ele = await ele;
  3342. if (typeof ele === 'string') ele = { name: ele };
  3343. if (ele.normalized) return ele;
  3344. ele.normalized = true;
  3345. let origVal = ele.value;
  3346. let role = roles(ele.role, this.options);
  3347. ele = role(this, ele);
  3348. if (typeof ele.disabled === 'string' && !ele.hint) {
  3349. ele.hint = ele.disabled;
  3350. ele.disabled = true;
  3351. }
  3352. if (ele.disabled === true && ele.hint == null) {
  3353. ele.hint = '(disabled)';
  3354. }
  3355. // if the choice was already normalized, return it
  3356. if (ele.index != null) return ele;
  3357. ele.name = ele.name || ele.key || ele.title || ele.value || ele.message;
  3358. ele.message = ele.message || ele.name || '';
  3359. ele.value = [ele.value, ele.name].find(this.isValue.bind(this));
  3360. ele.input = '';
  3361. ele.index = i;
  3362. ele.cursor = 0;
  3363. utils.define(ele, 'parent', parent);
  3364. ele.level = parent ? parent.level + 1 : 1;
  3365. if (ele.indent == null) {
  3366. ele.indent = parent ? parent.indent + ' ' : (ele.indent || '');
  3367. }
  3368. ele.path = parent ? parent.path + '.' + ele.name : ele.name;
  3369. ele.enabled = !!(this.multiple && !this.isDisabled(ele) && (ele.enabled || this.isSelected(ele)));
  3370. if (!this.isDisabled(ele)) {
  3371. this.longest = Math.max(this.longest, colors.unstyle(ele.message).length);
  3372. }
  3373. // shallow clone the choice first
  3374. let choice = { ...ele };
  3375. // then allow the choice to be reset using the "original" values
  3376. ele.reset = (input = choice.input, value = choice.value) => {
  3377. for (let key of Object.keys(choice)) ele[key] = choice[key];
  3378. ele.input = input;
  3379. ele.value = value;
  3380. };
  3381. if (origVal == null && typeof ele.initial === 'function') {
  3382. ele.input = await ele.initial.call(this, this.state, ele, i);
  3383. }
  3384. return ele;
  3385. }
  3386. async onChoice(choice, i) {
  3387. this.emit('choice', choice, i, this);
  3388. if (typeof choice.onChoice === 'function') {
  3389. await choice.onChoice.call(this, this.state, choice, i);
  3390. }
  3391. }
  3392. async addChoice(ele, i, parent) {
  3393. let choice = await this.toChoice(ele, i, parent);
  3394. this.choices.push(choice);
  3395. this.index = this.choices.length - 1;
  3396. this.limit = this.choices.length;
  3397. return choice;
  3398. }
  3399. async newItem(item, i, parent) {
  3400. let ele = { name: 'New choice name?', editable: true, newChoice: true, ...item };
  3401. let choice = await this.addChoice(ele, i, parent);
  3402. choice.updateChoice = () => {
  3403. delete choice.newChoice;
  3404. choice.name = choice.message = choice.input;
  3405. choice.input = '';
  3406. choice.cursor = 0;
  3407. };
  3408. return this.render();
  3409. }
  3410. indent(choice) {
  3411. if (choice.indent == null) {
  3412. return choice.level > 1 ? ' '.repeat(choice.level - 1) : '';
  3413. }
  3414. return choice.indent;
  3415. }
  3416. dispatch(s, key) {
  3417. if (this.multiple && this[key.name]) return this[key.name]();
  3418. this.alert();
  3419. }
  3420. focus(choice, enabled) {
  3421. if (typeof enabled !== 'boolean') enabled = choice.enabled;
  3422. if (enabled && !choice.enabled && this.selected.length >= this.maxSelected) {
  3423. return this.alert();
  3424. }
  3425. this.index = choice.index;
  3426. choice.enabled = enabled && !this.isDisabled(choice);
  3427. return choice;
  3428. }
  3429. space() {
  3430. if (!this.multiple) return this.alert();
  3431. this.toggle(this.focused);
  3432. return this.render();
  3433. }
  3434. a() {
  3435. if (this.maxSelected < this.choices.length) return this.alert();
  3436. let enabled = this.selectable.every(ch => ch.enabled);
  3437. this.choices.forEach(ch => (ch.enabled = !enabled));
  3438. return this.render();
  3439. }
  3440. i() {
  3441. // don't allow choices to be inverted if it will result in
  3442. // more than the maximum number of allowed selected items.
  3443. if (this.choices.length - this.selected.length > this.maxSelected) {
  3444. return this.alert();
  3445. }
  3446. this.choices.forEach(ch => (ch.enabled = !ch.enabled));
  3447. return this.render();
  3448. }
  3449. g(choice = this.focused) {
  3450. if (!this.choices.some(ch => !!ch.parent)) return this.a();
  3451. this.toggle((choice.parent && !choice.choices) ? choice.parent : choice);
  3452. return this.render();
  3453. }
  3454. toggle(choice, enabled) {
  3455. if (!choice.enabled && this.selected.length >= this.maxSelected) {
  3456. return this.alert();
  3457. }
  3458. if (typeof enabled !== 'boolean') enabled = !choice.enabled;
  3459. choice.enabled = enabled;
  3460. if (choice.choices) {
  3461. choice.choices.forEach(ch => this.toggle(ch, enabled));
  3462. }
  3463. let parent = choice.parent;
  3464. while (parent) {
  3465. let choices = parent.choices.filter(ch => this.isDisabled(ch));
  3466. parent.enabled = choices.every(ch => ch.enabled === true);
  3467. parent = parent.parent;
  3468. }
  3469. reset(this, this.choices);
  3470. this.emit('toggle', choice, this);
  3471. return choice;
  3472. }
  3473. enable(choice) {
  3474. if (this.selected.length >= this.maxSelected) return this.alert();
  3475. choice.enabled = !this.isDisabled(choice);
  3476. choice.choices && choice.choices.forEach(this.enable.bind(this));
  3477. return choice;
  3478. }
  3479. disable(choice) {
  3480. choice.enabled = false;
  3481. choice.choices && choice.choices.forEach(this.disable.bind(this));
  3482. return choice;
  3483. }
  3484. number(n) {
  3485. this.num += n;
  3486. let number = num => {
  3487. let i = Number(num);
  3488. if (i > this.choices.length - 1) return this.alert();
  3489. let focused = this.focused;
  3490. let choice = this.choices.find(ch => i === ch.index);
  3491. if (!choice.enabled && this.selected.length >= this.maxSelected) {
  3492. return this.alert();
  3493. }
  3494. if (this.visible.indexOf(choice) === -1) {
  3495. let choices = reorder(this.choices);
  3496. let actualIdx = choices.indexOf(choice);
  3497. if (focused.index > actualIdx) {
  3498. let start = choices.slice(actualIdx, actualIdx + this.limit);
  3499. let end = choices.filter(ch => !start.includes(ch));
  3500. this.choices = start.concat(end);
  3501. } else {
  3502. let pos = actualIdx - this.limit + 1;
  3503. this.choices = choices.slice(pos).concat(choices.slice(0, pos));
  3504. }
  3505. }
  3506. this.index = this.choices.indexOf(choice);
  3507. this.toggle(this.focused);
  3508. return this.render();
  3509. };
  3510. clearTimeout(this.numberTimeout);
  3511. return new Promise(resolve => {
  3512. let len = this.choices.length;
  3513. let num = this.num;
  3514. let handle = (val = false, res) => {
  3515. clearTimeout(this.numberTimeout);
  3516. if (val) res = number(num);
  3517. this.num = '';
  3518. resolve(res);
  3519. };
  3520. if (num === '0' || (num.length === 1 && Number(num + '0') > len)) {
  3521. return handle(true);
  3522. }
  3523. if (Number(num) > len) {
  3524. return handle(false, this.alert());
  3525. }
  3526. this.numberTimeout = setTimeout(() => handle(true), this.delay);
  3527. });
  3528. }
  3529. home() {
  3530. this.choices = reorder(this.choices);
  3531. this.index = 0;
  3532. return this.render();
  3533. }
  3534. end() {
  3535. let pos = this.choices.length - this.limit;
  3536. let choices = reorder(this.choices);
  3537. this.choices = choices.slice(pos).concat(choices.slice(0, pos));
  3538. this.index = this.limit - 1;
  3539. return this.render();
  3540. }
  3541. first() {
  3542. this.index = 0;
  3543. return this.render();
  3544. }
  3545. last() {
  3546. this.index = this.visible.length - 1;
  3547. return this.render();
  3548. }
  3549. prev() {
  3550. if (this.visible.length <= 1) return this.alert();
  3551. return this.up();
  3552. }
  3553. next() {
  3554. if (this.visible.length <= 1) return this.alert();
  3555. return this.down();
  3556. }
  3557. right() {
  3558. if (this.cursor >= this.input.length) return this.alert();
  3559. this.cursor++;
  3560. return this.render();
  3561. }
  3562. left() {
  3563. if (this.cursor <= 0) return this.alert();
  3564. this.cursor--;
  3565. return this.render();
  3566. }
  3567. up() {
  3568. let len = this.choices.length;
  3569. let vis = this.visible.length;
  3570. let idx = this.index;
  3571. if (this.options.scroll === false && idx === 0) {
  3572. return this.alert();
  3573. }
  3574. if (len > vis && idx === 0) {
  3575. return this.scrollUp();
  3576. }
  3577. this.index = ((idx - 1 % len) + len) % len;
  3578. if (this.isDisabled()) {
  3579. return this.up();
  3580. }
  3581. return this.render();
  3582. }
  3583. down() {
  3584. let len = this.choices.length;
  3585. let vis = this.visible.length;
  3586. let idx = this.index;
  3587. if (this.options.scroll === false && idx === vis - 1) {
  3588. return this.alert();
  3589. }
  3590. if (len > vis && idx === vis - 1) {
  3591. return this.scrollDown();
  3592. }
  3593. this.index = (idx + 1) % len;
  3594. if (this.isDisabled()) {
  3595. return this.down();
  3596. }
  3597. return this.render();
  3598. }
  3599. scrollUp(i = 0) {
  3600. this.choices = scrollUp(this.choices);
  3601. this.index = i;
  3602. if (this.isDisabled()) {
  3603. return this.up();
  3604. }
  3605. return this.render();
  3606. }
  3607. scrollDown(i = this.visible.length - 1) {
  3608. this.choices = scrollDown(this.choices);
  3609. this.index = i;
  3610. if (this.isDisabled()) {
  3611. return this.down();
  3612. }
  3613. return this.render();
  3614. }
  3615. async shiftUp() {
  3616. if (this.options.sort === true) {
  3617. this.sorting = true;
  3618. this.swap(this.index - 1);
  3619. await this.up();
  3620. this.sorting = false;
  3621. return;
  3622. }
  3623. return this.scrollUp(this.index);
  3624. }
  3625. async shiftDown() {
  3626. if (this.options.sort === true) {
  3627. this.sorting = true;
  3628. this.swap(this.index + 1);
  3629. await this.down();
  3630. this.sorting = false;
  3631. return;
  3632. }
  3633. return this.scrollDown(this.index);
  3634. }
  3635. pageUp() {
  3636. if (this.visible.length <= 1) return this.alert();
  3637. this.limit = Math.max(this.limit - 1, 0);
  3638. this.index = Math.min(this.limit - 1, this.index);
  3639. this._limit = this.limit;
  3640. if (this.isDisabled()) {
  3641. return this.up();
  3642. }
  3643. return this.render();
  3644. }
  3645. pageDown() {
  3646. if (this.visible.length >= this.choices.length) return this.alert();
  3647. this.index = Math.max(0, this.index);
  3648. this.limit = Math.min(this.limit + 1, this.choices.length);
  3649. this._limit = this.limit;
  3650. if (this.isDisabled()) {
  3651. return this.down();
  3652. }
  3653. return this.render();
  3654. }
  3655. swap(pos) {
  3656. swap(this.choices, this.index, pos);
  3657. }
  3658. isDisabled(choice = this.focused) {
  3659. let keys = ['disabled', 'collapsed', 'hidden', 'completing', 'readonly'];
  3660. if (choice && keys.some(key => choice[key] === true)) {
  3661. return true;
  3662. }
  3663. return choice && choice.role === 'heading';
  3664. }
  3665. isEnabled(choice = this.focused) {
  3666. if (Array.isArray(choice)) return choice.every(ch => this.isEnabled(ch));
  3667. if (choice.choices) {
  3668. let choices = choice.choices.filter(ch => !this.isDisabled(ch));
  3669. return choice.enabled && choices.every(ch => this.isEnabled(ch));
  3670. }
  3671. return choice.enabled && !this.isDisabled(choice);
  3672. }
  3673. isChoice(choice, value) {
  3674. return choice.name === value || choice.index === Number(value);
  3675. }
  3676. isSelected(choice) {
  3677. if (Array.isArray(this.initial)) {
  3678. return this.initial.some(value => this.isChoice(choice, value));
  3679. }
  3680. return this.isChoice(choice, this.initial);
  3681. }
  3682. map(names = [], prop = 'value') {
  3683. return [].concat(names || []).reduce((acc, name) => {
  3684. acc[name] = this.find(name, prop);
  3685. return acc;
  3686. }, {});
  3687. }
  3688. filter(value, prop) {
  3689. let isChoice = (ele, i) => [ele.name, i].includes(value);
  3690. let fn = typeof value === 'function' ? value : isChoice;
  3691. let choices = this.options.multiple ? this.state._choices : this.choices;
  3692. let result = choices.filter(fn);
  3693. if (prop) {
  3694. return result.map(ch => ch[prop]);
  3695. }
  3696. return result;
  3697. }
  3698. find(value, prop) {
  3699. if (isObject(value)) return prop ? value[prop] : value;
  3700. let isChoice = (ele, i) => [ele.name, i].includes(value);
  3701. let fn = typeof value === 'function' ? value : isChoice;
  3702. let choice = this.choices.find(fn);
  3703. if (choice) {
  3704. return prop ? choice[prop] : choice;
  3705. }
  3706. }
  3707. findIndex(value) {
  3708. return this.choices.indexOf(this.find(value));
  3709. }
  3710. async submit() {
  3711. let choice = this.focused;
  3712. if (!choice) return this.alert();
  3713. if (choice.newChoice) {
  3714. if (!choice.input) return this.alert();
  3715. choice.updateChoice();
  3716. return this.render();
  3717. }
  3718. if (this.choices.some(ch => ch.newChoice)) {
  3719. return this.alert();
  3720. }
  3721. let { reorder, sort } = this.options;
  3722. let multi = this.multiple === true;
  3723. let value = this.selected;
  3724. if (value === void 0) {
  3725. return this.alert();
  3726. }
  3727. // re-sort choices to original order
  3728. if (Array.isArray(value) && reorder !== false && sort !== true) {
  3729. value = utils.reorder(value);
  3730. }
  3731. this.value = multi ? value.map(ch => ch.name) : value.name;
  3732. return super.submit();
  3733. }
  3734. set choices(choices = []) {
  3735. this.state._choices = this.state._choices || [];
  3736. this.state.choices = choices;
  3737. for (let choice of choices) {
  3738. if (!this.state._choices.some(ch => ch.name === choice.name)) {
  3739. this.state._choices.push(choice);
  3740. }
  3741. }
  3742. if (!this._initial && this.options.initial) {
  3743. this._initial = true;
  3744. let init = this.initial;
  3745. if (typeof init === 'string' || typeof init === 'number') {
  3746. let choice = this.find(init);
  3747. if (choice) {
  3748. this.initial = choice.index;
  3749. this.focus(choice, true);
  3750. }
  3751. }
  3752. }
  3753. }
  3754. get choices() {
  3755. return reset(this, this.state.choices || []);
  3756. }
  3757. set visible(visible) {
  3758. this.state.visible = visible;
  3759. }
  3760. get visible() {
  3761. return (this.state.visible || this.choices).slice(0, this.limit);
  3762. }
  3763. set limit(num) {
  3764. this.state.limit = num;
  3765. }
  3766. get limit() {
  3767. let { state, options, choices } = this;
  3768. let limit = state.limit || this._limit || options.limit || choices.length;
  3769. return Math.min(limit, this.height);
  3770. }
  3771. set value(value) {
  3772. super.value = value;
  3773. }
  3774. get value() {
  3775. if (typeof super.value !== 'string' && super.value === this.initial) {
  3776. return this.input;
  3777. }
  3778. return super.value;
  3779. }
  3780. set index(i) {
  3781. this.state.index = i;
  3782. }
  3783. get index() {
  3784. return Math.max(0, this.state ? this.state.index : 0);
  3785. }
  3786. get enabled() {
  3787. return this.filter(this.isEnabled.bind(this));
  3788. }
  3789. get focused() {
  3790. let choice = this.choices[this.index];
  3791. if (choice && this.state.submitted && this.multiple !== true) {
  3792. choice.enabled = true;
  3793. }
  3794. return choice;
  3795. }
  3796. get selectable() {
  3797. return this.choices.filter(choice => !this.isDisabled(choice));
  3798. }
  3799. get selected() {
  3800. return this.multiple ? this.enabled : this.focused;
  3801. }
  3802. }
  3803. function reset(prompt, choices) {
  3804. if (choices instanceof Promise) return choices;
  3805. if (typeof choices === 'function') {
  3806. if (utils.isAsyncFn(choices)) return choices;
  3807. choices = choices.call(prompt, prompt);
  3808. }
  3809. for (let choice of choices) {
  3810. if (Array.isArray(choice.choices)) {
  3811. let items = choice.choices.filter(ch => !prompt.isDisabled(ch));
  3812. choice.enabled = items.every(ch => ch.enabled === true);
  3813. }
  3814. if (prompt.isDisabled(choice) === true) {
  3815. delete choice.enabled;
  3816. }
  3817. }
  3818. return choices;
  3819. }
  3820. module.exports = ArrayPrompt;
  3821. /***/ }),
  3822. /***/ 66926:
  3823. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  3824. "use strict";
  3825. const FormPrompt = __webpack_require__(21826);
  3826. const defaultAuthenticate = () => {
  3827. throw new Error('expected prompt to have a custom authenticate method');
  3828. };
  3829. const factory = (authenticate = defaultAuthenticate) => {
  3830. class AuthPrompt extends FormPrompt {
  3831. constructor(options) {
  3832. super(options);
  3833. }
  3834. async submit() {
  3835. this.value = await authenticate.call(this, this.values, this.state);
  3836. super.base.submit.call(this);
  3837. }
  3838. static create(authenticate) {
  3839. return factory(authenticate);
  3840. }
  3841. }
  3842. return AuthPrompt;
  3843. };
  3844. module.exports = factory();
  3845. /***/ }),
  3846. /***/ 23838:
  3847. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  3848. "use strict";
  3849. const Prompt = __webpack_require__(232);
  3850. const { isPrimitive, hasColor } = __webpack_require__(83546);
  3851. class BooleanPrompt extends Prompt {
  3852. constructor(options) {
  3853. super(options);
  3854. this.cursorHide();
  3855. }
  3856. async initialize() {
  3857. let initial = await this.resolve(this.initial, this.state);
  3858. this.input = await this.cast(initial);
  3859. await super.initialize();
  3860. }
  3861. dispatch(ch) {
  3862. if (!this.isValue(ch)) return this.alert();
  3863. this.input = ch;
  3864. return this.submit();
  3865. }
  3866. format(value) {
  3867. let { styles, state } = this;
  3868. return !state.submitted ? styles.primary(value) : styles.success(value);
  3869. }
  3870. cast(input) {
  3871. return this.isTrue(input);
  3872. }
  3873. isTrue(input) {
  3874. return /^[ty1]/i.test(input);
  3875. }
  3876. isFalse(input) {
  3877. return /^[fn0]/i.test(input);
  3878. }
  3879. isValue(value) {
  3880. return isPrimitive(value) && (this.isTrue(value) || this.isFalse(value));
  3881. }
  3882. async hint() {
  3883. if (this.state.status === 'pending') {
  3884. let hint = await this.element('hint');
  3885. if (!hasColor(hint)) {
  3886. return this.styles.muted(hint);
  3887. }
  3888. return hint;
  3889. }
  3890. }
  3891. async render() {
  3892. let { input, size } = this.state;
  3893. let prefix = await this.prefix();
  3894. let sep = await this.separator();
  3895. let msg = await this.message();
  3896. let hint = this.styles.muted(this.default);
  3897. let promptLine = [prefix, msg, hint, sep].filter(Boolean).join(' ');
  3898. this.state.prompt = promptLine;
  3899. let header = await this.header();
  3900. let value = this.value = this.cast(input);
  3901. let output = await this.format(value);
  3902. let help = (await this.error()) || (await this.hint());
  3903. let footer = await this.footer();
  3904. if (help && !promptLine.includes(help)) output += ' ' + help;
  3905. promptLine += ' ' + output;
  3906. this.clear(size);
  3907. this.write([header, promptLine, footer].filter(Boolean).join('\n'));
  3908. this.restore();
  3909. }
  3910. set value(value) {
  3911. super.value = value;
  3912. }
  3913. get value() {
  3914. return this.cast(super.value);
  3915. }
  3916. }
  3917. module.exports = BooleanPrompt;
  3918. /***/ }),
  3919. /***/ 29920:
  3920. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  3921. module.exports = {
  3922. ArrayPrompt: __webpack_require__(98575),
  3923. AuthPrompt: __webpack_require__(66926),
  3924. BooleanPrompt: __webpack_require__(23838),
  3925. NumberPrompt: __webpack_require__(45376),
  3926. StringPrompt: __webpack_require__(43391)
  3927. };
  3928. /***/ }),
  3929. /***/ 45376:
  3930. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  3931. "use strict";
  3932. const StringPrompt = __webpack_require__(43391);
  3933. class NumberPrompt extends StringPrompt {
  3934. constructor(options = {}) {
  3935. super({ style: 'number', ...options });
  3936. this.min = this.isValue(options.min) ? this.toNumber(options.min) : -Infinity;
  3937. this.max = this.isValue(options.max) ? this.toNumber(options.max) : Infinity;
  3938. this.delay = options.delay != null ? options.delay : 1000;
  3939. this.float = options.float !== false;
  3940. this.round = options.round === true || options.float === false;
  3941. this.major = options.major || 10;
  3942. this.minor = options.minor || 1;
  3943. this.initial = options.initial != null ? options.initial : '';
  3944. this.input = String(this.initial);
  3945. this.cursor = this.input.length;
  3946. this.cursorShow();
  3947. }
  3948. append(ch) {
  3949. if (!/[-+.]/.test(ch) || (ch === '.' && this.input.includes('.'))) {
  3950. return this.alert('invalid number');
  3951. }
  3952. return super.append(ch);
  3953. }
  3954. number(ch) {
  3955. return super.append(ch);
  3956. }
  3957. next() {
  3958. if (this.input && this.input !== this.initial) return this.alert();
  3959. if (!this.isValue(this.initial)) return this.alert();
  3960. this.input = this.initial;
  3961. this.cursor = String(this.initial).length;
  3962. return this.render();
  3963. }
  3964. up(number) {
  3965. let step = number || this.minor;
  3966. let num = this.toNumber(this.input);
  3967. if (num > this.max + step) return this.alert();
  3968. this.input = `${num + step}`;
  3969. return this.render();
  3970. }
  3971. down(number) {
  3972. let step = number || this.minor;
  3973. let num = this.toNumber(this.input);
  3974. if (num < this.min - step) return this.alert();
  3975. this.input = `${num - step}`;
  3976. return this.render();
  3977. }
  3978. shiftDown() {
  3979. return this.down(this.major);
  3980. }
  3981. shiftUp() {
  3982. return this.up(this.major);
  3983. }
  3984. format(input = this.input) {
  3985. if (typeof this.options.format === 'function') {
  3986. return this.options.format.call(this, input);
  3987. }
  3988. return this.styles.info(input);
  3989. }
  3990. toNumber(value = '') {
  3991. return this.float ? +value : Math.round(+value);
  3992. }
  3993. isValue(value) {
  3994. return /^[-+]?[0-9]+((\.)|(\.[0-9]+))?$/.test(value);
  3995. }
  3996. submit() {
  3997. let value = [this.input, this.initial].find(v => this.isValue(v));
  3998. this.value = this.toNumber(value || 0);
  3999. return super.submit();
  4000. }
  4001. }
  4002. module.exports = NumberPrompt;
  4003. /***/ }),
  4004. /***/ 43391:
  4005. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  4006. "use strict";
  4007. const Prompt = __webpack_require__(232);
  4008. const placeholder = __webpack_require__(12786);
  4009. const { isPrimitive } = __webpack_require__(83546);
  4010. class StringPrompt extends Prompt {
  4011. constructor(options) {
  4012. super(options);
  4013. this.initial = isPrimitive(this.initial) ? String(this.initial) : '';
  4014. if (this.initial) this.cursorHide();
  4015. this.state.prevCursor = 0;
  4016. this.state.clipboard = [];
  4017. }
  4018. async keypress(input, key = {}) {
  4019. let prev = this.state.prevKeypress;
  4020. this.state.prevKeypress = key;
  4021. if (this.options.multiline === true && key.name === 'return') {
  4022. if (!prev || prev.name !== 'return') {
  4023. return this.append('\n', key);
  4024. }
  4025. }
  4026. return super.keypress(input, key);
  4027. }
  4028. moveCursor(n) {
  4029. this.cursor += n;
  4030. }
  4031. reset() {
  4032. this.input = this.value = '';
  4033. this.cursor = 0;
  4034. return this.render();
  4035. }
  4036. dispatch(ch, key) {
  4037. if (!ch || key.ctrl || key.code) return this.alert();
  4038. this.append(ch);
  4039. }
  4040. append(ch) {
  4041. let { cursor, input } = this.state;
  4042. this.input = `${input}`.slice(0, cursor) + ch + `${input}`.slice(cursor);
  4043. this.moveCursor(String(ch).length);
  4044. this.render();
  4045. }
  4046. insert(str) {
  4047. this.append(str);
  4048. }
  4049. delete() {
  4050. let { cursor, input } = this.state;
  4051. if (cursor <= 0) return this.alert();
  4052. this.input = `${input}`.slice(0, cursor - 1) + `${input}`.slice(cursor);
  4053. this.moveCursor(-1);
  4054. this.render();
  4055. }
  4056. deleteForward() {
  4057. let { cursor, input } = this.state;
  4058. if (input[cursor] === void 0) return this.alert();
  4059. this.input = `${input}`.slice(0, cursor) + `${input}`.slice(cursor + 1);
  4060. this.render();
  4061. }
  4062. cutForward() {
  4063. let pos = this.cursor;
  4064. if (this.input.length <= pos) return this.alert();
  4065. this.state.clipboard.push(this.input.slice(pos));
  4066. this.input = this.input.slice(0, pos);
  4067. this.render();
  4068. }
  4069. cutLeft() {
  4070. let pos = this.cursor;
  4071. if (pos === 0) return this.alert();
  4072. let before = this.input.slice(0, pos);
  4073. let after = this.input.slice(pos);
  4074. let words = before.split(' ');
  4075. this.state.clipboard.push(words.pop());
  4076. this.input = words.join(' ');
  4077. this.cursor = this.input.length;
  4078. this.input += after;
  4079. this.render();
  4080. }
  4081. paste() {
  4082. if (!this.state.clipboard.length) return this.alert();
  4083. this.insert(this.state.clipboard.pop());
  4084. this.render();
  4085. }
  4086. toggleCursor() {
  4087. if (this.state.prevCursor) {
  4088. this.cursor = this.state.prevCursor;
  4089. this.state.prevCursor = 0;
  4090. } else {
  4091. this.state.prevCursor = this.cursor;
  4092. this.cursor = 0;
  4093. }
  4094. this.render();
  4095. }
  4096. first() {
  4097. this.cursor = 0;
  4098. this.render();
  4099. }
  4100. last() {
  4101. this.cursor = this.input.length - 1;
  4102. this.render();
  4103. }
  4104. next() {
  4105. let init = this.initial != null ? String(this.initial) : '';
  4106. if (!init || !init.startsWith(this.input)) return this.alert();
  4107. this.input = this.initial;
  4108. this.cursor = this.initial.length;
  4109. this.render();
  4110. }
  4111. prev() {
  4112. if (!this.input) return this.alert();
  4113. this.reset();
  4114. }
  4115. backward() {
  4116. return this.left();
  4117. }
  4118. forward() {
  4119. return this.right();
  4120. }
  4121. right() {
  4122. if (this.cursor >= this.input.length) return this.alert();
  4123. this.moveCursor(1);
  4124. return this.render();
  4125. }
  4126. left() {
  4127. if (this.cursor <= 0) return this.alert();
  4128. this.moveCursor(-1);
  4129. return this.render();
  4130. }
  4131. isValue(value) {
  4132. return !!value;
  4133. }
  4134. async format(input = this.value) {
  4135. let initial = await this.resolve(this.initial, this.state);
  4136. if (!this.state.submitted) {
  4137. return placeholder(this, { input, initial, pos: this.cursor });
  4138. }
  4139. return this.styles.submitted(input || initial);
  4140. }
  4141. async render() {
  4142. let size = this.state.size;
  4143. let prefix = await this.prefix();
  4144. let separator = await this.separator();
  4145. let message = await this.message();
  4146. let prompt = [prefix, message, separator].filter(Boolean).join(' ');
  4147. this.state.prompt = prompt;
  4148. let header = await this.header();
  4149. let output = await this.format();
  4150. let help = (await this.error()) || (await this.hint());
  4151. let footer = await this.footer();
  4152. if (help && !output.includes(help)) output += ' ' + help;
  4153. prompt += ' ' + output;
  4154. this.clear(size);
  4155. this.write([header, prompt, footer].filter(Boolean).join('\n'));
  4156. this.restore();
  4157. }
  4158. }
  4159. module.exports = StringPrompt;
  4160. /***/ }),
  4161. /***/ 83546:
  4162. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4163. "use strict";
  4164. const toString = Object.prototype.toString;
  4165. const colors = __webpack_require__(53692);
  4166. let called = false;
  4167. let fns = [];
  4168. const complements = {
  4169. 'yellow': 'blue',
  4170. 'cyan': 'red',
  4171. 'green': 'magenta',
  4172. 'black': 'white',
  4173. 'blue': 'yellow',
  4174. 'red': 'cyan',
  4175. 'magenta': 'green',
  4176. 'white': 'black'
  4177. };
  4178. exports.longest = (arr, prop) => {
  4179. return arr.reduce((a, v) => Math.max(a, prop ? v[prop].length : v.length), 0);
  4180. };
  4181. exports.hasColor = str => !!str && colors.hasColor(str);
  4182. const isObject = exports.isObject = val => {
  4183. return val !== null && typeof val === 'object' && !Array.isArray(val);
  4184. };
  4185. exports.nativeType = val => {
  4186. return toString.call(val).slice(8, -1).toLowerCase().replace(/\s/g, '');
  4187. };
  4188. exports.isAsyncFn = val => {
  4189. return exports.nativeType(val) === 'asyncfunction';
  4190. };
  4191. exports.isPrimitive = val => {
  4192. return val != null && typeof val !== 'object' && typeof val !== 'function';
  4193. };
  4194. exports.resolve = (context, value, ...rest) => {
  4195. if (typeof value === 'function') {
  4196. return value.call(context, ...rest);
  4197. }
  4198. return value;
  4199. };
  4200. exports.scrollDown = (choices = []) => [...choices.slice(1), choices[0]];
  4201. exports.scrollUp = (choices = []) => [choices.pop(), ...choices];
  4202. exports.reorder = (arr = []) => {
  4203. let res = arr.slice();
  4204. res.sort((a, b) => {
  4205. if (a.index > b.index) return 1;
  4206. if (a.index < b.index) return -1;
  4207. return 0;
  4208. });
  4209. return res;
  4210. };
  4211. exports.swap = (arr, index, pos) => {
  4212. let len = arr.length;
  4213. let idx = pos === len ? 0 : pos < 0 ? len - 1 : pos;
  4214. let choice = arr[index];
  4215. arr[index] = arr[idx];
  4216. arr[idx] = choice;
  4217. };
  4218. exports.width = (stream, fallback = 80) => {
  4219. let columns = (stream && stream.columns) ? stream.columns : fallback;
  4220. if (stream && typeof stream.getWindowSize === 'function') {
  4221. columns = stream.getWindowSize()[0];
  4222. }
  4223. if (process.platform === 'win32') {
  4224. return columns - 1;
  4225. }
  4226. return columns;
  4227. };
  4228. exports.height = (stream, fallback = 20) => {
  4229. let rows = (stream && stream.rows) ? stream.rows : fallback;
  4230. if (stream && typeof stream.getWindowSize === 'function') {
  4231. rows = stream.getWindowSize()[1];
  4232. }
  4233. return rows;
  4234. };
  4235. exports.wordWrap = (str, options = {}) => {
  4236. if (!str) return str;
  4237. if (typeof options === 'number') {
  4238. options = { width: options };
  4239. }
  4240. let { indent = '', newline = ('\n' + indent), width = 80 } = options;
  4241. let spaces = (newline + indent).match(/[^\S\n]/g) || [];
  4242. width -= spaces.length;
  4243. let source = `.{1,${width}}([\\s\\u200B]+|$)|[^\\s\\u200B]+?([\\s\\u200B]+|$)`;
  4244. let output = str.trim();
  4245. let regex = new RegExp(source, 'g');
  4246. let lines = output.match(regex) || [];
  4247. lines = lines.map(line => line.replace(/\n$/, ''));
  4248. if (options.padEnd) lines = lines.map(line => line.padEnd(width, ' '));
  4249. if (options.padStart) lines = lines.map(line => line.padStart(width, ' '));
  4250. return indent + lines.join(newline);
  4251. };
  4252. exports.unmute = color => {
  4253. let name = color.stack.find(n => colors.keys.color.includes(n));
  4254. if (name) {
  4255. return colors[name];
  4256. }
  4257. let bg = color.stack.find(n => n.slice(2) === 'bg');
  4258. if (bg) {
  4259. return colors[name.slice(2)];
  4260. }
  4261. return str => str;
  4262. };
  4263. exports.pascal = str => str ? str[0].toUpperCase() + str.slice(1) : '';
  4264. exports.inverse = color => {
  4265. if (!color || !color.stack) return color;
  4266. let name = color.stack.find(n => colors.keys.color.includes(n));
  4267. if (name) {
  4268. let col = colors['bg' + exports.pascal(name)];
  4269. return col ? col.black : color;
  4270. }
  4271. let bg = color.stack.find(n => n.slice(0, 2) === 'bg');
  4272. if (bg) {
  4273. return colors[bg.slice(2).toLowerCase()] || color;
  4274. }
  4275. return colors.none;
  4276. };
  4277. exports.complement = color => {
  4278. if (!color || !color.stack) return color;
  4279. let name = color.stack.find(n => colors.keys.color.includes(n));
  4280. let bg = color.stack.find(n => n.slice(0, 2) === 'bg');
  4281. if (name && !bg) {
  4282. return colors[complements[name] || name];
  4283. }
  4284. if (bg) {
  4285. let lower = bg.slice(2).toLowerCase();
  4286. let comp = complements[lower];
  4287. if (!comp) return color;
  4288. return colors['bg' + exports.pascal(comp)] || color;
  4289. }
  4290. return colors.none;
  4291. };
  4292. exports.meridiem = date => {
  4293. let hours = date.getHours();
  4294. let minutes = date.getMinutes();
  4295. let ampm = hours >= 12 ? 'pm' : 'am';
  4296. hours = hours % 12;
  4297. let hrs = hours === 0 ? 12 : hours;
  4298. let min = minutes < 10 ? '0' + minutes : minutes;
  4299. return hrs + ':' + min + ' ' + ampm;
  4300. };
  4301. /**
  4302. * Set a value on the given object.
  4303. * @param {Object} obj
  4304. * @param {String} prop
  4305. * @param {any} value
  4306. */
  4307. exports.set = (obj = {}, prop = '', val) => {
  4308. return prop.split('.').reduce((acc, k, i, arr) => {
  4309. let value = arr.length - 1 > i ? (acc[k] || {}) : val;
  4310. if (!exports.isObject(value) && i < arr.length - 1) value = {};
  4311. return (acc[k] = value);
  4312. }, obj);
  4313. };
  4314. /**
  4315. * Get a value from the given object.
  4316. * @param {Object} obj
  4317. * @param {String} prop
  4318. */
  4319. exports.get = (obj = {}, prop = '', fallback) => {
  4320. let value = obj[prop] == null
  4321. ? prop.split('.').reduce((acc, k) => acc && acc[k], obj)
  4322. : obj[prop];
  4323. return value == null ? fallback : value;
  4324. };
  4325. exports.mixin = (target, b) => {
  4326. if (!isObject(target)) return b;
  4327. if (!isObject(b)) return target;
  4328. for (let key of Object.keys(b)) {
  4329. let desc = Object.getOwnPropertyDescriptor(b, key);
  4330. if (desc.hasOwnProperty('value')) {
  4331. if (target.hasOwnProperty(key) && isObject(desc.value)) {
  4332. let existing = Object.getOwnPropertyDescriptor(target, key);
  4333. if (isObject(existing.value)) {
  4334. target[key] = exports.merge({}, target[key], b[key]);
  4335. } else {
  4336. Reflect.defineProperty(target, key, desc);
  4337. }
  4338. } else {
  4339. Reflect.defineProperty(target, key, desc);
  4340. }
  4341. } else {
  4342. Reflect.defineProperty(target, key, desc);
  4343. }
  4344. }
  4345. return target;
  4346. };
  4347. exports.merge = (...args) => {
  4348. let target = {};
  4349. for (let ele of args) exports.mixin(target, ele);
  4350. return target;
  4351. };
  4352. exports.mixinEmitter = (obj, emitter) => {
  4353. let proto = emitter.constructor.prototype;
  4354. for (let key of Object.keys(proto)) {
  4355. let val = proto[key];
  4356. if (typeof val === 'function') {
  4357. exports.define(obj, key, val.bind(emitter));
  4358. } else {
  4359. exports.define(obj, key, val);
  4360. }
  4361. }
  4362. };
  4363. exports.onExit = callback => {
  4364. const onExit = (quit, code) => {
  4365. if (called) return;
  4366. called = true;
  4367. fns.forEach(fn => fn());
  4368. if (quit === true) {
  4369. process.exit(128 + code);
  4370. }
  4371. };
  4372. if (fns.length === 0) {
  4373. process.once('SIGTERM', onExit.bind(null, true, 15));
  4374. process.once('SIGINT', onExit.bind(null, true, 2));
  4375. process.once('exit', onExit);
  4376. }
  4377. fns.push(callback);
  4378. };
  4379. exports.define = (obj, key, value) => {
  4380. Reflect.defineProperty(obj, key, { value });
  4381. };
  4382. exports.defineExport = (obj, key, fn) => {
  4383. let custom;
  4384. Reflect.defineProperty(obj, key, {
  4385. enumerable: true,
  4386. configurable: true,
  4387. set(val) {
  4388. custom = val;
  4389. },
  4390. get() {
  4391. return custom ? custom() : fn();
  4392. }
  4393. });
  4394. };
  4395. /***/ })
  4396. };
  4397. ;
  4398. //# sourceMappingURL=31.index.js.map