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Af0B,C","sourcesContent":["/*!\n * node-progress\n * Copyright(c) 2011 TJ Holowaychuk \n * MIT Licensed\n */\n\nexport abstract class ProgressBar {\n private stream: any\n\n private current = 0\n total = 0\n private 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\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}"],"sourceRoot":""}