index.js 73 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338
  1. var __defProp = Object.defineProperty;
  2. var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
  3. // src/constants/ansi-escape-codes.constants.ts
  4. var ANSI_ESCAPE = "\x1B[";
  5. var ANSI_ESCAPE_CODES = {
  6. CURSOR_HIDE: ANSI_ESCAPE + "?25l",
  7. CURSOR_SHOW: ANSI_ESCAPE + "?25h"
  8. };
  9. // src/constants/environment-variables.constants.ts
  10. var ListrEnvironmentVariables = /* @__PURE__ */ ((ListrEnvironmentVariables2) => {
  11. ListrEnvironmentVariables2["FORCE_UNICODE"] = "LISTR_FORCE_UNICODE";
  12. ListrEnvironmentVariables2["FORCE_TTY"] = "LISTR_FORCE_TTY";
  13. ListrEnvironmentVariables2["DISABLE_COLOR"] = "NO_COLOR";
  14. ListrEnvironmentVariables2["FORCE_COLOR"] = "FORCE_COLOR";
  15. return ListrEnvironmentVariables2;
  16. })(ListrEnvironmentVariables || {});
  17. // src/constants/listr-error.constants.ts
  18. var ListrErrorTypes = /* @__PURE__ */ ((ListrErrorTypes2) => {
  19. ListrErrorTypes2["WILL_RETRY"] = "WILL_RETRY";
  20. ListrErrorTypes2["WILL_ROLLBACK"] = "WILL_ROLLBACK";
  21. ListrErrorTypes2["HAS_FAILED_TO_ROLLBACK"] = "HAS_FAILED_TO_ROLLBACK";
  22. ListrErrorTypes2["HAS_FAILED"] = "HAS_FAILED";
  23. ListrErrorTypes2["HAS_FAILED_WITHOUT_ERROR"] = "HAS_FAILED_WITHOUT_ERROR";
  24. return ListrErrorTypes2;
  25. })(ListrErrorTypes || {});
  26. // src/constants/listr-events.constants.ts
  27. var ListrEventType = /* @__PURE__ */ ((ListrEventType2) => {
  28. ListrEventType2["SHOULD_REFRESH_RENDER"] = "SHOUD_REFRESH_RENDER";
  29. return ListrEventType2;
  30. })(ListrEventType || {});
  31. // src/constants/listr-renderer.constants.ts
  32. var ListrRendererSelection = /* @__PURE__ */ ((ListrRendererSelection2) => {
  33. ListrRendererSelection2["PRIMARY"] = "PRIMARY";
  34. ListrRendererSelection2["SECONDARY"] = "SECONDARY";
  35. ListrRendererSelection2["SILENT"] = "SILENT";
  36. return ListrRendererSelection2;
  37. })(ListrRendererSelection || {});
  38. // src/constants/listr-task-events.constants.ts
  39. var ListrTaskEventType = /* @__PURE__ */ ((ListrTaskEventType2) => {
  40. ListrTaskEventType2["TITLE"] = "TITLE";
  41. ListrTaskEventType2["STATE"] = "STATE";
  42. ListrTaskEventType2["ENABLED"] = "ENABLED";
  43. ListrTaskEventType2["SUBTASK"] = "SUBTASK";
  44. ListrTaskEventType2["PROMPT"] = "PROMPT";
  45. ListrTaskEventType2["OUTPUT"] = "OUTPUT";
  46. ListrTaskEventType2["MESSAGE"] = "MESSAGE";
  47. ListrTaskEventType2["CLOSED"] = "CLOSED";
  48. return ListrTaskEventType2;
  49. })(ListrTaskEventType || {});
  50. // src/constants/listr-task-state.constants.ts
  51. var ListrTaskState = /* @__PURE__ */ ((ListrTaskState2) => {
  52. ListrTaskState2["WAITING"] = "WAITING";
  53. ListrTaskState2["STARTED"] = "STARTED";
  54. ListrTaskState2["COMPLETED"] = "COMPLETED";
  55. ListrTaskState2["FAILED"] = "FAILED";
  56. ListrTaskState2["SKIPPED"] = "SKIPPED";
  57. ListrTaskState2["ROLLING_BACK"] = "ROLLING_BACK";
  58. ListrTaskState2["ROLLED_BACK"] = "ROLLED_BACK";
  59. ListrTaskState2["RETRY"] = "RETRY";
  60. ListrTaskState2["PAUSED"] = "PAUSED";
  61. ListrTaskState2["PROMPT"] = "PROMPT";
  62. ListrTaskState2["PROMPT_COMPLETED"] = "PROMPT_COMPLETED";
  63. ListrTaskState2["PROMPT_FAILED"] = "PROMPT_FAILED";
  64. return ListrTaskState2;
  65. })(ListrTaskState || {});
  66. // src/lib/event-manager.ts
  67. import EventEmitter from "eventemitter3";
  68. var EventManager = class {
  69. static {
  70. __name(this, "EventManager");
  71. }
  72. emitter = new EventEmitter();
  73. emit(dispatch, args) {
  74. this.emitter.emit(dispatch, args);
  75. }
  76. on(dispatch, handler) {
  77. this.emitter.addListener(dispatch, handler);
  78. }
  79. once(dispatch, handler) {
  80. this.emitter.once(dispatch, handler);
  81. }
  82. off(dispatch, handler) {
  83. this.emitter.off(dispatch, handler);
  84. }
  85. complete() {
  86. this.emitter.removeAllListeners();
  87. }
  88. };
  89. // src/interfaces/event.interface.ts
  90. var BaseEventMap = class {
  91. static {
  92. __name(this, "BaseEventMap");
  93. }
  94. };
  95. // src/utils/environment/is-observable.ts
  96. function isObservable(obj) {
  97. return !!obj && typeof obj === "object" && typeof obj.subscribe === "function";
  98. }
  99. __name(isObservable, "isObservable");
  100. // src/utils/environment/is-readable.ts
  101. function isReadable(obj) {
  102. return !!obj && typeof obj === "object" && obj.readable === true && typeof obj.read === "function" && typeof obj.on === "function";
  103. }
  104. __name(isReadable, "isReadable");
  105. // src/utils/environment/is-unicode-supported.ts
  106. function isUnicodeSupported() {
  107. return !!process.env["LISTR_FORCE_UNICODE" /* FORCE_UNICODE */] || process.platform !== "win32" || !!process.env.CI || !!process.env.WT_SESSION || process.env.TERM_PROGRAM === "vscode" || process.env.TERM === "xterm-256color" || process.env.TERM === "alacritty";
  108. }
  109. __name(isUnicodeSupported, "isUnicodeSupported");
  110. // src/utils/format/cleanse-ansi.constants.ts
  111. var CLEAR_LINE_REGEX = "(?:\\u001b|\\u009b)\\[[\\=><~/#&.:=?%@~_-]*[0-9]*[\\a-ln-tqyz=><~/#&.:=?%@~_-]+";
  112. var BELL_REGEX = /\u0007/;
  113. // src/utils/format/cleanse-ansi.ts
  114. function cleanseAnsi(chunk) {
  115. return String(chunk).replace(new RegExp(CLEAR_LINE_REGEX, "gmi"), "").replace(new RegExp(BELL_REGEX, "gmi"), "").trim();
  116. }
  117. __name(cleanseAnsi, "cleanseAnsi");
  118. // src/utils/format/color.ts
  119. import { createColors } from "colorette";
  120. var color = createColors();
  121. // src/utils/format/indent.ts
  122. function indent(string, count) {
  123. return string.replace(/^(?!\s*$)/gm, " ".repeat(count));
  124. }
  125. __name(indent, "indent");
  126. // src/utils/format/figures.ts
  127. var FIGURES_MAIN = {
  128. warning: "\u26A0",
  129. cross: "\u2716",
  130. arrowDown: "\u2193",
  131. tick: "\u2714",
  132. arrowRight: "\u2192",
  133. pointer: "\u276F",
  134. checkboxOn: "\u2612",
  135. arrowLeft: "\u2190",
  136. squareSmallFilled: "\u25FC",
  137. pointerSmall: "\u203A"
  138. };
  139. var FIGURES_FALLBACK = {
  140. ...FIGURES_MAIN,
  141. warning: "\u203C",
  142. cross: "\xD7",
  143. tick: "\u221A",
  144. pointer: ">",
  145. checkboxOn: "[\xD7]",
  146. squareSmallFilled: "\u25A0"
  147. };
  148. var figures = isUnicodeSupported() ? FIGURES_MAIN : FIGURES_FALLBACK;
  149. // src/utils/format/splat.ts
  150. import { format } from "util";
  151. function splat(message, ...splat2) {
  152. return format(String(message), ...splat2);
  153. }
  154. __name(splat, "splat");
  155. // src/utils/logger/logger.constants.ts
  156. var ListrLogLevels = /* @__PURE__ */ ((ListrLogLevels2) => {
  157. ListrLogLevels2["STARTED"] = "STARTED";
  158. ListrLogLevels2["COMPLETED"] = "COMPLETED";
  159. ListrLogLevels2["FAILED"] = "FAILED";
  160. ListrLogLevels2["SKIPPED"] = "SKIPPED";
  161. ListrLogLevels2["OUTPUT"] = "OUTPUT";
  162. ListrLogLevels2["TITLE"] = "TITLE";
  163. ListrLogLevels2["ROLLBACK"] = "ROLLBACK";
  164. ListrLogLevels2["RETRY"] = "RETRY";
  165. ListrLogLevels2["PROMPT"] = "PROMPT";
  166. ListrLogLevels2["PAUSED"] = "PAUSED";
  167. return ListrLogLevels2;
  168. })(ListrLogLevels || {});
  169. var LISTR_LOGGER_STYLE = {
  170. icon: {
  171. ["STARTED" /* STARTED */]: figures.pointer,
  172. ["FAILED" /* FAILED */]: figures.cross,
  173. ["SKIPPED" /* SKIPPED */]: figures.arrowDown,
  174. ["COMPLETED" /* COMPLETED */]: figures.tick,
  175. ["OUTPUT" /* OUTPUT */]: figures.pointerSmall,
  176. ["TITLE" /* TITLE */]: figures.arrowRight,
  177. ["RETRY" /* RETRY */]: figures.warning,
  178. ["ROLLBACK" /* ROLLBACK */]: figures.arrowLeft,
  179. ["PAUSED" /* PAUSED */]: figures.squareSmallFilled
  180. },
  181. color: {
  182. ["STARTED" /* STARTED */]: color.yellow,
  183. ["FAILED" /* FAILED */]: color.red,
  184. ["SKIPPED" /* SKIPPED */]: color.yellow,
  185. ["COMPLETED" /* COMPLETED */]: color.green,
  186. ["RETRY" /* RETRY */]: color.yellowBright,
  187. ["ROLLBACK" /* ROLLBACK */]: color.redBright,
  188. ["PAUSED" /* PAUSED */]: color.yellowBright
  189. }
  190. };
  191. var LISTR_LOGGER_STDERR_LEVELS = ["RETRY" /* RETRY */, "ROLLBACK" /* ROLLBACK */, "FAILED" /* FAILED */];
  192. // src/utils/logger/logger.ts
  193. import { EOL } from "os";
  194. var ListrLogger = class {
  195. constructor(options) {
  196. this.options = options;
  197. this.options = {
  198. useIcons: true,
  199. toStderr: [],
  200. ...options ?? {}
  201. };
  202. this.options.fields ??= {};
  203. this.options.fields.prefix ??= [];
  204. this.options.fields.suffix ??= [];
  205. this.process = this.options.processOutput ?? new ProcessOutput();
  206. }
  207. static {
  208. __name(this, "ListrLogger");
  209. }
  210. process;
  211. log(level, message, options) {
  212. const output = this.format(level, message, options);
  213. if (this.options.toStderr.includes(level)) {
  214. this.process.toStderr(output);
  215. return;
  216. }
  217. this.process.toStdout(output);
  218. }
  219. toStdout(message, options, eol = true) {
  220. this.process.toStdout(this.format(null, message, options), eol);
  221. }
  222. toStderr(message, options, eol = true) {
  223. this.process.toStderr(this.format(null, message, options), eol);
  224. }
  225. wrap(message, options) {
  226. if (!message) {
  227. return message;
  228. }
  229. return this.applyFormat(`[${message}]`, options);
  230. }
  231. splat(...args) {
  232. const message = args.shift() ?? "";
  233. return args.length === 0 ? message : splat(message, args);
  234. }
  235. suffix(message, ...suffixes) {
  236. suffixes.filter(Boolean).forEach((suffix) => {
  237. message += this.spacing(message);
  238. if (typeof suffix === "string") {
  239. message += this.wrap(suffix);
  240. } else if (typeof suffix === "object") {
  241. suffix.args ??= [];
  242. if (typeof suffix.condition === "function" ? !suffix.condition(...suffix.args) : !(suffix.condition ?? true)) {
  243. return message;
  244. }
  245. message += this.wrap(typeof suffix.field === "function" ? suffix.field(...suffix.args) : suffix.field, {
  246. format: suffix?.format(...suffix.args)
  247. });
  248. }
  249. });
  250. return message;
  251. }
  252. prefix(message, ...prefixes) {
  253. prefixes.filter(Boolean).forEach((prefix) => {
  254. message = this.spacing(message) + message;
  255. if (typeof prefix === "string") {
  256. message = this.wrap(prefix) + message;
  257. } else if (typeof prefix === "object") {
  258. prefix.args ??= [];
  259. if (typeof prefix.condition === "function" ? !prefix.condition(...prefix.args) : !(prefix.condition ?? true)) {
  260. return message;
  261. }
  262. message = this.wrap(typeof prefix.field === "function" ? prefix.field(...prefix.args) : prefix.field, {
  263. format: prefix?.format()
  264. }) + message;
  265. }
  266. });
  267. return message;
  268. }
  269. fields(message, options) {
  270. if (this.options?.fields?.prefix) {
  271. message = this.prefix(message, ...this.options.fields.prefix);
  272. }
  273. if (options?.prefix) {
  274. message = this.prefix(message, ...options.prefix);
  275. }
  276. if (options?.suffix) {
  277. message = this.suffix(message, ...options.suffix);
  278. }
  279. if (this.options?.fields?.suffix) {
  280. message = this.suffix(message, ...this.options.fields.suffix);
  281. }
  282. return message;
  283. }
  284. icon(level, icon) {
  285. if (!level) {
  286. return null;
  287. }
  288. icon ||= this.options.icon?.[level];
  289. const coloring = this.options.color?.[level];
  290. if (icon && coloring) {
  291. icon = coloring(icon);
  292. }
  293. return icon;
  294. }
  295. format(level, message, options) {
  296. if (!Array.isArray(message)) {
  297. message = [message];
  298. }
  299. message = this.splat(message.shift(), ...message).toString().split(EOL).filter((m) => !m || m.trim() !== "").map((m) => {
  300. return this.style(
  301. level,
  302. this.fields(m, {
  303. prefix: Array.isArray(options?.prefix) ? options.prefix : [options?.prefix],
  304. suffix: Array.isArray(options?.suffix) ? options.suffix : [options?.suffix]
  305. })
  306. );
  307. }).join(EOL);
  308. return message;
  309. }
  310. style(level, message) {
  311. if (!level || !message) {
  312. return message;
  313. }
  314. const icon = this.icon(level, !this.options.useIcons && this.wrap(level));
  315. if (icon) {
  316. message = icon + " " + message;
  317. }
  318. return message;
  319. }
  320. applyFormat(message, options) {
  321. if (options?.format) {
  322. return options.format(message);
  323. }
  324. return message;
  325. }
  326. spacing(message) {
  327. return typeof message === "undefined" || message.trim() === "" ? "" : " ";
  328. }
  329. };
  330. // src/utils/process-output/process-output-buffer.ts
  331. import { StringDecoder } from "string_decoder";
  332. var ProcessOutputBuffer = class {
  333. constructor(options) {
  334. this.options = options;
  335. }
  336. static {
  337. __name(this, "ProcessOutputBuffer");
  338. }
  339. buffer = [];
  340. decoder = new StringDecoder();
  341. get all() {
  342. return this.buffer;
  343. }
  344. get last() {
  345. return this.buffer.at(-1);
  346. }
  347. get length() {
  348. return this.buffer.length;
  349. }
  350. write(data, ...args) {
  351. const callback = args[args.length - 1];
  352. this.buffer.push({
  353. time: Date.now(),
  354. stream: this.options?.stream,
  355. entry: this.decoder.write(typeof data === "string" ? Buffer.from(data, typeof args[0] === "string" ? args[0] : void 0) : Buffer.from(data))
  356. });
  357. if (this.options?.limit) {
  358. this.buffer = this.buffer.slice(-this.options.limit);
  359. }
  360. if (typeof callback === "function") {
  361. callback();
  362. }
  363. return true;
  364. }
  365. reset() {
  366. this.buffer = [];
  367. }
  368. };
  369. // src/utils/process-output/process-output-stream.ts
  370. var ProcessOutputStream = class {
  371. constructor(stream) {
  372. this.stream = stream;
  373. this.method = stream.write;
  374. this.buffer = new ProcessOutputBuffer({ stream });
  375. }
  376. static {
  377. __name(this, "ProcessOutputStream");
  378. }
  379. method;
  380. buffer;
  381. get out() {
  382. return Object.assign({}, this.stream, {
  383. write: this.write.bind(this)
  384. });
  385. }
  386. hijack() {
  387. this.stream.write = this.buffer.write.bind(this.buffer);
  388. }
  389. release() {
  390. this.stream.write = this.method;
  391. const buffer = [...this.buffer.all];
  392. this.buffer.reset();
  393. return buffer;
  394. }
  395. write(...args) {
  396. return this.method.apply(this.stream, args);
  397. }
  398. };
  399. // src/utils/process-output/process-output.ts
  400. import { EOL as EOL2 } from "os";
  401. var ProcessOutput = class {
  402. constructor(stdout, stderr, options) {
  403. this.options = options;
  404. this.stream = {
  405. stdout: new ProcessOutputStream(stdout ?? process.stdout),
  406. stderr: new ProcessOutputStream(stderr ?? process.stderr)
  407. };
  408. this.options = {
  409. dump: ["stdout", "stderr"],
  410. leaveEmptyLine: true,
  411. ...options
  412. };
  413. }
  414. static {
  415. __name(this, "ProcessOutput");
  416. }
  417. stream;
  418. active;
  419. get stdout() {
  420. return this.stream.stdout.out;
  421. }
  422. get stderr() {
  423. return this.stream.stderr.out;
  424. }
  425. hijack() {
  426. if (this.active) {
  427. throw new Error("ProcessOutput has been already hijacked!");
  428. }
  429. this.stream.stdout.write(ANSI_ESCAPE_CODES.CURSOR_HIDE);
  430. Object.values(this.stream).forEach((stream) => stream.hijack());
  431. this.active = true;
  432. }
  433. release() {
  434. const output = Object.entries(this.stream).map(([name, stream]) => ({ name, buffer: stream.release() })).filter((output2) => this.options.dump.includes(output2.name)).flatMap((output2) => output2.buffer).sort((a, b) => a.time - b.time).map((message) => {
  435. return {
  436. ...message,
  437. entry: cleanseAnsi(message.entry)
  438. };
  439. }).filter((message) => message.entry);
  440. if (output.length > 0) {
  441. if (this.options.leaveEmptyLine) {
  442. this.stdout.write(EOL2);
  443. }
  444. output.forEach((message) => {
  445. const stream = message.stream ?? this.stdout;
  446. stream.write(message.entry + EOL2);
  447. });
  448. }
  449. this.stream.stdout.write(ANSI_ESCAPE_CODES.CURSOR_SHOW);
  450. this.active = false;
  451. }
  452. toStdout(buffer, eol = true) {
  453. if (eol) {
  454. buffer = buffer + EOL2;
  455. }
  456. return this.stream.stdout.write(buffer);
  457. }
  458. toStderr(buffer, eol = true) {
  459. if (eol) {
  460. buffer = buffer + EOL2;
  461. }
  462. return this.stream.stderr.write(buffer);
  463. }
  464. };
  465. // src/utils/process-output/writable.ts
  466. import { Writable } from "stream";
  467. function createWritable(cb) {
  468. const writable = new Writable();
  469. writable.rows = Infinity;
  470. writable.columns = Infinity;
  471. writable.write = (chunk) => {
  472. cb(chunk.toString());
  473. return true;
  474. };
  475. return writable;
  476. }
  477. __name(createWritable, "createWritable");
  478. // src/utils/prompts/adapter.ts
  479. var ListrPromptAdapter = class {
  480. constructor(task, wrapper) {
  481. this.task = task;
  482. this.wrapper = wrapper;
  483. }
  484. static {
  485. __name(this, "ListrPromptAdapter");
  486. }
  487. state;
  488. reportStarted() {
  489. this.state = this.task.state;
  490. if (this.task.prompt) {
  491. throw new PromptError("There is already an active prompt attached to this task which may not be cleaned up properly.");
  492. }
  493. this.task.prompt = this;
  494. this.task.state$ = "PROMPT" /* PROMPT */;
  495. }
  496. reportFailed() {
  497. this.task.state$ = "PROMPT_FAILED" /* PROMPT_FAILED */;
  498. this.restoreState();
  499. }
  500. reportCompleted() {
  501. this.task.state$ = "PROMPT_COMPLETED" /* PROMPT_COMPLETED */;
  502. this.restoreState();
  503. }
  504. restoreState() {
  505. this.task.prompt = void 0;
  506. if (this.state) {
  507. this.task.state = this.state;
  508. }
  509. }
  510. };
  511. // src/utils/ui/spinner.ts
  512. var Spinner = class {
  513. static {
  514. __name(this, "Spinner");
  515. }
  516. spinner = !isUnicodeSupported() ? ["-", "\\", "|", "/"] : ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
  517. id;
  518. spinnerPosition = 0;
  519. spin() {
  520. this.spinnerPosition = ++this.spinnerPosition % this.spinner.length;
  521. }
  522. fetch() {
  523. return this.spinner[this.spinnerPosition];
  524. }
  525. isRunning() {
  526. return !!this.id;
  527. }
  528. start(cb, interval = 100) {
  529. this.id = setInterval(() => {
  530. this.spin();
  531. if (cb) {
  532. cb();
  533. }
  534. }, interval);
  535. }
  536. stop() {
  537. clearInterval(this.id);
  538. }
  539. };
  540. // src/renderer/default/renderer.constants.ts
  541. var ListrDefaultRendererLogLevels = /* @__PURE__ */ ((ListrDefaultRendererLogLevels2) => {
  542. ListrDefaultRendererLogLevels2["SKIPPED_WITH_COLLAPSE"] = "SKIPPED_WITH_COLLAPSE";
  543. ListrDefaultRendererLogLevels2["SKIPPED_WITHOUT_COLLAPSE"] = "SKIPPED_WITHOUT_COLLAPSE";
  544. ListrDefaultRendererLogLevels2["OUTPUT"] = "OUTPUT";
  545. ListrDefaultRendererLogLevels2["OUTPUT_WITH_BOTTOMBAR"] = "OUTPUT_WITH_BOTTOMBAR";
  546. ListrDefaultRendererLogLevels2["PENDING"] = "PENDING";
  547. ListrDefaultRendererLogLevels2["COMPLETED"] = "COMPLETED";
  548. ListrDefaultRendererLogLevels2["COMPLETED_WITH_FAILED_SUBTASKS"] = "COMPLETED_WITH_FAILED_SUBTASKS";
  549. ListrDefaultRendererLogLevels2["COMPLETED_WITH_FAILED_SISTER_TASKS"] = "COMPLETED_WITH_SISTER_TASKS_FAILED";
  550. ListrDefaultRendererLogLevels2["RETRY"] = "RETRY";
  551. ListrDefaultRendererLogLevels2["ROLLING_BACK"] = "ROLLING_BACK";
  552. ListrDefaultRendererLogLevels2["ROLLED_BACK"] = "ROLLED_BACK";
  553. ListrDefaultRendererLogLevels2["FAILED"] = "FAILED";
  554. ListrDefaultRendererLogLevels2["FAILED_WITH_FAILED_SUBTASKS"] = "FAILED_WITH_SUBTASKS";
  555. ListrDefaultRendererLogLevels2["WAITING"] = "WAITING";
  556. ListrDefaultRendererLogLevels2["PAUSED"] = "PAUSED";
  557. return ListrDefaultRendererLogLevels2;
  558. })(ListrDefaultRendererLogLevels || {});
  559. var LISTR_DEFAULT_RENDERER_STYLE = {
  560. icon: {
  561. ["SKIPPED_WITH_COLLAPSE" /* SKIPPED_WITH_COLLAPSE */]: figures.arrowDown,
  562. ["SKIPPED_WITHOUT_COLLAPSE" /* SKIPPED_WITHOUT_COLLAPSE */]: figures.warning,
  563. ["OUTPUT" /* OUTPUT */]: figures.pointerSmall,
  564. ["OUTPUT_WITH_BOTTOMBAR" /* OUTPUT_WITH_BOTTOMBAR */]: figures.pointerSmall,
  565. ["PENDING" /* PENDING */]: figures.pointer,
  566. ["COMPLETED" /* COMPLETED */]: figures.tick,
  567. ["COMPLETED_WITH_FAILED_SUBTASKS" /* COMPLETED_WITH_FAILED_SUBTASKS */]: figures.warning,
  568. ["COMPLETED_WITH_SISTER_TASKS_FAILED" /* COMPLETED_WITH_FAILED_SISTER_TASKS */]: figures.squareSmallFilled,
  569. ["RETRY" /* RETRY */]: figures.warning,
  570. ["ROLLING_BACK" /* ROLLING_BACK */]: figures.warning,
  571. ["ROLLED_BACK" /* ROLLED_BACK */]: figures.arrowLeft,
  572. ["FAILED" /* FAILED */]: figures.cross,
  573. ["FAILED_WITH_SUBTASKS" /* FAILED_WITH_FAILED_SUBTASKS */]: figures.pointer,
  574. ["WAITING" /* WAITING */]: figures.squareSmallFilled,
  575. ["PAUSED" /* PAUSED */]: figures.squareSmallFilled
  576. },
  577. color: {
  578. ["SKIPPED_WITH_COLLAPSE" /* SKIPPED_WITH_COLLAPSE */]: color.yellow,
  579. ["SKIPPED_WITHOUT_COLLAPSE" /* SKIPPED_WITHOUT_COLLAPSE */]: color.yellow,
  580. ["PENDING" /* PENDING */]: color.yellow,
  581. ["COMPLETED" /* COMPLETED */]: color.green,
  582. ["COMPLETED_WITH_FAILED_SUBTASKS" /* COMPLETED_WITH_FAILED_SUBTASKS */]: color.yellow,
  583. ["COMPLETED_WITH_SISTER_TASKS_FAILED" /* COMPLETED_WITH_FAILED_SISTER_TASKS */]: color.red,
  584. ["RETRY" /* RETRY */]: color.yellowBright,
  585. ["ROLLING_BACK" /* ROLLING_BACK */]: color.redBright,
  586. ["ROLLED_BACK" /* ROLLED_BACK */]: color.redBright,
  587. ["FAILED" /* FAILED */]: color.red,
  588. ["FAILED_WITH_SUBTASKS" /* FAILED_WITH_FAILED_SUBTASKS */]: color.red,
  589. ["WAITING" /* WAITING */]: color.dim,
  590. ["PAUSED" /* PAUSED */]: color.yellowBright
  591. }
  592. };
  593. // src/renderer/default/renderer.ts
  594. import { EOL as EOL3 } from "os";
  595. // src/presets/timer/parser.ts
  596. function parseTimer(duration) {
  597. const seconds = Math.floor(duration / 1e3);
  598. const minutes = Math.floor(seconds / 60);
  599. let parsedTime;
  600. if (seconds === 0 && minutes === 0) {
  601. parsedTime = `0.${Math.floor(duration / 100)}s`;
  602. }
  603. if (seconds > 0) {
  604. parsedTime = `${seconds % 60}s`;
  605. }
  606. if (minutes > 0) {
  607. parsedTime = `${minutes}m${parsedTime}`;
  608. }
  609. return parsedTime;
  610. }
  611. __name(parseTimer, "parseTimer");
  612. // src/presets/timer/preset.ts
  613. var PRESET_TIMER = {
  614. condition: true,
  615. field: parseTimer,
  616. format: /* @__PURE__ */ __name(() => color.dim, "format")
  617. };
  618. // src/presets/timestamp/parser.ts
  619. function parseTimestamp() {
  620. const now = /* @__PURE__ */ new Date();
  621. return String(now.getHours()).padStart(2, "0") + ":" + String(now.getMinutes()).padStart(2, "0") + ":" + String(now.getSeconds()).padStart(2, "0");
  622. }
  623. __name(parseTimestamp, "parseTimestamp");
  624. // src/presets/timestamp/preset.ts
  625. var PRESET_TIMESTAMP = {
  626. condition: true,
  627. field: parseTimestamp,
  628. format: /* @__PURE__ */ __name(() => color.dim, "format")
  629. };
  630. // src/renderer/default/renderer.ts
  631. var DefaultRenderer = class _DefaultRenderer {
  632. constructor(tasks, options, events) {
  633. this.tasks = tasks;
  634. this.options = options;
  635. this.events = events;
  636. this.options = {
  637. ..._DefaultRenderer.rendererOptions,
  638. ...this.options,
  639. icon: {
  640. ...LISTR_DEFAULT_RENDERER_STYLE.icon,
  641. ...options?.icon ?? {}
  642. },
  643. color: {
  644. ...LISTR_DEFAULT_RENDERER_STYLE.color,
  645. ...options?.color ?? {}
  646. }
  647. };
  648. this.spinner = this.options.spinner ?? new Spinner();
  649. this.logger = this.options.logger ?? new ListrLogger({ useIcons: true, toStderr: [] });
  650. this.logger.options.icon = this.options.icon;
  651. this.logger.options.color = this.options.color;
  652. }
  653. static {
  654. __name(this, "DefaultRenderer");
  655. }
  656. static nonTTY = false;
  657. static rendererOptions = {
  658. indentation: 2,
  659. clearOutput: false,
  660. showSubtasks: true,
  661. collapseSubtasks: true,
  662. collapseSkips: true,
  663. showSkipMessage: true,
  664. suffixSkips: false,
  665. collapseErrors: true,
  666. showErrorMessage: true,
  667. suffixRetries: true,
  668. lazy: false,
  669. removeEmptyLines: true,
  670. formatOutput: "wrap",
  671. pausedTimer: {
  672. ...PRESET_TIMER,
  673. format: /* @__PURE__ */ __name(() => color.yellowBright, "format")
  674. }
  675. };
  676. static rendererTaskOptions = {
  677. outputBar: true
  678. };
  679. prompt;
  680. activePrompt;
  681. spinner;
  682. logger;
  683. updater;
  684. truncate;
  685. wrap;
  686. buffer = {
  687. output: /* @__PURE__ */ new Map(),
  688. bottom: /* @__PURE__ */ new Map()
  689. };
  690. cache = {
  691. render: /* @__PURE__ */ new Map(),
  692. rendererOptions: /* @__PURE__ */ new Map(),
  693. rendererTaskOptions: /* @__PURE__ */ new Map()
  694. };
  695. async render() {
  696. const { createLogUpdate } = await import("log-update");
  697. const { default: truncate } = await import("cli-truncate");
  698. const { default: wrap } = await import("wrap-ansi");
  699. this.updater = createLogUpdate(this.logger.process.stdout);
  700. this.truncate = truncate;
  701. this.wrap = wrap;
  702. this.logger.process.hijack();
  703. if (!this.options?.lazy) {
  704. this.spinner.start(() => {
  705. this.update();
  706. });
  707. }
  708. this.events.on("SHOUD_REFRESH_RENDER" /* SHOULD_REFRESH_RENDER */, () => {
  709. this.update();
  710. });
  711. }
  712. update() {
  713. this.updater(this.create());
  714. }
  715. end() {
  716. this.spinner.stop();
  717. this.updater.clear();
  718. this.updater.done();
  719. if (!this.options.clearOutput) {
  720. this.logger.process.toStdout(this.create({ prompt: false }));
  721. }
  722. this.logger.process.release();
  723. }
  724. create(options) {
  725. options = {
  726. tasks: true,
  727. bottomBar: true,
  728. prompt: true,
  729. ...options
  730. };
  731. const render = [];
  732. const renderTasks = this.renderer(this.tasks);
  733. const renderBottomBar = this.renderBottomBar();
  734. const renderPrompt = this.renderPrompt();
  735. if (options.tasks && renderTasks.length > 0) {
  736. render.push(...renderTasks);
  737. }
  738. if (options.bottomBar && renderBottomBar.length > 0) {
  739. if (render.length > 0) {
  740. render.push("");
  741. }
  742. render.push(...renderBottomBar);
  743. }
  744. if (options.prompt && renderPrompt.length > 0) {
  745. if (render.length > 0) {
  746. render.push("");
  747. }
  748. render.push(...renderPrompt);
  749. }
  750. return render.join(EOL3);
  751. }
  752. // eslint-disable-next-line complexity
  753. style(task, output = false) {
  754. const rendererOptions = this.cache.rendererOptions.get(task.id);
  755. if (task.isSkipped()) {
  756. if (output || rendererOptions.collapseSkips) {
  757. return this.logger.icon("SKIPPED_WITH_COLLAPSE" /* SKIPPED_WITH_COLLAPSE */);
  758. } else if (rendererOptions.collapseSkips === false) {
  759. return this.logger.icon("SKIPPED_WITHOUT_COLLAPSE" /* SKIPPED_WITHOUT_COLLAPSE */);
  760. }
  761. }
  762. if (output) {
  763. if (this.shouldOutputToBottomBar(task)) {
  764. return this.logger.icon("OUTPUT_WITH_BOTTOMBAR" /* OUTPUT_WITH_BOTTOMBAR */);
  765. }
  766. return this.logger.icon("OUTPUT" /* OUTPUT */);
  767. }
  768. if (task.hasSubtasks()) {
  769. if (task.isStarted() || task.isPrompt() && rendererOptions.showSubtasks !== false && !task.subtasks.every((subtask) => !subtask.hasTitle())) {
  770. return this.logger.icon("PENDING" /* PENDING */);
  771. } else if (task.isCompleted() && task.subtasks.some((subtask) => subtask.hasFailed())) {
  772. return this.logger.icon("COMPLETED_WITH_FAILED_SUBTASKS" /* COMPLETED_WITH_FAILED_SUBTASKS */);
  773. } else if (task.hasFailed()) {
  774. return this.logger.icon("FAILED_WITH_SUBTASKS" /* FAILED_WITH_FAILED_SUBTASKS */);
  775. }
  776. }
  777. if (task.isStarted() || task.isPrompt()) {
  778. return this.logger.icon("PENDING" /* PENDING */, !this.options?.lazy && this.spinner.fetch());
  779. } else if (task.isCompleted()) {
  780. return this.logger.icon("COMPLETED" /* COMPLETED */);
  781. } else if (task.isRetrying()) {
  782. return this.logger.icon("RETRY" /* RETRY */, !this.options?.lazy && this.spinner.fetch());
  783. } else if (task.isRollingBack()) {
  784. return this.logger.icon("ROLLING_BACK" /* ROLLING_BACK */, !this.options?.lazy && this.spinner.fetch());
  785. } else if (task.hasRolledBack()) {
  786. return this.logger.icon("ROLLED_BACK" /* ROLLED_BACK */);
  787. } else if (task.hasFailed()) {
  788. return this.logger.icon("FAILED" /* FAILED */);
  789. } else if (task.isPaused()) {
  790. return this.logger.icon("PAUSED" /* PAUSED */);
  791. }
  792. return this.logger.icon("WAITING" /* WAITING */);
  793. }
  794. format(message, icon, level) {
  795. if (message.trim() === "") {
  796. return [];
  797. }
  798. if (icon) {
  799. message = icon + " " + message;
  800. }
  801. let parsed;
  802. const columns = (process.stdout.columns ?? 80) - level * this.options.indentation - 2;
  803. switch (this.options.formatOutput) {
  804. case "truncate":
  805. parsed = message.split(EOL3).map((s, i) => {
  806. return this.truncate(this.indent(s, i), columns);
  807. });
  808. break;
  809. case "wrap":
  810. parsed = this.wrap(message, columns, { hard: true }).split(EOL3).map((s, i) => this.indent(s, i));
  811. break;
  812. default:
  813. throw new ListrRendererError("Format option for the renderer is wrong.");
  814. }
  815. if (this.options.removeEmptyLines) {
  816. parsed = parsed.filter(Boolean);
  817. }
  818. return parsed.map((str) => indent(str, level * this.options.indentation));
  819. }
  820. shouldOutputToOutputBar(task) {
  821. const outputBar = this.cache.rendererTaskOptions.get(task.id).outputBar;
  822. return typeof outputBar === "number" && outputBar !== 0 || typeof outputBar === "boolean" && outputBar !== false;
  823. }
  824. shouldOutputToBottomBar(task) {
  825. const bottomBar = this.cache.rendererTaskOptions.get(task.id).bottomBar;
  826. return typeof bottomBar === "number" && bottomBar !== 0 || typeof bottomBar === "boolean" && bottomBar !== false || !task.hasTitle();
  827. }
  828. renderer(tasks, level = 0) {
  829. return tasks.flatMap((task) => {
  830. if (!task.isEnabled()) {
  831. return [];
  832. }
  833. if (this.cache.render.has(task.id)) {
  834. return this.cache.render.get(task.id);
  835. }
  836. this.calculate(task);
  837. this.setupBuffer(task);
  838. const rendererOptions = this.cache.rendererOptions.get(task.id);
  839. const rendererTaskOptions = this.cache.rendererTaskOptions.get(task.id);
  840. const output = [];
  841. if (task.isPrompt()) {
  842. if (this.activePrompt && this.activePrompt !== task.id) {
  843. throw new ListrRendererError("Only one prompt can be active at the given time, please re-evaluate your task design.");
  844. } else if (!this.activePrompt) {
  845. task.on("PROMPT" /* PROMPT */, (prompt) => {
  846. const cleansed = cleanseAnsi(prompt);
  847. if (cleansed) {
  848. this.prompt = cleansed;
  849. }
  850. });
  851. task.on("STATE" /* STATE */, (state) => {
  852. if (state === "PROMPT_COMPLETED" /* PROMPT_COMPLETED */ || task.hasFinalized() || task.hasReset()) {
  853. this.prompt = null;
  854. this.activePrompt = null;
  855. task.off("PROMPT" /* PROMPT */);
  856. }
  857. });
  858. this.activePrompt = task.id;
  859. }
  860. }
  861. if (task.hasTitle()) {
  862. if (!(tasks.some((task2) => task2.hasFailed()) && !task.hasFailed() && task.options.exitOnError !== false && !(task.isCompleted() || task.isSkipped()))) {
  863. if (task.hasFailed() && rendererOptions.collapseErrors) {
  864. output.push(...this.format(!task.hasSubtasks() && task.message.error && rendererOptions.showErrorMessage ? task.message.error : task.title, this.style(task), level));
  865. } else if (task.isSkipped() && rendererOptions.collapseSkips) {
  866. output.push(
  867. ...this.format(
  868. this.logger.suffix(task.message.skip && rendererOptions.showSkipMessage ? task.message.skip : task.title, {
  869. field: "SKIPPED" /* SKIPPED */,
  870. condition: rendererOptions.suffixSkips,
  871. format: /* @__PURE__ */ __name(() => color.dim, "format")
  872. }),
  873. this.style(task),
  874. level
  875. )
  876. );
  877. } else if (task.isRetrying()) {
  878. output.push(
  879. ...this.format(
  880. this.logger.suffix(task.title, {
  881. field: `${"RETRY" /* RETRY */}:${task.message.retry.count}`,
  882. format: /* @__PURE__ */ __name(() => color.yellow, "format"),
  883. condition: rendererOptions.suffixRetries
  884. }),
  885. this.style(task),
  886. level
  887. )
  888. );
  889. } else if (task.isCompleted() && task.hasTitle() && assertFunctionOrSelf(rendererTaskOptions.timer?.condition, task.message.duration)) {
  890. output.push(
  891. ...this.format(
  892. this.logger.suffix(task?.title, {
  893. ...rendererTaskOptions.timer,
  894. args: [task.message.duration]
  895. }),
  896. this.style(task),
  897. level
  898. )
  899. );
  900. } else if (task.isPaused()) {
  901. output.push(
  902. ...this.format(
  903. this.logger.suffix(task.title, {
  904. ...rendererOptions.pausedTimer,
  905. args: [task.message.paused - Date.now()]
  906. }),
  907. this.style(task),
  908. level
  909. )
  910. );
  911. } else {
  912. output.push(...this.format(task.title, this.style(task), level));
  913. }
  914. } else {
  915. output.push(...this.format(task.title, this.logger.icon("COMPLETED_WITH_SISTER_TASKS_FAILED" /* COMPLETED_WITH_FAILED_SISTER_TASKS */), level));
  916. }
  917. }
  918. if (!task.hasSubtasks() || !rendererOptions.showSubtasks) {
  919. if (task.hasFailed() && rendererOptions.collapseErrors === false && (rendererOptions.showErrorMessage || !rendererOptions.showSubtasks)) {
  920. output.push(...this.dump(task, level, "FAILED" /* FAILED */));
  921. } else if (task.isSkipped() && rendererOptions.collapseSkips === false && (rendererOptions.showSkipMessage || !rendererOptions.showSubtasks)) {
  922. output.push(...this.dump(task, level, "SKIPPED" /* SKIPPED */));
  923. }
  924. }
  925. if (task.isPending() || rendererTaskOptions.persistentOutput) {
  926. output.push(...this.renderOutputBar(task, level));
  927. }
  928. if (
  929. // check if renderer option is on first
  930. rendererOptions.showSubtasks !== false && // if it doesnt have subtasks no need to check
  931. task.hasSubtasks() && (task.isPending() || task.hasFinalized() && !task.hasTitle() || // have to be completed and have subtasks
  932. task.isCompleted() && rendererOptions.collapseSubtasks === false && !task.subtasks.some((subtask) => this.cache.rendererOptions.get(subtask.id)?.collapseSubtasks === true) || // if any of the subtasks have the collapse option of
  933. task.subtasks.some((subtask) => this.cache.rendererOptions.get(subtask.id)?.collapseSubtasks === false) || // if any of the subtasks has failed
  934. task.subtasks.some((subtask) => subtask.hasFailed()) || // if any of the subtasks rolled back
  935. task.subtasks.some((subtask) => subtask.hasRolledBack()))
  936. ) {
  937. const subtaskLevel = !task.hasTitle() ? level : level + 1;
  938. const subtaskRender = this.renderer(task.subtasks, subtaskLevel);
  939. output.push(...subtaskRender);
  940. }
  941. if (task.hasFinalized()) {
  942. if (!rendererTaskOptions.persistentOutput) {
  943. this.buffer.bottom.delete(task.id);
  944. this.buffer.output.delete(task.id);
  945. }
  946. }
  947. if (task.isClosed()) {
  948. this.cache.render.set(task.id, output);
  949. this.reset(task);
  950. }
  951. return output;
  952. });
  953. }
  954. renderOutputBar(task, level) {
  955. const output = this.buffer.output.get(task.id);
  956. if (!output) {
  957. return [];
  958. }
  959. return output.all.flatMap((o) => this.dump(task, level, "OUTPUT" /* OUTPUT */, o.entry));
  960. }
  961. renderBottomBar() {
  962. if (this.buffer.bottom.size === 0) {
  963. return [];
  964. }
  965. return Array.from(this.buffer.bottom.values()).flatMap((output) => output.all).sort((a, b) => a.time - b.time).map((output) => output.entry);
  966. }
  967. renderPrompt() {
  968. if (!this.prompt) {
  969. return [];
  970. }
  971. return [this.prompt];
  972. }
  973. calculate(task) {
  974. if (this.cache.rendererOptions.has(task.id) && this.cache.rendererTaskOptions.has(task.id)) {
  975. return;
  976. }
  977. const rendererOptions = {
  978. ...this.options,
  979. ...task.rendererOptions
  980. };
  981. this.cache.rendererOptions.set(task.id, rendererOptions);
  982. this.cache.rendererTaskOptions.set(task.id, {
  983. ..._DefaultRenderer.rendererTaskOptions,
  984. timer: rendererOptions.timer,
  985. ...task.rendererTaskOptions
  986. });
  987. }
  988. setupBuffer(task) {
  989. if (this.buffer.bottom.has(task.id) || this.buffer.output.has(task.id)) {
  990. return;
  991. }
  992. const rendererTaskOptions = this.cache.rendererTaskOptions.get(task.id);
  993. if (this.shouldOutputToBottomBar(task) && !this.buffer.bottom.has(task.id)) {
  994. this.buffer.bottom.set(task.id, new ProcessOutputBuffer({ limit: typeof rendererTaskOptions.bottomBar === "number" ? rendererTaskOptions.bottomBar : 1 }));
  995. task.on("OUTPUT" /* OUTPUT */, (output) => {
  996. const data = this.dump(task, -1, "OUTPUT" /* OUTPUT */, output);
  997. this.buffer.bottom.get(task.id).write(data.join(EOL3));
  998. });
  999. task.on("STATE" /* STATE */, (state) => {
  1000. switch (state) {
  1001. case ("RETRY" /* RETRY */ || "ROLLING_BACK" /* ROLLING_BACK */):
  1002. this.buffer.bottom.delete(task.id);
  1003. break;
  1004. }
  1005. });
  1006. } else if (this.shouldOutputToOutputBar(task) && !this.buffer.output.has(task.id)) {
  1007. this.buffer.output.set(task.id, new ProcessOutputBuffer({ limit: typeof rendererTaskOptions.outputBar === "number" ? rendererTaskOptions.outputBar : 1 }));
  1008. task.on("OUTPUT" /* OUTPUT */, (output) => {
  1009. this.buffer.output.get(task.id).write(output);
  1010. });
  1011. task.on("STATE" /* STATE */, (state) => {
  1012. switch (state) {
  1013. case ("RETRY" /* RETRY */ || "ROLLING_BACK" /* ROLLING_BACK */):
  1014. this.buffer.output.delete(task.id);
  1015. break;
  1016. }
  1017. });
  1018. }
  1019. }
  1020. reset(task) {
  1021. this.cache.rendererOptions.delete(task.id);
  1022. this.cache.rendererTaskOptions.delete(task.id);
  1023. this.buffer.output.delete(task.id);
  1024. }
  1025. dump(task, level, source = "OUTPUT" /* OUTPUT */, data) {
  1026. if (!data) {
  1027. switch (source) {
  1028. case "OUTPUT" /* OUTPUT */:
  1029. data = task.output;
  1030. break;
  1031. case "SKIPPED" /* SKIPPED */:
  1032. data = task.message.skip;
  1033. break;
  1034. case "FAILED" /* FAILED */:
  1035. data = task.message.error;
  1036. break;
  1037. }
  1038. }
  1039. if (task.hasTitle() && source === "FAILED" /* FAILED */ && data === task.title || typeof data !== "string") {
  1040. return [];
  1041. }
  1042. if (source === "OUTPUT" /* OUTPUT */) {
  1043. data = cleanseAnsi(data);
  1044. }
  1045. return this.format(data, this.style(task, true), level + 1);
  1046. }
  1047. indent(str, i) {
  1048. return i > 0 ? indent(str.trim(), this.options.indentation) : str.trim();
  1049. }
  1050. };
  1051. // src/renderer/silent/renderer.ts
  1052. var SilentRenderer = class {
  1053. constructor(tasks, options) {
  1054. this.tasks = tasks;
  1055. this.options = options;
  1056. }
  1057. static {
  1058. __name(this, "SilentRenderer");
  1059. }
  1060. static nonTTY = true;
  1061. static rendererOptions;
  1062. static rendererTaskOptions;
  1063. render() {
  1064. return;
  1065. }
  1066. end() {
  1067. return;
  1068. }
  1069. };
  1070. // src/renderer/simple/renderer.ts
  1071. var SimpleRenderer = class _SimpleRenderer {
  1072. constructor(tasks, options) {
  1073. this.tasks = tasks;
  1074. this.options = options;
  1075. this.options = {
  1076. ..._SimpleRenderer.rendererOptions,
  1077. ...options,
  1078. icon: {
  1079. ...LISTR_LOGGER_STYLE.icon,
  1080. ...options?.icon ?? {}
  1081. },
  1082. color: {
  1083. ...LISTR_LOGGER_STYLE.color,
  1084. ...options?.color ?? {}
  1085. }
  1086. };
  1087. this.logger = this.options.logger ?? new ListrLogger({ useIcons: true, toStderr: LISTR_LOGGER_STDERR_LEVELS });
  1088. this.logger.options.icon = this.options.icon;
  1089. this.logger.options.color = this.options.color;
  1090. if (this.options.timestamp) {
  1091. this.logger.options.fields.prefix.unshift(this.options.timestamp);
  1092. }
  1093. }
  1094. static {
  1095. __name(this, "SimpleRenderer");
  1096. }
  1097. static nonTTY = true;
  1098. static rendererOptions = {
  1099. pausedTimer: {
  1100. ...PRESET_TIMER,
  1101. field: /* @__PURE__ */ __name((time) => `${"PAUSED" /* PAUSED */}:${time}`, "field"),
  1102. format: /* @__PURE__ */ __name(() => color.yellowBright, "format")
  1103. }
  1104. };
  1105. static rendererTaskOptions = {};
  1106. logger;
  1107. cache = {
  1108. rendererOptions: /* @__PURE__ */ new Map(),
  1109. rendererTaskOptions: /* @__PURE__ */ new Map()
  1110. };
  1111. // eslint-disable-next-line @typescript-eslint/no-empty-function
  1112. end() {
  1113. }
  1114. render() {
  1115. this.renderer(this.tasks);
  1116. }
  1117. renderer(tasks) {
  1118. tasks.forEach((task) => {
  1119. this.calculate(task);
  1120. task.once("CLOSED" /* CLOSED */, () => {
  1121. this.reset(task);
  1122. });
  1123. const rendererOptions = this.cache.rendererOptions.get(task.id);
  1124. const rendererTaskOptions = this.cache.rendererTaskOptions.get(task.id);
  1125. task.on("SUBTASK" /* SUBTASK */, (subtasks) => {
  1126. this.renderer(subtasks);
  1127. });
  1128. task.on("STATE" /* STATE */, (state) => {
  1129. if (!task.hasTitle()) {
  1130. return;
  1131. }
  1132. if (state === "STARTED" /* STARTED */) {
  1133. this.logger.log("STARTED" /* STARTED */, task.title);
  1134. } else if (state === "COMPLETED" /* COMPLETED */) {
  1135. const timer = rendererTaskOptions?.timer;
  1136. this.logger.log(
  1137. "COMPLETED" /* COMPLETED */,
  1138. task.title,
  1139. timer && {
  1140. suffix: {
  1141. ...timer,
  1142. condition: !!task.message?.duration && timer.condition,
  1143. args: [task.message.duration]
  1144. }
  1145. }
  1146. );
  1147. } else if (state === "PROMPT" /* PROMPT */) {
  1148. this.logger.process.hijack();
  1149. task.on("PROMPT" /* PROMPT */, (prompt) => {
  1150. this.logger.process.toStderr(prompt, false);
  1151. });
  1152. } else if (state === "PROMPT_COMPLETED" /* PROMPT_COMPLETED */) {
  1153. task.off("PROMPT" /* PROMPT */);
  1154. this.logger.process.release();
  1155. }
  1156. });
  1157. task.on("OUTPUT" /* OUTPUT */, (output) => {
  1158. this.logger.log("OUTPUT" /* OUTPUT */, output);
  1159. });
  1160. task.on("MESSAGE" /* MESSAGE */, (message) => {
  1161. if (message.error) {
  1162. this.logger.log("FAILED" /* FAILED */, task.title, {
  1163. suffix: {
  1164. field: `${"FAILED" /* FAILED */}: ${message.error}`,
  1165. format: /* @__PURE__ */ __name(() => color.red, "format")
  1166. }
  1167. });
  1168. } else if (message.skip) {
  1169. this.logger.log("SKIPPED" /* SKIPPED */, task.title, {
  1170. suffix: {
  1171. field: `${"SKIPPED" /* SKIPPED */}: ${message.skip}`,
  1172. format: /* @__PURE__ */ __name(() => color.yellow, "format")
  1173. }
  1174. });
  1175. } else if (message.rollback) {
  1176. this.logger.log("ROLLBACK" /* ROLLBACK */, task.title, {
  1177. suffix: {
  1178. field: `${"ROLLBACK" /* ROLLBACK */}: ${message.rollback}`,
  1179. format: /* @__PURE__ */ __name(() => color.red, "format")
  1180. }
  1181. });
  1182. } else if (message.retry) {
  1183. this.logger.log("RETRY" /* RETRY */, task.title, {
  1184. suffix: {
  1185. field: `${"RETRY" /* RETRY */}:${message.retry.count}`,
  1186. format: /* @__PURE__ */ __name(() => color.red, "format")
  1187. }
  1188. });
  1189. } else if (message.paused) {
  1190. const timer = rendererOptions?.pausedTimer;
  1191. this.logger.log(
  1192. "PAUSED" /* PAUSED */,
  1193. task.title,
  1194. timer && {
  1195. suffix: {
  1196. ...timer,
  1197. condition: !!message?.paused && timer.condition,
  1198. args: [message.paused - Date.now()]
  1199. }
  1200. }
  1201. );
  1202. }
  1203. });
  1204. });
  1205. }
  1206. calculate(task) {
  1207. if (this.cache.rendererOptions.has(task.id) && this.cache.rendererTaskOptions.has(task.id)) {
  1208. return;
  1209. }
  1210. const rendererOptions = {
  1211. ...this.options,
  1212. ...task.rendererOptions
  1213. };
  1214. this.cache.rendererOptions.set(task.id, rendererOptions);
  1215. this.cache.rendererTaskOptions.set(task.id, {
  1216. ..._SimpleRenderer.rendererTaskOptions,
  1217. timer: rendererOptions.timer,
  1218. ...task.rendererTaskOptions
  1219. });
  1220. }
  1221. reset(task) {
  1222. this.cache.rendererOptions.delete(task.id);
  1223. this.cache.rendererTaskOptions.delete(task.id);
  1224. }
  1225. };
  1226. // src/renderer/test/serializer.ts
  1227. var TestRendererSerializer = class {
  1228. constructor(options) {
  1229. this.options = options;
  1230. }
  1231. static {
  1232. __name(this, "TestRendererSerializer");
  1233. }
  1234. serialize(event, data, task) {
  1235. return JSON.stringify(this.generate(event, data, task));
  1236. }
  1237. generate(event, data, task) {
  1238. const output = {
  1239. event,
  1240. data
  1241. };
  1242. if (typeof this.options?.task !== "boolean") {
  1243. const t = Object.fromEntries(
  1244. this.options.task.map((entity) => {
  1245. const property = task[entity];
  1246. if (typeof property === "function") {
  1247. return [entity, property.call(task)];
  1248. }
  1249. return [entity, property];
  1250. })
  1251. );
  1252. if (Object.keys(task).length > 0) {
  1253. output.task = t;
  1254. }
  1255. }
  1256. return output;
  1257. }
  1258. };
  1259. // src/renderer/test/renderer.ts
  1260. var TestRenderer = class _TestRenderer {
  1261. constructor(tasks, options) {
  1262. this.tasks = tasks;
  1263. this.options = options;
  1264. this.options = { ..._TestRenderer.rendererOptions, ...this.options };
  1265. this.logger = this.options.logger ?? new ListrLogger({ useIcons: false });
  1266. this.serializer = new TestRendererSerializer(this.options);
  1267. }
  1268. static {
  1269. __name(this, "TestRenderer");
  1270. }
  1271. static nonTTY = true;
  1272. static rendererOptions = {
  1273. subtasks: true,
  1274. state: Object.values(ListrTaskState),
  1275. output: true,
  1276. prompt: true,
  1277. title: true,
  1278. messages: ["skip", "error", "retry", "rollback", "paused"],
  1279. messagesToStderr: ["error", "rollback", "retry"],
  1280. task: [
  1281. "hasRolledBack",
  1282. "isRollingBack",
  1283. "isCompleted",
  1284. "isSkipped",
  1285. "hasFinalized",
  1286. "hasSubtasks",
  1287. "title",
  1288. "hasReset",
  1289. "hasTitle",
  1290. "isPrompt",
  1291. "isPaused",
  1292. "isPending",
  1293. "isSkipped",
  1294. "isStarted",
  1295. "hasFailed",
  1296. "isEnabled",
  1297. "isRetrying",
  1298. "path"
  1299. ]
  1300. };
  1301. static rendererTaskOptions;
  1302. logger;
  1303. serializer;
  1304. render() {
  1305. this.renderer(this.tasks);
  1306. }
  1307. // eslint-disable-next-line @typescript-eslint/no-empty-function
  1308. end() {
  1309. }
  1310. // verbose renderer multi-level
  1311. renderer(tasks) {
  1312. tasks.forEach((task) => {
  1313. if (this.options.subtasks) {
  1314. task.on("SUBTASK" /* SUBTASK */, (subtasks) => {
  1315. this.renderer(subtasks);
  1316. });
  1317. }
  1318. if (this.options.state) {
  1319. task.on("STATE" /* STATE */, (state) => {
  1320. this.logger.toStdout(this.serializer.serialize("STATE" /* STATE */, state, task));
  1321. });
  1322. }
  1323. if (this.options.output) {
  1324. task.on("OUTPUT" /* OUTPUT */, (data) => {
  1325. this.logger.toStdout(this.serializer.serialize("OUTPUT" /* OUTPUT */, data, task));
  1326. });
  1327. }
  1328. if (this.options.prompt) {
  1329. task.on("PROMPT" /* PROMPT */, (prompt) => {
  1330. this.logger.toStdout(this.serializer.serialize("PROMPT" /* PROMPT */, prompt, task));
  1331. });
  1332. }
  1333. if (this.options.title) {
  1334. task.on("TITLE" /* TITLE */, (title) => {
  1335. this.logger.toStdout(this.serializer.serialize("TITLE" /* TITLE */, title, task));
  1336. });
  1337. }
  1338. task.on("MESSAGE" /* MESSAGE */, (message) => {
  1339. const parsed = Object.fromEntries(
  1340. Object.entries(message).map(([key, value]) => {
  1341. if (this.options.messages.includes(key)) {
  1342. return [key, value];
  1343. }
  1344. }).filter(Boolean)
  1345. );
  1346. if (Object.keys(parsed).length > 0) {
  1347. const output = this.serializer.serialize("MESSAGE" /* MESSAGE */, parsed, task);
  1348. if (this.options.messagesToStderr.some((state) => Object.keys(parsed).includes(state))) {
  1349. this.logger.toStderr(output);
  1350. } else {
  1351. this.logger.toStdout(output);
  1352. }
  1353. }
  1354. });
  1355. });
  1356. }
  1357. };
  1358. // src/renderer/verbose/renderer.ts
  1359. var VerboseRenderer = class _VerboseRenderer {
  1360. constructor(tasks, options) {
  1361. this.tasks = tasks;
  1362. this.options = options;
  1363. this.options = {
  1364. ..._VerboseRenderer.rendererOptions,
  1365. ...this.options,
  1366. icon: {
  1367. ...LISTR_LOGGER_STYLE.icon,
  1368. ...options?.icon ?? {}
  1369. },
  1370. color: {
  1371. ...LISTR_LOGGER_STYLE.color,
  1372. ...options?.color ?? {}
  1373. }
  1374. };
  1375. this.logger = this.options.logger ?? new ListrLogger({ useIcons: false, toStderr: LISTR_LOGGER_STDERR_LEVELS });
  1376. this.logger.options.icon = this.options.icon;
  1377. this.logger.options.color = this.options.color;
  1378. if (this.options.timestamp) {
  1379. this.logger.options.fields.prefix.unshift(this.options.timestamp);
  1380. }
  1381. }
  1382. static {
  1383. __name(this, "VerboseRenderer");
  1384. }
  1385. static nonTTY = true;
  1386. static rendererOptions = {
  1387. logTitleChange: false,
  1388. pausedTimer: {
  1389. ...PRESET_TIMER,
  1390. format: /* @__PURE__ */ __name(() => color.yellowBright, "format")
  1391. }
  1392. };
  1393. static rendererTaskOptions;
  1394. logger;
  1395. cache = {
  1396. rendererOptions: /* @__PURE__ */ new Map(),
  1397. rendererTaskOptions: /* @__PURE__ */ new Map()
  1398. };
  1399. render() {
  1400. this.renderer(this.tasks);
  1401. }
  1402. // eslint-disable-next-line @typescript-eslint/no-empty-function
  1403. end() {
  1404. }
  1405. renderer(tasks) {
  1406. tasks.forEach((task) => {
  1407. this.calculate(task);
  1408. task.once("CLOSED" /* CLOSED */, () => {
  1409. this.reset(task);
  1410. });
  1411. const rendererOptions = this.cache.rendererOptions.get(task.id);
  1412. const rendererTaskOptions = this.cache.rendererTaskOptions.get(task.id);
  1413. task.on("SUBTASK" /* SUBTASK */, (subtasks) => {
  1414. this.renderer(subtasks);
  1415. });
  1416. task.on("STATE" /* STATE */, (state) => {
  1417. if (!task.hasTitle()) {
  1418. return;
  1419. }
  1420. if (state === "STARTED" /* STARTED */) {
  1421. this.logger.log("STARTED" /* STARTED */, task.title);
  1422. } else if (state === "COMPLETED" /* COMPLETED */) {
  1423. const timer = rendererTaskOptions.timer;
  1424. this.logger.log(
  1425. "COMPLETED" /* COMPLETED */,
  1426. task.title,
  1427. timer && {
  1428. suffix: {
  1429. ...timer,
  1430. condition: !!task.message?.duration && timer.condition,
  1431. args: [task.message.duration]
  1432. }
  1433. }
  1434. );
  1435. }
  1436. });
  1437. task.on("OUTPUT" /* OUTPUT */, (data) => {
  1438. this.logger.log("OUTPUT" /* OUTPUT */, data);
  1439. });
  1440. task.on("PROMPT" /* PROMPT */, (prompt) => {
  1441. const cleansed = cleanseAnsi(prompt);
  1442. if (cleansed) {
  1443. this.logger.log("PROMPT" /* PROMPT */, cleansed);
  1444. }
  1445. });
  1446. if (this.options?.logTitleChange !== false) {
  1447. task.on("TITLE" /* TITLE */, (title) => {
  1448. this.logger.log("TITLE" /* TITLE */, title);
  1449. });
  1450. }
  1451. task.on("MESSAGE" /* MESSAGE */, (message) => {
  1452. if (message?.error) {
  1453. this.logger.log("FAILED" /* FAILED */, message.error);
  1454. } else if (message?.skip) {
  1455. this.logger.log("SKIPPED" /* SKIPPED */, message.skip);
  1456. } else if (message?.rollback) {
  1457. this.logger.log("ROLLBACK" /* ROLLBACK */, message.rollback);
  1458. } else if (message?.retry) {
  1459. this.logger.log("RETRY" /* RETRY */, task.title, { suffix: message.retry.count.toString() });
  1460. } else if (message?.paused) {
  1461. const timer = rendererOptions?.pausedTimer;
  1462. this.logger.log(
  1463. "PAUSED" /* PAUSED */,
  1464. task.title,
  1465. timer && {
  1466. suffix: {
  1467. ...timer,
  1468. condition: !!message?.paused && timer.condition,
  1469. args: [message.paused - Date.now()]
  1470. }
  1471. }
  1472. );
  1473. }
  1474. });
  1475. });
  1476. }
  1477. calculate(task) {
  1478. if (this.cache.rendererOptions.has(task.id) && this.cache.rendererTaskOptions.has(task.id)) {
  1479. return;
  1480. }
  1481. const rendererOptions = {
  1482. ...this.options,
  1483. ...task.rendererOptions
  1484. };
  1485. this.cache.rendererOptions.set(task.id, rendererOptions);
  1486. this.cache.rendererTaskOptions.set(task.id, {
  1487. ..._VerboseRenderer.rendererTaskOptions,
  1488. timer: rendererOptions.timer,
  1489. ...task.rendererTaskOptions
  1490. });
  1491. }
  1492. reset(task) {
  1493. this.cache.rendererOptions.delete(task.id);
  1494. this.cache.rendererTaskOptions.delete(task.id);
  1495. }
  1496. };
  1497. // src/utils/ui/renderer.ts
  1498. var RENDERERS = {
  1499. default: DefaultRenderer,
  1500. simple: SimpleRenderer,
  1501. verbose: VerboseRenderer,
  1502. test: TestRenderer,
  1503. silent: SilentRenderer
  1504. };
  1505. function isRendererSupported(renderer) {
  1506. return process.stdout.isTTY === true || renderer.nonTTY === true;
  1507. }
  1508. __name(isRendererSupported, "isRendererSupported");
  1509. function getRendererClass(renderer) {
  1510. if (typeof renderer === "string") {
  1511. return RENDERERS[renderer] ?? RENDERERS.default;
  1512. }
  1513. return typeof renderer === "function" ? renderer : RENDERERS.default;
  1514. }
  1515. __name(getRendererClass, "getRendererClass");
  1516. function getRenderer(options) {
  1517. if (assertFunctionOrSelf(options?.silentRendererCondition)) {
  1518. return { renderer: getRendererClass("silent"), selection: "SILENT" /* SILENT */ };
  1519. }
  1520. const r = {
  1521. renderer: getRendererClass(options.renderer),
  1522. options: options.rendererOptions,
  1523. selection: "PRIMARY" /* PRIMARY */
  1524. };
  1525. if (!isRendererSupported(r.renderer) || assertFunctionOrSelf(options?.fallbackRendererCondition)) {
  1526. return {
  1527. renderer: getRendererClass(options.fallbackRenderer),
  1528. options: options.fallbackRendererOptions,
  1529. selection: "SECONDARY" /* SECONDARY */
  1530. };
  1531. }
  1532. return r;
  1533. }
  1534. __name(getRenderer, "getRenderer");
  1535. // src/utils/assert.ts
  1536. function assertFunctionOrSelf(functionOrSelf, ...args) {
  1537. if (typeof functionOrSelf === "function") {
  1538. return functionOrSelf(...args);
  1539. } else {
  1540. return functionOrSelf;
  1541. }
  1542. }
  1543. __name(assertFunctionOrSelf, "assertFunctionOrSelf");
  1544. // src/utils/clone.ts
  1545. import rfdc from "rfdc";
  1546. var clone = rfdc({ circles: true });
  1547. function cloneObject(obj) {
  1548. return clone(obj);
  1549. }
  1550. __name(cloneObject, "cloneObject");
  1551. // src/utils/concurrency.ts
  1552. var Concurrency = class {
  1553. static {
  1554. __name(this, "Concurrency");
  1555. }
  1556. concurrency;
  1557. count;
  1558. queue;
  1559. constructor(options) {
  1560. this.concurrency = options.concurrency;
  1561. this.count = 0;
  1562. this.queue = /* @__PURE__ */ new Set();
  1563. }
  1564. add(fn) {
  1565. if (this.count < this.concurrency) {
  1566. return this.run(fn);
  1567. }
  1568. return new Promise((resolve) => {
  1569. const callback = /* @__PURE__ */ __name(() => resolve(this.run(fn)), "callback");
  1570. this.queue.add(callback);
  1571. });
  1572. }
  1573. flush() {
  1574. for (const callback of this.queue) {
  1575. if (this.count >= this.concurrency) {
  1576. break;
  1577. }
  1578. this.queue.delete(callback);
  1579. callback();
  1580. }
  1581. }
  1582. run(fn) {
  1583. this.count++;
  1584. const promise = fn();
  1585. const cleanup = /* @__PURE__ */ __name(() => {
  1586. this.count--;
  1587. this.flush();
  1588. }, "cleanup");
  1589. promise.then(cleanup, () => {
  1590. this.queue.clear();
  1591. });
  1592. return promise;
  1593. }
  1594. };
  1595. // src/utils/delay.ts
  1596. function delay(time) {
  1597. return new Promise((resolve) => {
  1598. setTimeout(resolve, time);
  1599. });
  1600. }
  1601. __name(delay, "delay");
  1602. // src/interfaces/listr-error.interface.ts
  1603. var ListrError = class extends Error {
  1604. constructor(error, type, task) {
  1605. super(error.message);
  1606. this.error = error;
  1607. this.type = type;
  1608. this.task = task;
  1609. this.name = "ListrError";
  1610. this.path = task.path;
  1611. if (task?.options.collectErrors === "full") {
  1612. this.task = cloneObject(task);
  1613. this.ctx = cloneObject(task.listr.ctx);
  1614. }
  1615. this.stack = error?.stack;
  1616. }
  1617. static {
  1618. __name(this, "ListrError");
  1619. }
  1620. path;
  1621. ctx;
  1622. };
  1623. // src/interfaces/listr-renderer-error.interface.ts
  1624. var ListrRendererError = class extends Error {
  1625. static {
  1626. __name(this, "ListrRendererError");
  1627. }
  1628. };
  1629. // src/interfaces/prompt-error.interface.ts
  1630. var PromptError = class extends Error {
  1631. static {
  1632. __name(this, "PromptError");
  1633. }
  1634. };
  1635. // src/lib/task-wrapper.ts
  1636. var TaskWrapper = class {
  1637. constructor(task) {
  1638. this.task = task;
  1639. }
  1640. static {
  1641. __name(this, "TaskWrapper");
  1642. }
  1643. /* istanbul ignore next */
  1644. get title() {
  1645. return this.task.title;
  1646. }
  1647. /**
  1648. * Title of the current task.
  1649. *
  1650. * @see {@link https://listr2.kilic.dev/task/title.html}
  1651. */
  1652. set title(title) {
  1653. title = Array.isArray(title) ? title : [title];
  1654. this.task.title$ = splat(title.shift(), ...title);
  1655. }
  1656. /* istanbul ignore next */
  1657. get output() {
  1658. return this.task.output;
  1659. }
  1660. /* istanbul ignore next */
  1661. /**
  1662. * Send output from the current task to the renderer.
  1663. *
  1664. * @see {@link https://listr2.kilic.dev/task/output.html}
  1665. */
  1666. set output(output) {
  1667. output = Array.isArray(output) ? output : [output];
  1668. this.task.output$ = splat(output.shift(), ...output);
  1669. }
  1670. /* istanbul ignore next */
  1671. /** Send an output to the output channel as prompt. */
  1672. set promptOutput(output) {
  1673. this.task.promptOutput$ = output;
  1674. }
  1675. /**
  1676. * Creates a new set of Listr subtasks.
  1677. *
  1678. * @see {@link https://listr2.kilic.dev/task/subtasks.html}
  1679. */
  1680. newListr(task, options) {
  1681. let tasks;
  1682. if (typeof task === "function") {
  1683. tasks = task(this);
  1684. } else {
  1685. tasks = task;
  1686. }
  1687. return new Listr(tasks, options, this.task);
  1688. }
  1689. /**
  1690. * Report an error that has to be collected and handled.
  1691. *
  1692. * @see {@link https://listr2.kilic.dev/task/error-handling.html}
  1693. */
  1694. report(error, type) {
  1695. if (this.task.options.collectErrors !== false) {
  1696. this.task.listr.errors.push(new ListrError(error, type, this.task));
  1697. }
  1698. this.task.message$ = { error: error.message ?? this.task?.title };
  1699. }
  1700. /**
  1701. * Skip the current task.
  1702. *
  1703. * @see {@link https://listr2.kilic.dev/task/skip.html}
  1704. */
  1705. skip(message, ...metadata) {
  1706. this.task.state$ = "SKIPPED" /* SKIPPED */;
  1707. if (message) {
  1708. this.task.message$ = { skip: message ? splat(message, ...metadata) : this.task?.title };
  1709. }
  1710. }
  1711. /**
  1712. * Check whether this task is currently in a retry state.
  1713. *
  1714. * @see {@link https://listr2.kilic.dev/task/retry.html}
  1715. */
  1716. isRetrying() {
  1717. return this.task.isRetrying() ? this.task.retry : { count: 0 };
  1718. }
  1719. /* istanbul ignore next */
  1720. /**
  1721. * Create a new prompt for getting user input through the prompt adapter.
  1722. * This will create a new prompt through the adapter if the task is not currently rendering a prompt or will return the active instance.
  1723. *
  1724. * This part of the application requires optional peer dependencies, please refer to documentation.
  1725. *
  1726. * @see {@link https://listr2.kilic.dev/task/prompt.html}
  1727. */
  1728. prompt(adapter) {
  1729. if (this.task.prompt) {
  1730. return this.task.prompt;
  1731. }
  1732. return new adapter(this.task, this);
  1733. }
  1734. /* istanbul ignore next */
  1735. /**
  1736. * Generates a fake stdout for your use case, where it will be tunnelled through Listr to handle the rendering process.
  1737. *
  1738. * @see {@link https://listr2.kilic.dev/renderer/process-output.html}
  1739. */
  1740. stdout(type) {
  1741. return createWritable((chunk) => {
  1742. switch (type) {
  1743. case "PROMPT" /* PROMPT */:
  1744. this.promptOutput = chunk;
  1745. break;
  1746. default:
  1747. this.output = chunk;
  1748. }
  1749. });
  1750. }
  1751. /** Run this task. */
  1752. run(ctx) {
  1753. return this.task.run(ctx, this);
  1754. }
  1755. };
  1756. // src/lib/task.ts
  1757. import { randomUUID } from "crypto";
  1758. // src/lib/listr-task-event-manager.ts
  1759. var ListrTaskEventManager = class extends EventManager {
  1760. static {
  1761. __name(this, "ListrTaskEventManager");
  1762. }
  1763. };
  1764. // src/lib/task.ts
  1765. var Task = class extends ListrTaskEventManager {
  1766. constructor(listr, task, options, rendererOptions, rendererTaskOptions) {
  1767. super();
  1768. this.listr = listr;
  1769. this.task = task;
  1770. this.options = options;
  1771. this.rendererOptions = rendererOptions;
  1772. this.rendererTaskOptions = rendererTaskOptions;
  1773. if (task.title) {
  1774. const title = Array.isArray(task?.title) ? task.title : [task.title];
  1775. this.title = splat(title.shift(), ...title);
  1776. this.initialTitle = this.title;
  1777. }
  1778. this.taskFn = task.task;
  1779. this.parent = listr.parentTask;
  1780. }
  1781. static {
  1782. __name(this, "Task");
  1783. }
  1784. /** Unique id per task, can be used for identifying a Task. */
  1785. id = randomUUID();
  1786. /** The current state of the task. */
  1787. state = "WAITING" /* WAITING */;
  1788. /** Subtasks of the current task. */
  1789. subtasks;
  1790. /** Title of the task. */
  1791. title;
  1792. /** Initial/Untouched version of the title for using whenever task has a reset. */
  1793. initialTitle;
  1794. /** Output channel for the task. */
  1795. output;
  1796. /** Current state of the retry process whenever the task is retrying. */
  1797. retry;
  1798. /**
  1799. * A channel for messages.
  1800. *
  1801. * This requires a separate channel for messages like error, skip or runtime messages to further utilize in the renderers.
  1802. */
  1803. message = {};
  1804. /** Current prompt instance or prompt error whenever the task is prompting. */
  1805. prompt;
  1806. /** Parent task of the current task. */
  1807. parent;
  1808. /** Enable flag of this task. */
  1809. enabled;
  1810. /** User provided Task callback function to run. */
  1811. taskFn;
  1812. /** Marks the task as closed. This is different from finalized since this is not really related to task itself. */
  1813. closed;
  1814. /**
  1815. * Update the current state of the Task and emit the neccassary events.
  1816. */
  1817. set state$(state) {
  1818. this.state = state;
  1819. this.emit("STATE" /* STATE */, state);
  1820. if (this.hasSubtasks() && this.hasFailed()) {
  1821. for (const subtask of this.subtasks) {
  1822. if (subtask.state === "STARTED" /* STARTED */) {
  1823. subtask.state$ = "FAILED" /* FAILED */;
  1824. }
  1825. }
  1826. }
  1827. this.listr.events.emit("SHOUD_REFRESH_RENDER" /* SHOULD_REFRESH_RENDER */);
  1828. }
  1829. /**
  1830. * Update the current output of the Task and emit the neccassary events.
  1831. */
  1832. set output$(data) {
  1833. this.output = data;
  1834. this.emit("OUTPUT" /* OUTPUT */, data);
  1835. this.listr.events.emit("SHOUD_REFRESH_RENDER" /* SHOULD_REFRESH_RENDER */);
  1836. }
  1837. /**
  1838. * Update the current prompt output of the Task and emit the neccassary events.
  1839. */
  1840. set promptOutput$(data) {
  1841. this.emit("PROMPT" /* PROMPT */, data);
  1842. if (cleanseAnsi(data)) {
  1843. this.listr.events.emit("SHOUD_REFRESH_RENDER" /* SHOULD_REFRESH_RENDER */);
  1844. }
  1845. }
  1846. /**
  1847. * Update or extend the current message of the Task and emit the neccassary events.
  1848. */
  1849. set message$(data) {
  1850. this.message = { ...this.message, ...data };
  1851. this.emit("MESSAGE" /* MESSAGE */, data);
  1852. this.listr.events.emit("SHOUD_REFRESH_RENDER" /* SHOULD_REFRESH_RENDER */);
  1853. }
  1854. /**
  1855. * Update the current title of the Task and emit the neccassary events.
  1856. */
  1857. set title$(title) {
  1858. this.title = title;
  1859. this.emit("TITLE" /* TITLE */, title);
  1860. this.listr.events.emit("SHOUD_REFRESH_RENDER" /* SHOULD_REFRESH_RENDER */);
  1861. }
  1862. /**
  1863. * Current task path in the hierarchy.
  1864. */
  1865. get path() {
  1866. return [...this.listr.path, this.initialTitle];
  1867. }
  1868. /**
  1869. * Checks whether the current task with the given context should be set as enabled.
  1870. */
  1871. async check(ctx) {
  1872. if (this.state === "WAITING" /* WAITING */) {
  1873. this.enabled = await assertFunctionOrSelf(this.task?.enabled ?? true, ctx);
  1874. this.emit("ENABLED" /* ENABLED */, this.enabled);
  1875. this.listr.events.emit("SHOUD_REFRESH_RENDER" /* SHOULD_REFRESH_RENDER */);
  1876. }
  1877. return this.enabled;
  1878. }
  1879. /** Returns whether this task has subtasks. */
  1880. hasSubtasks() {
  1881. return this.subtasks?.length > 0;
  1882. }
  1883. /** Returns whether this task is finalized in someform. */
  1884. hasFinalized() {
  1885. return this.isCompleted() || this.hasFailed() || this.isSkipped() || this.hasRolledBack();
  1886. }
  1887. /** Returns whether this task is in progress. */
  1888. isPending() {
  1889. return this.isStarted() || this.isPrompt() || this.hasReset();
  1890. }
  1891. /** Returns whether this task has started. */
  1892. isStarted() {
  1893. return this.state === "STARTED" /* STARTED */;
  1894. }
  1895. /** Returns whether this task is skipped. */
  1896. isSkipped() {
  1897. return this.state === "SKIPPED" /* SKIPPED */;
  1898. }
  1899. /** Returns whether this task has been completed. */
  1900. isCompleted() {
  1901. return this.state === "COMPLETED" /* COMPLETED */;
  1902. }
  1903. /** Returns whether this task has been failed. */
  1904. hasFailed() {
  1905. return this.state === "FAILED" /* FAILED */;
  1906. }
  1907. /** Returns whether this task has an active rollback task going on. */
  1908. isRollingBack() {
  1909. return this.state === "ROLLING_BACK" /* ROLLING_BACK */;
  1910. }
  1911. /** Returns whether the rollback action was successful. */
  1912. hasRolledBack() {
  1913. return this.state === "ROLLED_BACK" /* ROLLED_BACK */;
  1914. }
  1915. /** Returns whether this task has an actively retrying task going on. */
  1916. isRetrying() {
  1917. return this.state === "RETRY" /* RETRY */;
  1918. }
  1919. /** Returns whether this task has some kind of reset like retry and rollback going on. */
  1920. hasReset() {
  1921. return this.state === "RETRY" /* RETRY */ || this.state === "ROLLING_BACK" /* ROLLING_BACK */;
  1922. }
  1923. /** Returns whether enabled function resolves to true. */
  1924. isEnabled() {
  1925. return this.enabled;
  1926. }
  1927. /** Returns whether this task actually has a title. */
  1928. hasTitle() {
  1929. return typeof this?.title === "string";
  1930. }
  1931. /** Returns whether this task has a prompt inside. */
  1932. isPrompt() {
  1933. return this.state === "PROMPT" /* PROMPT */ || this.state === "PROMPT_COMPLETED" /* PROMPT_COMPLETED */;
  1934. }
  1935. /** Returns whether this task is currently paused. */
  1936. isPaused() {
  1937. return this.state === "PAUSED" /* PAUSED */;
  1938. }
  1939. /** Returns whether this task is closed. */
  1940. isClosed() {
  1941. return this.closed;
  1942. }
  1943. /** Pause the given task for certain time. */
  1944. async pause(time) {
  1945. const state = this.state;
  1946. this.state$ = "PAUSED" /* PAUSED */;
  1947. this.message$ = {
  1948. paused: Date.now() + time
  1949. };
  1950. await delay(time);
  1951. this.state$ = state;
  1952. this.message$ = {
  1953. paused: null
  1954. };
  1955. }
  1956. /** Run the current task. */
  1957. async run(context, wrapper) {
  1958. const handleResult = /* @__PURE__ */ __name((result) => {
  1959. if (result instanceof Listr) {
  1960. result.options = { ...this.options, ...result.options };
  1961. result.rendererClass = getRendererClass("silent");
  1962. this.subtasks = result.tasks;
  1963. result.errors = this.listr.errors;
  1964. this.emit("SUBTASK" /* SUBTASK */, this.subtasks);
  1965. result = result.run(context);
  1966. } else if (result instanceof Promise) {
  1967. result = result.then(handleResult);
  1968. } else if (isReadable(result)) {
  1969. result = new Promise((resolve, reject) => {
  1970. result.on("data", (data) => {
  1971. this.output$ = data.toString();
  1972. });
  1973. result.on("error", (error) => reject(error));
  1974. result.on("end", () => resolve(null));
  1975. });
  1976. } else if (isObservable(result)) {
  1977. result = new Promise((resolve, reject) => {
  1978. result.subscribe({
  1979. next: /* @__PURE__ */ __name((data) => {
  1980. this.output$ = data;
  1981. }, "next"),
  1982. error: reject,
  1983. complete: resolve
  1984. });
  1985. });
  1986. }
  1987. return result;
  1988. }, "handleResult");
  1989. const startTime = Date.now();
  1990. this.state$ = "STARTED" /* STARTED */;
  1991. const skipped = await assertFunctionOrSelf(this.task?.skip ?? false, context);
  1992. if (skipped) {
  1993. if (typeof skipped === "string") {
  1994. this.message$ = { skip: skipped };
  1995. } else if (this.hasTitle()) {
  1996. this.message$ = { skip: this.title };
  1997. } else {
  1998. this.message$ = { skip: "Skipped task without a title." };
  1999. }
  2000. this.state$ = "SKIPPED" /* SKIPPED */;
  2001. return;
  2002. }
  2003. try {
  2004. const retryCount = typeof this.task?.retry === "number" && this.task.retry > 0 ? this.task.retry + 1 : typeof this.task?.retry === "object" && this.task.retry.tries > 0 ? this.task.retry.tries + 1 : 1;
  2005. const retryDelay = typeof this.task.retry === "object" && this.task.retry.delay;
  2006. for (let retries = 1; retries <= retryCount; retries++) {
  2007. try {
  2008. await handleResult(this.taskFn(context, wrapper));
  2009. break;
  2010. } catch (err) {
  2011. if (retries !== retryCount) {
  2012. this.retry = { count: retries, error: err };
  2013. this.message$ = { retry: this.retry };
  2014. this.title$ = this.initialTitle;
  2015. this.output = void 0;
  2016. wrapper.report(err, "WILL_RETRY" /* WILL_RETRY */);
  2017. this.state$ = "RETRY" /* RETRY */;
  2018. if (retryDelay) {
  2019. await this.pause(retryDelay);
  2020. }
  2021. } else {
  2022. throw err;
  2023. }
  2024. }
  2025. }
  2026. if (this.isStarted() || this.isRetrying()) {
  2027. this.message$ = { duration: Date.now() - startTime };
  2028. this.state$ = "COMPLETED" /* COMPLETED */;
  2029. }
  2030. } catch (error) {
  2031. if (this.prompt instanceof PromptError) {
  2032. error = this.prompt;
  2033. }
  2034. if (this.task?.rollback) {
  2035. wrapper.report(error, "WILL_ROLLBACK" /* WILL_ROLLBACK */);
  2036. try {
  2037. this.state$ = "ROLLING_BACK" /* ROLLING_BACK */;
  2038. await this.task.rollback(context, wrapper);
  2039. this.message$ = { rollback: this.title };
  2040. this.state$ = "ROLLED_BACK" /* ROLLED_BACK */;
  2041. } catch (err) {
  2042. this.state$ = "FAILED" /* FAILED */;
  2043. wrapper.report(err, "HAS_FAILED_TO_ROLLBACK" /* HAS_FAILED_TO_ROLLBACK */);
  2044. this.close();
  2045. throw err;
  2046. }
  2047. if (this.listr.options?.exitAfterRollback !== false) {
  2048. this.close();
  2049. throw error;
  2050. }
  2051. } else {
  2052. this.state$ = "FAILED" /* FAILED */;
  2053. if (this.listr.options.exitOnError !== false && await assertFunctionOrSelf(this.task?.exitOnError, context) !== false) {
  2054. wrapper.report(error, "HAS_FAILED" /* HAS_FAILED */);
  2055. this.close();
  2056. throw error;
  2057. } else if (!this.hasSubtasks()) {
  2058. wrapper.report(error, "HAS_FAILED_WITHOUT_ERROR" /* HAS_FAILED_WITHOUT_ERROR */);
  2059. }
  2060. }
  2061. } finally {
  2062. this.close();
  2063. }
  2064. }
  2065. close() {
  2066. this.emit("CLOSED" /* CLOSED */);
  2067. this.listr.events.emit("SHOUD_REFRESH_RENDER" /* SHOULD_REFRESH_RENDER */);
  2068. this.complete();
  2069. }
  2070. };
  2071. // src/lib/listr-event-manager.ts
  2072. var ListrEventManager = class extends EventManager {
  2073. static {
  2074. __name(this, "ListrEventManager");
  2075. }
  2076. };
  2077. // src/listr.ts
  2078. var Listr = class {
  2079. constructor(task, options, parentTask) {
  2080. this.task = task;
  2081. this.options = options;
  2082. this.parentTask = parentTask;
  2083. this.options = {
  2084. concurrent: false,
  2085. renderer: "default",
  2086. fallbackRenderer: "simple",
  2087. exitOnError: true,
  2088. exitAfterRollback: true,
  2089. collectErrors: false,
  2090. registerSignalListeners: true,
  2091. ...this.parentTask?.options ?? {},
  2092. ...options
  2093. };
  2094. if (this.options.concurrent === true) {
  2095. this.options.concurrent = Infinity;
  2096. } else if (typeof this.options.concurrent !== "number") {
  2097. this.options.concurrent = 1;
  2098. }
  2099. this.concurrency = new Concurrency({ concurrency: this.options.concurrent });
  2100. if (parentTask) {
  2101. this.path = [...parentTask.listr.path, parentTask.title];
  2102. this.errors = parentTask.listr.errors;
  2103. }
  2104. if (this.parentTask?.listr.events instanceof ListrEventManager) {
  2105. this.events = this.parentTask.listr.events;
  2106. } else {
  2107. this.events = new ListrEventManager();
  2108. }
  2109. const renderer = getRenderer({
  2110. renderer: this.options.renderer,
  2111. rendererOptions: this.options.rendererOptions,
  2112. fallbackRenderer: this.options.fallbackRenderer,
  2113. fallbackRendererOptions: this.options.fallbackRendererOptions,
  2114. fallbackRendererCondition: this.options?.fallbackRendererCondition,
  2115. silentRendererCondition: this.options?.silentRendererCondition
  2116. });
  2117. this.rendererClass = renderer.renderer;
  2118. this.rendererClassOptions = renderer.options;
  2119. this.rendererSelection = renderer.selection;
  2120. this.add(task ?? []);
  2121. if (this.options.registerSignalListeners) {
  2122. this.boundSignalHandler = this.signalHandler.bind(this);
  2123. process.once("SIGINT", this.boundSignalHandler).setMaxListeners(0);
  2124. }
  2125. if (this.options?.forceTTY || process.env["LISTR_FORCE_TTY" /* FORCE_TTY */]) {
  2126. process.stdout.isTTY = true;
  2127. process.stderr.isTTY = true;
  2128. }
  2129. if (this.options?.forceUnicode) {
  2130. process.env["LISTR_FORCE_UNICODE" /* FORCE_UNICODE */] = "1";
  2131. }
  2132. }
  2133. static {
  2134. __name(this, "Listr");
  2135. }
  2136. tasks = [];
  2137. errors = [];
  2138. ctx;
  2139. events;
  2140. path = [];
  2141. rendererClass;
  2142. rendererClassOptions;
  2143. rendererSelection;
  2144. boundSignalHandler;
  2145. concurrency;
  2146. renderer;
  2147. /**
  2148. * Whether this is the root task.
  2149. */
  2150. isRoot() {
  2151. return !this.parentTask;
  2152. }
  2153. /**
  2154. * Whether this is a subtask of another task list.
  2155. */
  2156. isSubtask() {
  2157. return !!this.parentTask;
  2158. }
  2159. /**
  2160. * Add tasks to current task list.
  2161. *
  2162. * @see {@link https://listr2.kilic.dev/task/task.html}
  2163. */
  2164. add(tasks) {
  2165. this.tasks.push(...this.generate(tasks));
  2166. }
  2167. /**
  2168. * Run the task list.
  2169. *
  2170. * @see {@link https://listr2.kilic.dev/listr/listr.html#run-the-generated-task-list}
  2171. */
  2172. async run(context) {
  2173. if (!this.renderer) {
  2174. this.renderer = new this.rendererClass(this.tasks, this.rendererClassOptions, this.events);
  2175. }
  2176. await this.renderer.render();
  2177. this.ctx = this.options?.ctx ?? context ?? {};
  2178. await Promise.all(this.tasks.map((task) => task.check(this.ctx)));
  2179. try {
  2180. await Promise.all(this.tasks.map((task) => this.concurrency.add(() => this.runTask(task))));
  2181. this.renderer.end();
  2182. this.removeSignalHandler();
  2183. } catch (err) {
  2184. if (this.options.exitOnError !== false) {
  2185. this.renderer.end(err);
  2186. this.removeSignalHandler();
  2187. throw err;
  2188. }
  2189. }
  2190. return this.ctx;
  2191. }
  2192. generate(tasks) {
  2193. tasks = Array.isArray(tasks) ? tasks : [tasks];
  2194. return tasks.map((task) => {
  2195. let rendererTaskOptions;
  2196. if (this.rendererSelection === "PRIMARY" /* PRIMARY */) {
  2197. rendererTaskOptions = task.rendererOptions;
  2198. } else if (this.rendererSelection === "SECONDARY" /* SECONDARY */) {
  2199. rendererTaskOptions = task.fallbackRendererOptions;
  2200. }
  2201. return new Task(
  2202. this,
  2203. task,
  2204. this.options,
  2205. this.rendererClassOptions,
  2206. rendererTaskOptions
  2207. );
  2208. });
  2209. }
  2210. async runTask(task) {
  2211. if (!await task.check(this.ctx)) {
  2212. return;
  2213. }
  2214. return new TaskWrapper(task).run(this.ctx);
  2215. }
  2216. signalHandler() {
  2217. this.tasks?.forEach(async (task) => {
  2218. if (task.isPending()) {
  2219. task.state$ = "FAILED" /* FAILED */;
  2220. }
  2221. });
  2222. if (this.isRoot()) {
  2223. this.renderer.end(new Error("Interrupted."));
  2224. process.exit(127);
  2225. }
  2226. }
  2227. removeSignalHandler() {
  2228. if (this.boundSignalHandler) {
  2229. process.removeListener("SIGINT", this.boundSignalHandler);
  2230. }
  2231. }
  2232. };
  2233. export {
  2234. ANSI_ESCAPE,
  2235. ANSI_ESCAPE_CODES,
  2236. BaseEventMap,
  2237. Concurrency,
  2238. DefaultRenderer,
  2239. EventManager,
  2240. LISTR_DEFAULT_RENDERER_STYLE,
  2241. LISTR_LOGGER_STDERR_LEVELS,
  2242. LISTR_LOGGER_STYLE,
  2243. Listr,
  2244. ListrDefaultRendererLogLevels,
  2245. ListrEnvironmentVariables,
  2246. ListrError,
  2247. ListrErrorTypes,
  2248. ListrEventManager,
  2249. ListrEventType,
  2250. ListrLogLevels,
  2251. ListrLogger,
  2252. ListrPromptAdapter,
  2253. ListrRendererError,
  2254. ListrRendererSelection,
  2255. ListrTaskEventManager,
  2256. ListrTaskEventType,
  2257. ListrTaskState,
  2258. PRESET_TIMER,
  2259. PRESET_TIMESTAMP,
  2260. ProcessOutput,
  2261. ProcessOutputBuffer,
  2262. ProcessOutputStream,
  2263. PromptError,
  2264. SilentRenderer,
  2265. SimpleRenderer,
  2266. Spinner,
  2267. TestRenderer,
  2268. TestRendererSerializer,
  2269. VerboseRenderer,
  2270. assertFunctionOrSelf,
  2271. cleanseAnsi,
  2272. cloneObject,
  2273. color,
  2274. createWritable,
  2275. delay,
  2276. figures,
  2277. getRenderer,
  2278. getRendererClass,
  2279. indent,
  2280. isObservable,
  2281. isReadable,
  2282. isUnicodeSupported,
  2283. parseTimer,
  2284. parseTimestamp,
  2285. splat
  2286. };