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AC,IAAI,CAAC,CAAA;QAClB,gDAAgD;QAChD,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;IAC7B,CAAC;CAGF;AAlKD,kCAkKC;AAED,MAAa,gBAAgB;IAI3B,YAA6B,WAAwB;QAAxB,gBAAW,GAAX,WAAW,CAAa;QAH7C,UAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;QAClB,eAAU,GAAG,IAAI,CAAC,KAAK,GAAG,IAAI,CAAA;IAEkB,CAAC;IAEzD,MAAM,CAAC,WAAmB,EAAE,KAAa;QACvC,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;QACtB,IAAI,GAAG,IAAI,IAAI,CAAC,UAAU,IAAI,WAAW,IAAI,KAAK,EAAE;YAClD,IAAI,CAAC,UAAU,GAAG,GAAG,GAAG,IAAI,CAAA;YAE5B,IAAI,CAAC,WAAW,CAAC,KAAK,GAAG,KAAK,CAAA;YAC9B,IAAI,CAAC,WAAW,CAAC,aAAa,GAAG,WAAW,CAAA;SAC7C;IACH,CAAC;CACF;AAfD,4CAeC","sourcesContent":["/*!\n * node-progress\n * Copyright(c) 2011 TJ Holowaychuk <tj@vision-media.ca>\n * MIT Licensed\n */\n\nexport abstract class ProgressBar {\n private readonly stream: any\n\n private current = 0\n total = 0\n private readonly width: number\n\n private chars: any\n private tokens: any = null\n private lastDraw = \"\"\n\n private start = 0\n\n private complete = false\n\n /**\n * Initialize a `ProgressBar` with the given `fmt` string and `options` or`total`.\n *\n * Options:\n * - `curr` current completed index\n * - `total` total number of ticks to complete\n * - `width` the displayed width of the progress bar defaulting to total\n * - `stream` the output stream defaulting to stderr\n * - `head` head character defaulting to complete character\n * - `complete` completion character defaulting to \"=\"\n * - `incomplete` incomplete character defaulting to \"-\"\n * - `renderThrottle` minimum time between updates in milliseconds defaulting to 16\n * - `callback` optional function to call when the progress bar completes\n * - `clear` will clear the progress bar upon termination\n *\n * Tokens:\n * - `:bar` the progress bar itself\n * - `:current` current tick number\n * - `:total` total ticks\n * - `:elapsed` time elapsed in seconds\n * - `:percent` completion percentage\n * - `:eta` eta in seconds\n * - `:rate` rate of ticks per second\n */\n constructor(private readonly format: string, options: any = {}) {\n this.stream = options.stream || process.stderr\n\n this.total = options.total\n this.width = options.width || this.total\n this.chars = {\n complete: options.complete || \"=\",\n incomplete: options.incomplete || \"-\",\n head: options.head || options.complete || \"=\",\n }\n }\n\n /**\n * \"tick\" the progress bar with optional `len` and optional `tokens`.\n */\n tick(delta: number) {\n this.currentAmount = this.current + delta\n }\n\n set currentAmount(value: number) {\n this.current = value\n\n if (this.complete) {\n return\n }\n\n this.render()\n\n if (this.current >= this.total) {\n this.complete = true\n this.terminate()\n }\n }\n\n render() {\n // start time for eta\n if (this.start === 0) {\n this.start = Date.now()\n }\n\n const ratio = Math.min(Math.max(this.current / this.total, 0), 1)\n\n const percent = ratio * 100\n const elapsed = Date.now() - this.start\n const eta = percent === 100 ? 0 : elapsed * (this.total / this.current - 1)\n const rate = this.current / (elapsed / 1000)\n\n /* populate the bar template with percentages and timestamps */\n let str = this.format\n .replace(\":current\", this.current.toString())\n .replace(\":total\", this.total.toString())\n .replace(\":elapsed\", isNaN(elapsed) ? \"0.0\" : (elapsed / 1000).toFixed(1))\n .replace(\":eta\", isNaN(eta) || !isFinite(eta) ? \"0.0\" : (eta / 1000).toFixed(1))\n .replace(\":percent\", percent.toFixed(0) + \"%\")\n .replace(\":rate\", Math.round(rate).toString())\n\n // compute the available space (non-zero) for the bar\n let availableSpace = Math.max(0, this.stream.columns - str.replace(\":bar\", \"\").length)\n if (availableSpace && process.platform === \"win32\") {\n availableSpace -= 1\n }\n\n const width = Math.min(this.width, availableSpace)\n const completeLength = Math.round(width * ratio)\n let complete = Array(Math.max(0, completeLength + 1)).join(this.chars.complete)\n const incomplete = Array(Math.max(0, width - completeLength + 1)).join(this.chars.incomplete)\n\n /* add head to the complete string */\n if (completeLength > 0) {\n complete = `${complete.slice(0, -1)}${this.chars.head}`\n }\n\n /* fill in the actual progress bar */\n str = str.replace(\":bar\", complete + incomplete)\n\n /* replace the extra tokens */\n if (this.tokens != null) {\n for (const key of Object.keys(this.tokens)) {\n str = str.replace(`:${key}`, this.tokens[key])\n }\n }\n\n if (this.lastDraw !== str) {\n this.stream.cursorTo(0)\n this.stream.write(str)\n this.stream.clearLine(1)\n this.lastDraw = str\n }\n }\n\n /**\n * \"update\" the progress bar to represent an exact percentage.\n * The ratio (between 0 and 1) specified will be multiplied by `total` and\n * floored, representing the closest available \"tick.\" For example, if a\n * progress bar has a length of 3 and `update(0.5)` is called, the progress\n * will be set to 1.\n *\n * A ratio of 0.5 will attempt to set the progress to halfway.\n */\n update(ratio: number) {\n const goal = Math.floor(ratio * this.total)\n const delta = goal - this.current\n this.tick(delta)\n }\n\n /**\n * \"interrupt\" the progress bar and write a message above it.\n */\n interrupt(message: string) {\n // clear the current line\n const stream = this.stream\n stream.clearLine()\n // move the cursor to the start of the line\n stream.cursorTo(0)\n // write the message text\n stream.write(message)\n // terminate the line after writing the message\n stream.write(\"\\n\")\n // re-display the progress bar with its lastDraw\n stream.write(this.lastDraw)\n }\n\n abstract terminate(): void\n}\n\nexport class ProgressCallback {\n private start = Date.now()\n private nextUpdate = this.start + 1000\n\n constructor(private readonly progressBar: ProgressBar) {}\n\n update(transferred: number, total: number) {\n const now = Date.now()\n if (now >= this.nextUpdate || transferred >= total) {\n this.nextUpdate = now + 1000\n\n this.progressBar.total = total\n this.progressBar.currentAmount = transferred\n }\n }\n}\n"]}
\No newline at end of file