First upload version 0.0.1

This commit is contained in:
Neyra
2026-02-05 15:27:49 +08:00
commit 8e9b7201ed
4182 changed files with 593136 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
import DownloadEngineNodejs from "../../download-engine/engine/download-engine-nodejs.js";
import DownloadEngineMultiDownload from "../../download-engine/engine/download-engine-multi-download.js";
import { AvailableCLIProgressStyle } from "./progress-bars/switch-cli-progress-style.js";
import { CliFormattedStatus } from "./progress-bars/base-transfer-cli-progress-bar.js";
import { BaseMultiProgressBar } from "./multiProgressBars/BaseMultiProgressBar.js";
import cliSpinners from "cli-spinners";
type AllowedDownloadEngines = DownloadEngineNodejs | DownloadEngineMultiDownload;
export type CliProgressDownloadEngineOptions = {
truncateName?: boolean | number;
cliProgress?: boolean;
maxViewDownloads?: number;
createMultiProgressBar?: typeof BaseMultiProgressBar;
cliStyle?: AvailableCLIProgressStyle | ((status: CliFormattedStatus) => string);
cliName?: string;
cliAction?: string;
fetchStrategy?: "localFile" | "fetch";
loadingAnimation?: cliSpinners.SpinnerName;
};
export default class CliAnimationWrapper {
private readonly _downloadEngine;
private readonly _options;
private _activeCLI?;
constructor(downloadEngine: Promise<AllowedDownloadEngines>, _options: CliProgressDownloadEngineOptions);
private _init;
attachAnimation(): Promise<void>;
}
export {};

View File

@@ -0,0 +1,60 @@
import switchCliProgressStyle from "./progress-bars/switch-cli-progress-style.js";
import TransferCli from "./transfer-cli.js";
import { BaseMultiProgressBar } from "./multiProgressBars/BaseMultiProgressBar.js";
const DEFAULT_CLI_STYLE = "auto";
export default class CliAnimationWrapper {
_downloadEngine;
_options;
_activeCLI;
constructor(downloadEngine, _options) {
this._options = _options;
this._downloadEngine = downloadEngine;
this._init();
}
_init() {
if (!this._options.cliProgress) {
return;
}
this._options.cliAction ??= this._options.fetchStrategy === "localFile" ? "Copying" : "Downloading";
const cliOptions = { ...this._options };
if (this._options.cliAction) {
cliOptions.action = this._options.cliAction;
}
if (this._options.cliName) {
cliOptions.name = this._options.cliName;
}
cliOptions.createProgressBar = typeof this._options.cliStyle === "function" ?
{
createStatusLine: this._options.cliStyle,
multiProgressBar: this._options.createMultiProgressBar ?? BaseMultiProgressBar
} :
switchCliProgressStyle(this._options.cliStyle ?? DEFAULT_CLI_STYLE, {
truncateName: this._options.truncateName,
loadingSpinner: this._options.loadingAnimation
});
this._activeCLI = new TransferCli(cliOptions, this._options.cliLevel);
}
async attachAnimation() {
if (!this._activeCLI) {
return;
}
this._activeCLI.loadingAnimation.start();
try {
const engine = await this._downloadEngine;
this._activeCLI.loadingAnimation.stop();
engine.once("start", () => {
this._activeCLI?.start();
engine.on("progress", (progress) => {
this._activeCLI?.updateStatues(engine.downloadStatues, progress);
});
engine.on("closed", () => {
this._activeCLI?.stop();
});
});
}
finally {
this._activeCLI.loadingAnimation.stop();
}
}
}
//# sourceMappingURL=cli-animation-wrapper.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"cli-animation-wrapper.js","sourceRoot":"","sources":["../../../../src/download/transfer-visualize/transfer-cli/cli-animation-wrapper.ts"],"names":[],"mappings":"AAEA,OAAO,sBAAmD,MAAM,8CAA8C,CAAC;AAE/G,OAAO,WAA4C,MAAM,mBAAmB,CAAC;AAC7E,OAAO,EAAC,oBAAoB,EAAC,MAAM,6CAA6C,CAAC;AAGjF,MAAM,iBAAiB,GAA8B,MAAM,CAAC;AAiB5D,MAAM,CAAC,OAAO,OAAO,mBAAmB;IACnB,eAAe,CAAkC;IACjD,QAAQ,CAAmC;IACpD,UAAU,CAAe;IAEjC,YAAmB,cAA+C,EAAE,QAA0C;QAC1G,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,eAAe,GAAG,cAAc,CAAC;QACtC,IAAI,CAAC,KAAK,EAAE,CAAC;IACjB,CAAC;IAEO,KAAK;QACT,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC;YAC7B,OAAO;QACX,CAAC;QACD,IAAI,CAAC,QAAQ,CAAC,SAAS,K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AAI,CAAC,UAAU,CAAC,gBAAgB,CAAC,IAAI,EAAE,CAAC;YAExC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE;gBACtB,IAAI,CAAC,UAAU,EAAE,KAAK,EAAE,CAAC;gBAEzB,MAAM,CAAC,EAAE,CAAC,UAAU,EAAE,CAAC,QAAQ,EAAE,EAAE;oBAC/B,IAAI,CAAC,UAAU,EAAE,aAAa,CAAC,MAAM,CAAC,eAAe,EAAE,QAAQ,CAAC,CAAC;gBACrE,CAAC,CAAC,CAAC;gBAEH,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE;oBACrB,IAAI,CAAC,UAAU,EAAE,IAAI,EAAE,CAAC;gBAC5B,CAAC,CAAC,CAAC;YACP,CAAC,CAAC,CAAC;QACP,CAAC;gBAAS,CAAC;YACP,IAAI,CAAC,UAAU,CAAC,gBAAgB,CAAC,IAAI,EAAE,CAAC;QAC5C,CAAC;IACL,CAAC;CACJ"}

View File

@@ -0,0 +1,19 @@
import UpdateManager from "stdout-update";
import { CLIProgressPrintType } from "../multiProgressBars/BaseMultiProgressBar.js";
export type BaseLoadingAnimationOptions = {
updateIntervalMs?: number | null;
loadingText?: string;
logType: CLIProgressPrintType;
};
export declare const DEFAULT_LOADING_ANIMATION_OPTIONS: BaseLoadingAnimationOptions;
export default abstract class BaseLoadingAnimation {
protected options: BaseLoadingAnimationOptions;
protected stdoutManager: UpdateManager;
protected _animationActive: boolean;
protected constructor(options?: BaseLoadingAnimationOptions);
protected _render(): void;
protected abstract createFrame(): string;
start(): Promise<void>;
stop(): void;
private _processExit;
}

View File

@@ -0,0 +1,52 @@
import UpdateManager from "stdout-update";
import sleep from "sleep-promise";
export const DEFAULT_LOADING_ANIMATION_OPTIONS = {
loadingText: "Gathering information",
logType: "update"
};
const DEFAULT_UPDATE_INTERVAL_MS = 300;
export default class BaseLoadingAnimation {
options;
stdoutManager = UpdateManager.getInstance();
_animationActive = false;
constructor(options = DEFAULT_LOADING_ANIMATION_OPTIONS) {
this.options = options;
this._processExit = this._processExit.bind(this);
}
_render() {
const frame = this.createFrame();
if (this.options.logType === "update") {
this.stdoutManager.update([frame]);
}
else {
console.log(frame);
}
}
async start() {
process.on("SIGINT", this._processExit);
if (this.options.logType === "update") {
this.stdoutManager.hook();
}
this._animationActive = true;
while (this._animationActive) {
this._render();
await sleep(this.options.updateIntervalMs || DEFAULT_UPDATE_INTERVAL_MS);
}
}
stop() {
if (!this._animationActive) {
return;
}
this._animationActive = false;
if (this.options.logType === "update") {
this.stdoutManager.erase();
this.stdoutManager.unhook(false);
}
process.off("SIGINT", this._processExit);
}
_processExit() {
this.stop();
process.exit(0);
}
}
//# sourceMappingURL=base-loading-animation.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"base-loading-animation.js","sourceRoot":"","sources":["../../../../../src/download/transfer-visualize/transfer-cli/loading-animation/base-loading-animation.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,MAAM,eAAe,CAAC;AASlC,MAAM,CAAC,MAAM,iCAAiC,GAAgC;IAC1E,WAAW,EAAE,uBAAuB;IACpC,OAAO,EAAE,QAAQ;CACpB,CAAC;AAEF,MAAM,0BAA0B,GAAG,GAAG,CAAC;AAEvC,MAAM,CAAC,OAAO,OAAgB,oBAAoB;IACpC,OAAO,CAA8B;IACrC,aAAa,GAAG,aAAa,CAAC,WAAW,EAAE,CAAC;IAC5C,gBAAgB,GAAG,KAAK,CAAC;IAGnC,YAAsB,UAAuC,iCAAiC;QAC1F,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACrD,CAAC;IAES,OAAO;QACb,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;QAEjC,IAAI,IAAI,CAAC,OAAO,CAAC,OAAO,KAAK,QAAQ,EA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ner } from "cli-spinners";
export default class CliSpinnersLoadingAnimation extends BaseLoadingAnimation {
private _spinner;
private _frameIndex;
constructor(spinner: Spinner, options: BaseLoadingAnimationOptions);
protected createFrame(): string;
}

View File

@@ -0,0 +1,20 @@
import BaseLoadingAnimation, { DEFAULT_LOADING_ANIMATION_OPTIONS } from "./base-loading-animation.js";
export default class CliSpinnersLoadingAnimation extends BaseLoadingAnimation {
_spinner;
_frameIndex = 0;
constructor(spinner, options) {
options = { ...DEFAULT_LOADING_ANIMATION_OPTIONS, ...options };
options.updateIntervalMs ??= spinner.interval;
super(options);
this._spinner = spinner;
}
createFrame() {
const frame = this._spinner.frames[this._frameIndex];
this._frameIndex++;
if (this._frameIndex >= this._spinner.frames.length) {
this._frameIndex = 0;
}
return `${frame} ${this.options.loadingText}`;
}
}
//# sourceMappingURL=cli-spinners-loading-animation.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"cli-spinners-loading-animation.js","sourceRoot":"","sources":["../../../../../src/download/transfer-visualize/transfer-cli/loading-animation/cli-spinners-loading-animation.ts"],"names":[],"mappings":"AAAA,OAAO,oBAAoB,EAAE,EAA8B,iCAAiC,EAAC,MAAM,6BAA6B,CAAC;AAGjI,MAAM,CAAC,OAAO,OAAO,2BAA4B,SAAQ,oBAAoB;IACjE,QAAQ,CAAU;IAClB,WAAW,GAAG,CAAC,CAAC;IAExB,YAAmB,OAAgB,EAAE,OAAoC;QACrE,OAAO,GAAG,EAAC,GAAG,iCAAiC,EAAE,GAAG,OAAO,EAAC,CAAC;QAC7D,OAAO,CAAC,gBAAgB,KAAK,OAAO,CAAC,QAAQ,CAAC;QAC9C,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC5B,CAAC;IAES,WAAW;QACjB,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QACrD,IAAI,CAAC,WAAW,EAAE,CAAC;QACnB,IAAI,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;YAClD,IAAI,CAAC,WAAW,GAAG,CAAC,CAAC;QACzB,CAAC;QACD,OAAO,GAAG,KAAK,IAAI,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC;IAClD,CAAC;CACJ"}

View File

@@ -0,0 +1,24 @@
import { TransferCliProgressBar } from "../progress-bars/base-transfer-cli-progress-bar.js";
import { FormattedStatus } from "../../format-transfer-status.js";
export type MultiProgressBarOptions = {
maxViewDownloads: number;
createProgressBar: TransferCliProgressBar;
action?: string;
};
export type CLIProgressPrintType = "update" | "log";
export declare class BaseMultiProgressBar {
protected options: MultiProgressBarOptions;
readonly updateIntervalMs: null | number;
readonly printType: CLIProgressPrintType;
constructor(options: MultiProgressBarOptions);
protected createProgresses(statuses: FormattedStatus[]): string;
/**
* Sorts the statuses by importance, active downloads first, then remaining, then finished (by end time - latest first)
*/
protected recorderStatusByImportance(statuses: FormattedStatus[]): {
notFinished: boolean;
remaining: number;
allStatusesSorted: FormattedStatus[];
};
createMultiProgressBar(statuses: FormattedStatus[], oneStatus: FormattedStatus): string;
}

View File

@@ -0,0 +1,50 @@
import { DownloadStatus } from "../../../download-engine/download-file/progress-status-file.js";
import chalk from "chalk";
import prettyBytes from "pretty-bytes";
export class BaseMultiProgressBar {
options;
updateIntervalMs = null;
printType = "update";
constructor(options) {
this.options = options;
}
createProgresses(statuses) {
return statuses.map((status) => {
status.transferAction = this.options.action ?? status.transferAction;
return this.options.createProgressBar.createStatusLine(status);
})
.join("\n");
}
/**
* Sorts the statuses by importance, active downloads first, then remaining, then finished (by end time - latest first)
*/
recorderStatusByImportance(statuses) {
const activeTasks = statuses.filter(status => status.downloadStatus === DownloadStatus.Active);
const remaining = statuses.filter(status => [DownloadStatus.Paused, DownloadStatus.NotStarted].includes(status.downloadStatus));
const loading = statuses.filter(status => status.downloadStatus === DownloadStatus.Loading);
const finishedTasks = statuses.filter(status => status.downloadStatus === DownloadStatus.Finished)
.sort((a, b) => b.endTime - a.endTime);
const showTotalTasks = activeTasks.concat(remaining)
.concat(loading);
const showTotalTasksWithFinished = showTotalTasks.concat(finishedTasks);
return {
notFinished: showTotalTasks.length > 0,
remaining: remaining.length + loading.length,
allStatusesSorted: showTotalTasksWithFinished
};
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
createMultiProgressBar(statuses, oneStatus) {
if (statuses.length < this.options.maxViewDownloads) {
return this.createProgresses(statuses);
}
const { notFinished, remaining, allStatusesSorted } = this.recorderStatusByImportance(statuses);
const tasksLogs = this.createProgresses(allStatusesSorted.slice(0, this.options.maxViewDownloads));
if (notFinished) {
return tasksLogs + `\nand ${chalk.gray(remaining)} more out of ${chalk.blueBright(statuses.length)} downloads.`;
}
const totalSize = allStatusesSorted.reduce((acc, status) => acc + status.totalBytes, 0);
return tasksLogs + `\n${chalk.green(`All ${statuses.length} downloads (${prettyBytes(totalSize)}) finished.`)}`;
}
}
//# sourceMappingURL=BaseMultiProgressBar.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"BaseMultiProgressBar.js","sourceRoot":"","sources":["../../../../../src/download/transfer-visualize/transfer-cli/multiProgressBars/BaseMultiProgressBar.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,cAAc,EAAC,MAAM,gEAAgE,CAAC;AAC9F,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,WAAW,MAAM,cAAc,CAAC;AAUvC,MAAM,OAAO,oBAAoB;IAIA;IAHb,gBAAgB,GAAkB,IAAI,CAAC;IACvC,SAAS,GAAyB,QAAQ,CAAC;IAE3D,YAA6B,OAAgC;QAAhC,YAAO,GAAP,OAAO,CAAyB;IAC7D,CAAC;IAES,gBAAgB,CAAC,QAA2B;QAClD,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;YAC3B,MAAM,CAAC,cAAc,GAAG,IAAI,CAAC,OAA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,CAAC;IACN,CAAC;IAED,6DAA6D;IAC7D,sBAAsB,CAAC,QAA2B,EAAE,SAA0B;QAC1E,IAAI,QAAQ,CAAC,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAAE,CAAC;YAClD,OAAO,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC;QAC3C,CAAC;QAED,MAAM,EAAC,WAAW,EAAE,SAAS,EAAE,iBAAiB,EAAC,GAAG,IAAI,CAAC,0BAA0B,CAAC,QAAQ,CAAC,CAAC;QAC9F,MAAM,SAAS,GAAG,IAAI,CAAC,gBAAgB,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC;QAEnG,IAAI,WAAW,EAAE,CAAC;YACd,OAAO,SAAS,GAAG,SAAS,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,gBAAgB,KAAK,CAAC,UAAU,CAAC,QAAQ,CAAC,MAAM,CAAC,aAAa,CAAC;QACpH,CAAC;QAED,MAAM,SAAS,GAAG,iBAAiB,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,CAAC,GAAG,GAAG,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC;QACxF,OAAO,SAAS,GAAG,KAAK,KAAK,CAAC,KAAK,CAAC,OAAO,QAAQ,CAAC,MAAM,eAAe,WAAW,CAAC,SAAS,CAAC,aAAa,CAAC,EAAE,CAAC;IACpH,CAAC;CACJ"}

View File

@@ -0,0 +1,5 @@
import { SummaryMultiProgressBar } from "./SummaryMultiProgressBar.js";
export declare class CIMultiProgressBar extends SummaryMultiProgressBar {
readonly printType = "log";
readonly updateIntervalMs: number;
}

View File

@@ -0,0 +1,6 @@
import { SummaryMultiProgressBar } from "./SummaryMultiProgressBar.js";
export class CIMultiProgressBar extends SummaryMultiProgressBar {
printType = "log";
updateIntervalMs = parseInt(process.env.IPULL_CI_UPDATE_INTERVAL ?? "0") || 8_000;
}
//# sourceMappingURL=CIMultiProgressBar.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"CIMultiProgressBar.js","sourceRoot":"","sources":["../../../../../src/download/transfer-visualize/transfer-cli/multiProgressBars/CIMultiProgressBar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,uBAAuB,EAAC,MAAM,8BAA8B,CAAC;AAErE,MAAM,OAAO,kBAAmB,SAAQ,uBAAuB;IAClC,SAAS,GAAG,KAAK,CAAC;IAClB,gBAAgB,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,wBAAwB,IAAI,GAAG,CAAC,IAAI,KAAK,CAAC;CAC9G"}

View File

@@ -0,0 +1,9 @@
import { BaseMultiProgressBar, CLIProgressPrintType } from "./BaseMultiProgressBar.js";
import { FormattedStatus } from "../../format-transfer-status.js";
export declare class SummaryMultiProgressBar extends BaseMultiProgressBar {
readonly printType: CLIProgressPrintType;
readonly updateIntervalMs: number;
private _parallelDownloads;
private _lastStatuses;
createMultiProgressBar(statuses: FormattedStatus[], oneStatus: FormattedStatus): string;
}

View File

@@ -0,0 +1,35 @@
import { BaseMultiProgressBar } from "./BaseMultiProgressBar.js";
import { DownloadFlags, DownloadStatus } from "../../../download-engine/download-file/progress-status-file.js";
export class SummaryMultiProgressBar extends BaseMultiProgressBar {
printType = "update";
updateIntervalMs = 0;
_parallelDownloads = 0;
_lastStatuses = [];
createMultiProgressBar(statuses, oneStatus) {
oneStatus = structuredClone(oneStatus);
oneStatus.downloadFlags.push(DownloadFlags.DownloadSequence);
const linesToPrint = [];
let index = 0;
for (const status of statuses) {
const isStatusChanged = this._lastStatuses[index++]?.downloadStatus !== status.downloadStatus;
const copyStatus = structuredClone(status);
if (isStatusChanged) {
linesToPrint.push(copyStatus);
}
}
if (this.printType === "log") {
this._lastStatuses = structuredClone(statuses);
}
const { allStatusesSorted } = this.recorderStatusByImportance(linesToPrint);
const filterStatusesSliced = allStatusesSorted.slice(0, this.options.maxViewDownloads);
if (statuses.length > 1 || oneStatus.downloadStatus === DownloadStatus.Active) {
filterStatusesSliced.push(oneStatus);
}
const activeDownloads = statuses.filter((status) => status.downloadStatus === DownloadStatus.Active).length;
this._parallelDownloads ||= activeDownloads;
const finishedDownloads = statuses.filter((status) => status.downloadStatus === DownloadStatus.Finished).length;
oneStatus.comment = `${finishedDownloads}/${statuses.length} files done${this._parallelDownloads > 1 ? ` (${activeDownloads} active)` : ""}`;
return this.createProgresses(filterStatusesSliced);
}
}
//# sourceMappingURL=SummaryMultiProgressBar.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"SummaryMultiProgressBar.js","sourceRoot":"","sources":["../../../../../src/download/transfer-visualize/transfer-cli/multiProgressBars/SummaryMultiProgressBar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,oBAAoB,EAAuB,MAAM,2BAA2B,CAAC;AAErF,OAAO,EAAC,aAAa,EAAE,cAAc,EAAC,MAAM,gEAAgE,CAAC;AAE7G,MAAM,OAAO,uBAAwB,SAAQ,oBAAoB;IACpC,SAAS,GAAyB,QAAQ,CAAC;IAC3C,gBAAgB,GAAW,CAAC,CAAC;IAC9C,kBAAkB,GAAG,CAAC,CAAC;IACvB,aAAa,GAAsB,EAAE,CAAC;IAErC,sBAAsB,CAAC,QAA2B,EAAE,SAA0B;QACnF,SAAS,GAAG,eAAe,CAAC,SAAS,CAAC,CAAC;QACvC,SAAS,CAAC,aAAa,CAAC,IAAI,CAAC,aAAa,CAAC,gBAAgB,CAAC,CAAC;QAE7D,MAAM,YAAY,GAAsB,EAAE,CAAC;QAE3C,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,KAAK,MAAM,MAAM,IAAI,QAAQ,EAAE,CAAC;YAC5B,MAAM,eAAe,GAAG,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC,EAAE,cAAc,KAAK,MAAM,CAAC,cAAc,CAAC;YAC9F,MAAM,UAAU,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC;YAE3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fer-status.js";
import { BaseMultiProgressBar } from "../multiProgressBars/BaseMultiProgressBar.js";
import { DataLine, DataPart } from "../../utils/data-line.js";
import cliSpinners, { Spinner } from "cli-spinners";
export type CliFormattedStatus = FormattedStatus & {
transferAction: string;
};
export type BaseCliOptions = {
truncateName?: boolean | number;
loadingSpinner?: cliSpinners.SpinnerName;
};
export interface TransferCliProgressBar {
multiProgressBar: typeof BaseMultiProgressBar;
createStatusLine(status: CliFormattedStatus): string;
}
/**
* A class to display transfer progress in the terminal, with a progress bar and other information.
*/
export default class BaseTransferCliProgressBar implements TransferCliProgressBar {
multiProgressBar: typeof BaseMultiProgressBar;
downloadLoadingSpinner: Spinner;
private _spinnerState;
protected status: CliFormattedStatus;
protected options: BaseCliOptions;
protected minNameLength: number;
constructor(options: BaseCliOptions);
switchTransferToShortText(): string;
protected get showETA(): boolean;
protected getNameSize(fileName?: string): number;
protected getSpinnerText(): string;
protected getNameAndCommentDataParts(): DataPart[];
protected getETA(spacer?: string, formatter?: (text: string, size: number, type: "spacer" | "time") => string): DataLine;
protected createProgressBarLine(length: number): string;
protected renderProgressLine(): string;
protected renderFinishedLine(): string;
protected renderPendingLine(): string;
protected renderLoadingLine(): string;
createStatusLine(status: CliFormattedStatus): string;
}

View File

@@ -0,0 +1,284 @@
import chalk from "chalk";
import { truncateText } from "../../utils/cli-text.js";
import { clamp } from "../../utils/numbers.js";
import { DownloadStatus } from "../../../download-engine/download-file/progress-status-file.js";
import { BaseMultiProgressBar } from "../multiProgressBars/BaseMultiProgressBar.js";
import { STATUS_ICONS } from "../../utils/progressBarIcons.js";
import { renderDataLine } from "../../utils/data-line.js";
import cliSpinners from "cli-spinners";
const SKIP_ETA_START_TIME = 1000 * 2;
const MIN_NAME_LENGTH = 20;
const MIN_COMMENT_LENGTH = 15;
const DEFAULT_SPINNER_UPDATE_INTERVAL_MS = 10;
/**
* A class to display transfer progress in the terminal, with a progress bar and other information.
*/
export default class BaseTransferCliProgressBar {
multiProgressBar = BaseMultiProgressBar;
downloadLoadingSpinner;
_spinnerState = {
step: 0,
lastChanged: 0
};
status = null;
options;
minNameLength = MIN_NAME_LENGTH;
constructor(options) {
this.options = options;
this.downloadLoadingSpinner = cliSpinners[options.loadingSpinner ?? "dots"];
}
switchTransferToShortText() {
switch (this.status.transferAction) {
case "Downloading":
return "Pull";
case "Copying":
return "Copy";
}
return this.status.transferAction;
}
get showETA() {
return this.status.startTime < Date.now() - SKIP_ETA_START_TIME;
}
getNameSize(fileName = this.status.fileName) {
return this.options.truncateName === false
? fileName.length
: typeof this.options.truncateName === "number"
? this.options.truncateName
: Math.min(fileName.length, this.minNameLength);
}
getSpinnerText() {
const spinner = this.downloadLoadingSpinner.frames[this._spinnerState.step];
if (this._spinnerState.lastChanged + DEFAULT_SPINNER_UPDATE_INTERVAL_MS < Date.now()) {
this._spinnerState.step++;
if (this._spinnerState.step >= this.downloadLoadingSpinner.frames.length) {
this._spinnerState.step = 0;
}
this._spinnerState.lastChanged = Date.now();
}
return spinner;
}
getNameAndCommentDataParts() {
const { fileName, comment, downloadStatus } = this.status;
let fullComment = comment;
if (downloadStatus === DownloadStatus.Cancelled || downloadStatus === DownloadStatus.Paused) {
if (fullComment) {
fullComment += " | " + downloadStatus;
}
else {
fullComment = downloadStatus;
}
}
return [{
type: "name",
fullText: fileName,
size: this.getNameSize(),
flex: typeof this.options.truncateName === "number"
? undefined
: 1,
maxSize: fileName.length,
cropper: truncateText,
formatter: (text) => chalk.bold(text)
}, ...((fullComment == null || fullComment.length === 0)
? []
: [{
type: "spacer",
fullText: " (",
size: " (".length,
formatter: (text) => chalk.dim(text)
}, {
type: "nameComment",
fullText: fullComment,
size: Math.min(fullComment.length, MIN_COMMENT_LENGTH),
maxSize: fullComment.length,
flex: 1,
cropper: truncateText,
formatter: (text) => chalk.dim(text)
}, {
type: "spacer",
fullText: ")",
size: ")".length,
formatter: (text) => chalk.dim(text)
}])];
}
getETA(spacer = " | ", formatter = text => text) {
const formatedTimeLeft = this.status.timeLeft < 1_000 ? "0s" : this.status.formatTimeLeft;
const timeLeft = `${formatedTimeLeft.padStart("10s".length)} left`;
if (this.showETA) {
return [{
type: "spacer",
fullText: spacer,
size: spacer.length,
formatter(text, size) {
return formatter(text, size, "spacer");
}
}, {
type: "timeLeft",
fullText: timeLeft,
size: timeLeft.length,
formatter(text, size) {
return formatter(text, size, "time");
}
}];
}
return [];
}
createProgressBarLine(length) {
const fileName = truncateText(this.status.fileName, length);
const percentage = clamp(this.status.transferredBytes / this.status.totalBytes, 0, 1);
const fullLength = Math.floor(percentage * length);
const emptyLength = length - fullLength;
return chalk.cyan(fileName.slice(0, fullLength)) + chalk.dim(fileName.slice(fullLength, fullLength + emptyLength));
}
renderProgressLine() {
const { formattedPercentage, formattedSpeed, formatTransferredOfTotal, formatTotal } = this.status;
const status = this.switchTransferToShortText();
return renderDataLine([
{
type: "status",
fullText: status,
size: status.length,
formatter: (text) => chalk.cyan(text)
},
{
type: "spacer",
fullText: " ",
size: " ".length
},
{
type: "percentage",
fullText: formattedPercentage,
size: "100.00%".length,
formatter: () => chalk.green(formattedPercentage)
},
{
type: "spacer",
fullText: " ",
size: " ".length
},
{
type: "progressBar",
size: this.getNameSize(),
fullText: "",
flex: 4,
addEndPadding: 4,
maxSize: 40,
formatter: (_, size) => {
return `[${this.createProgressBarLine(size)}]`;
}
},
{
type: "spacer",
fullText: " ",
size: " ".length
},
{
type: "transferred",
fullText: formatTransferredOfTotal,
size: `999.99MB/${formatTotal}`.length
},
{
type: "spacer",
fullText: " (",
size: " (".length
},
{
type: "speed",
fullText: formattedSpeed,
size: Math.max("00.00kB/s".length, formattedSpeed.length),
formatter: text => chalk.ansi256(31)(text)
},
{
type: "spacer",
fullText: ")",
size: ")".length
},
...this.getETA(" ~ ", text => chalk.dim(text))
]);
}
renderFinishedLine() {
const status = this.status.downloadStatus === DownloadStatus.Finished ? chalk.green(STATUS_ICONS.done) : chalk.red(STATUS_ICONS.failed);
return renderDataLine([
{
type: "status",
fullText: "",
size: 1,
formatter: () => status
},
{
type: "spacer",
fullText: " ",
size: " ".length
},
...this.getNameAndCommentDataParts()
]);
}
renderPendingLine() {
return renderDataLine([
{
type: "status",
fullText: "",
size: 1,
formatter: () => STATUS_ICONS.pending
},
{
type: "spacer",
fullText: " ",
size: " ".length
},
...this.getNameAndCommentDataParts(),
{
type: "spacer",
fullText: " ",
size: " ".length
},
{
type: "description",
fullText: this.status.formatTotal,
size: this.status.formatTotal.length,
formatter: (text) => chalk.dim(text)
}
]);
}
renderLoadingLine() {
const spinner = this.getSpinnerText();
const showText = "Gathering information";
return renderDataLine([
{
type: "status",
fullText: spinner,
size: spinner.length,
formatter: (text) => chalk.cyan(text)
},
{
type: "spacer",
fullText: " ",
size: " ".length
},
{
type: "name",
fullText: showText,
size: this.getNameSize(showText),
flex: typeof this.options.truncateName === "number"
? undefined
: 1,
maxSize: showText.length,
cropper: truncateText,
formatter: (text) => chalk.bold(text)
}
]);
}
createStatusLine(status) {
this.status = status;
if ([DownloadStatus.Finished, DownloadStatus.Error, DownloadStatus.Cancelled].includes(this.status.downloadStatus)) {
return this.renderFinishedLine();
}
if (this.status.downloadStatus === DownloadStatus.NotStarted) {
return this.renderPendingLine();
}
if (this.status.downloadStatus === DownloadStatus.Loading) {
return this.renderLoadingLine();
}
return this.renderProgressLine();
}
}
//# sourceMappingURL=base-transfer-cli-progress-bar.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,6 @@
import SummaryTransferCliProgressBar from "./summary-transfer-cli-progress-bar.js";
import { CIMultiProgressBar } from "../multiProgressBars/CIMultiProgressBar.js";
export default class CiTransferCliProgressBar extends SummaryTransferCliProgressBar {
multiProgressBar: typeof CIMultiProgressBar;
minNameLength: number;
}

View File

@@ -0,0 +1,8 @@
import SummaryTransferCliProgressBar from "./summary-transfer-cli-progress-bar.js";
import { CIMultiProgressBar } from "../multiProgressBars/CIMultiProgressBar.js";
const MIN_NAME_LENGTH = 80;
export default class CiTransferCliProgressBar extends SummaryTransferCliProgressBar {
multiProgressBar = CIMultiProgressBar;
minNameLength = MIN_NAME_LENGTH;
}
//# sourceMappingURL=ci-transfer-cli-progress-bar.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"ci-transfer-cli-progress-bar.js","sourceRoot":"","sources":["../../../../../src/download/transfer-visualize/transfer-cli/progress-bars/ci-transfer-cli-progress-bar.ts"],"names":[],"mappings":"AAAA,OAAO,6BAA6B,MAAM,wCAAwC,CAAC;AACnF,OAAO,EAAC,kBAAkB,EAAC,MAAM,4CAA4C,CAAC;AAE9E,MAAM,eAAe,GAAG,EAAE,CAAC;AAE3B,MAAM,CAAC,OAAO,OAAO,wBAAyB,SAAQ,6BAA6B;IACtE,gBAAgB,GAAG,kBAAkB,CAAC;IACtC,aAAa,GAAG,eAAe,CAAC;CAC5C"}

View File

@@ -0,0 +1,9 @@
import BaseTransferCliProgressBar from "./base-transfer-cli-progress-bar.js";
/**
* A class to display transfer progress in the terminal, with a progress bar and other information.
*/
export default class FancyTransferCliProgressBar extends BaseTransferCliProgressBar {
protected renderProgressLine(): string;
protected renderFinishedLine(): string;
protected renderPendingLine(): string;
}

View File

@@ -0,0 +1,125 @@
import chalk from "chalk";
import { PRETTY_MS_OPTIONS } from "../../format-transfer-status.js";
import { renderDataLine } from "../../utils/data-line.js";
import prettyMilliseconds from "pretty-ms";
import sliceAnsi from "slice-ansi";
import stripAnsi from "strip-ansi";
import { DownloadStatus } from "../../../download-engine/download-file/progress-status-file.js";
import BaseTransferCliProgressBar from "./base-transfer-cli-progress-bar.js";
import { STATUS_ICONS } from "../../utils/progressBarIcons.js";
/**
* A class to display transfer progress in the terminal, with a progress bar and other information.
*/
export default class FancyTransferCliProgressBar extends BaseTransferCliProgressBar {
renderProgressLine() {
const { formattedSpeed, formatTransferred, formatTotal, formattedPercentage, percentage } = this.status;
const formattedPercentageWithPadding = formattedPercentage.padEnd(6, " ");
const progressBarText = ` ${formattedPercentageWithPadding} (${formatTransferred}/${formatTotal}) `;
const dimEta = this.getETA(" | ", text => chalk.dim(text));
return renderDataLine([{
type: "status",
fullText: "",
size: 1,
formatter: () => STATUS_ICONS.activeDownload
}, {
type: "spacer",
fullText: " ",
size: " ".length
}, ...this.getNameAndCommentDataParts(), {
type: "spacer",
fullText: " ",
size: " ".length
}, {
type: "progressBar",
fullText: progressBarText,
size: Math.max(progressBarText.length, `100.0% (1024.00MB/${formatTotal})`.length),
flex: 4,
addEndPadding: 4,
maxSize: 40,
formatter(_, size) {
const leftPad = " ".repeat(Math.floor((size - progressBarText.length) / 2));
return renderProgressBar({
barText: leftPad + ` ${chalk.black.bgWhiteBright(formattedPercentageWithPadding)} ${chalk.gray(`(${formatTransferred}/${formatTotal})`)} `,
backgroundText: leftPad + ` ${chalk.yellow.bgGray(formattedPercentageWithPadding)} ${chalk.white(`(${formatTransferred}/${formatTotal})`)} `,
length: size,
loadedPercentage: percentage / 100,
barStyle: chalk.black.bgWhiteBright,
backgroundStyle: chalk.bgGray
});
}
}, {
type: "spacer",
fullText: " ",
size: " ".length
}, {
type: "speed",
fullText: formattedSpeed,
size: Math.max("00.00kB/s".length, formattedSpeed.length)
}, ...dimEta]);
}
renderFinishedLine() {
const wasSuccessful = this.status.downloadStatus === DownloadStatus.Finished;
const { endTime, startTime } = this.status;
const downloadTime = (endTime || Date.now()) - startTime;
const finishedText = wasSuccessful
? `downloaded ${this.status.formatTransferred} in ${prettyMilliseconds(downloadTime, PRETTY_MS_OPTIONS)}`
: `failed downloading after ${prettyMilliseconds(endTime - startTime, PRETTY_MS_OPTIONS)}`;
return renderDataLine([{
type: "status",
fullText: "",
size: 1,
formatter: () => (wasSuccessful
? STATUS_ICONS.done
: STATUS_ICONS.failed)
}, {
type: "spacer",
fullText: " ",
size: " ".length,
formatter: (text) => text
}, ...this.getNameAndCommentDataParts(), {
type: "spacer",
fullText: " ",
size: " ".length,
formatter: (text) => text
}, {
type: "description",
fullText: finishedText,
size: finishedText.length,
formatter: (text) => chalk.dim(text)
}]);
}
renderPendingLine() {
const pendingText = `will download ${this.status.formatTotal}`;
return renderDataLine([{
type: "status",
fullText: "",
size: 1,
formatter: () => STATUS_ICONS.pending
}, {
type: "spacer",
fullText: " ",
size: " ".length,
formatter: (text) => text
}, ...this.getNameAndCommentDataParts(), {
type: "spacer",
fullText: " ",
size: " ".length,
formatter: (text) => text
}, {
type: "description",
fullText: pendingText,
size: pendingText.length,
formatter: (text) => chalk.dim(text)
}]);
}
}
function renderProgressBar({ barText, backgroundText, length, loadedPercentage, barStyle, backgroundStyle }) {
const barChars = Math.floor(length * loadedPercentage);
const backgroundChars = length - barChars;
const slicedBarText = sliceAnsi(barText, 0, barChars);
const paddedBarText = slicedBarText + " ".repeat(barChars - stripAnsi(slicedBarText).length);
const slicedBackgroundText = sliceAnsi(backgroundText, barChars, barChars + backgroundChars);
const paddedBackgroundText = slicedBackgroundText + " ".repeat(backgroundChars - stripAnsi(slicedBackgroundText).length);
return barStyle(paddedBarText) + backgroundStyle(paddedBackgroundText);
}
//# sourceMappingURL=fancy-transfer-cli-progress-bar.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"fancy-transfer-cli-progress-bar.js","sourceRoot":"","sources":["../../../../../src/download/transfer-visualize/transfer-cli/progress-bars/fancy-transfer-cli-progress-bar.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAC,iBAAiB,EAAC,MAAM,iCAAiC,CAAC;AAClE,OAAO,EAAW,cAAc,EAAC,MAAM,0BAA0B,CAAC;AAClE,OAAO,kBAAkB,MAAM,WAAW,CAAC;AAC3C,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,EAAC,cAAc,EAAC,MAAM,gEAAgE,CAAC;AAC9F,OAAO,0BAA0B,MAAM,qCAAqC,CAAC;AAC7E,OAAO,EAAC,YAAY,EAAC,MAAM,iCAAiC,CAAC;AAE7D;;GAEG;AACH,MAAM,CAAC,OAAO,OAA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AAO,QAAQ,CAAC,aAAa,CAAC,GAAG,eAAe,CAAC,oBAAoB,CAAC,CAAC;AAC3E,CAAC"}

View File

@@ -0,0 +1,9 @@
import { SummaryMultiProgressBar } from "../multiProgressBars/SummaryMultiProgressBar.js";
import FancyTransferCliProgressBar from "./fancy-transfer-cli-progress-bar.js";
export default class SummaryTransferCliProgressBar extends FancyTransferCliProgressBar {
multiProgressBar: typeof SummaryMultiProgressBar;
switchTransferToIcon(): string;
getSpinnerText(): string;
renderProgressLine(): string;
protected renderDownloadSequence(): string;
}

View File

@@ -0,0 +1,103 @@
import chalk from "chalk";
import { SummaryMultiProgressBar } from "../multiProgressBars/SummaryMultiProgressBar.js";
import { renderDataLine } from "../../utils/data-line.js";
import FancyTransferCliProgressBar from "./fancy-transfer-cli-progress-bar.js";
import { STATUS_ICONS } from "../../utils/progressBarIcons.js";
import { DownloadFlags } from "../../../download-engine/download-file/progress-status-file.js";
export default class SummaryTransferCliProgressBar extends FancyTransferCliProgressBar {
multiProgressBar = SummaryMultiProgressBar;
switchTransferToIcon() {
switch (this.status.transferAction) {
case "Downloading":
return "↓";
case "Copying":
return "→";
}
return this.status.transferAction;
}
getSpinnerText() {
return STATUS_ICONS.pending;
}
renderProgressLine() {
if (this.status.downloadFlags.includes(DownloadFlags.DownloadSequence)) {
return this.renderDownloadSequence();
}
const pendingText = `downloading ${this.status.formatTotal}`;
return renderDataLine([{
type: "status",
fullText: "",
size: 1,
formatter: () => STATUS_ICONS.activeDownload
}, {
type: "spacer",
fullText: " ",
size: " ".length
}, ...this.getNameAndCommentDataParts(), {
type: "spacer",
fullText: " ",
size: " ".length
}, {
type: "description",
fullText: pendingText,
size: pendingText.length,
formatter: (text) => chalk.dim(text)
}]);
}
renderDownloadSequence() {
const { formatTransferredOfTotal, formattedSpeed, comment, formattedPercentage } = this.status;
const progressBar = `(${formatTransferredOfTotal})`;
return renderDataLine([
{
type: "status",
fullText: "",
size: 1,
formatter: () => chalk.cyan(this.switchTransferToIcon())
},
{
type: "spacer",
fullText: " ",
size: " ".length
},
{
type: "percentage",
fullText: formattedPercentage,
size: 6,
formatter: (text) => text
},
{
type: "spacer",
fullText: " ",
size: " ".length
},
{
type: "progressBar",
fullText: progressBar,
size: progressBar.length
},
{
type: "spacer",
fullText: " | ",
size: " | ".length,
formatter: (text) => chalk.dim(text)
},
{
type: "nameComment",
fullText: comment || "",
size: (comment || "").length
},
{
type: "spacer",
fullText: " | ",
size: " | ".length,
formatter: (text) => chalk.dim(text)
},
{
type: "speed",
fullText: formattedSpeed,
size: formattedSpeed.length
},
...this.getETA(" | ")
]);
}
}
//# sourceMappingURL=summary-transfer-cli-progress-bar.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"summary-transfer-cli-progress-bar.js","sourceRoot":"","sources":["../../../../../src/download/transfer-visualize/transfer-cli/progress-bars/summary-transfer-cli-progress-bar.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAC,uBAAuB,EAAC,MAAM,iDAAiD,CAAC;AACxF,OAAO,EAAC,cAAc,EAAC,MAAM,0BAA0B,CAAC;AACxD,OAAO,2BAA2B,MAAM,sCAAsC,CAAC;AAC/E,OAAO,EAAC,YAAY,EAAC,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EAAC,aAAa,EAAC,MAAM,gEAAgE,CAAC;AAG7F,MAAM,CAAC,OAAO,OAAO,6BAA8B,SAAQ,2BAA2B;IACzE,gBAAgB,GAAG,uBAAuB,CAAC;IAEpD,oBAAoB;QAChB,QAAQ,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC;YACjC,KAAK,aAAa;gBACd,OAAO,GAAG,CAAC;YACf,KAAK,SAAS;gBACV,OAAO,GAAG,CAAC;QACnB,CAAC;QAED,OAAO,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC;IACtC,CAAC;IAEQ,cAAc;QACnB,OAAO,YAAY,CAAC,OAAO,CAAC;IAChC,CAAC;IAEQ,kBAAk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I,IAAI,EAAE,QAAQ;gBACd,QAAQ,EAAE,GAAG;gBACb,IAAI,EAAE,GAAG,CAAC,MAAM;aACnB;YACD;gBACI,IAAI,EAAE,YAAY;gBAClB,QAAQ,EAAE,mBAAmB;gBAC7B,IAAI,EAAE,CAAC;gBACP,SAAS,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI;aAC5B;YACD;gBACI,IAAI,EAAE,QAAQ;gBACd,QAAQ,EAAE,GAAG;gBACb,IAAI,EAAE,GAAG,CAAC,MAAM;aACnB;YACD;gBACI,IAAI,EAAE,aAAa;gBACnB,QAAQ,EAAE,WAAW;gBACrB,IAAI,EAAE,WAAW,CAAC,MAAM;aAC3B;YACD;gBACI,IAAI,EAAE,QAAQ;gBACd,QAAQ,EAAE,KAAK;gBACf,IAAI,EAAE,KAAK,CAAC,MAAM;gBAClB,SAAS,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC;aACvC;YACD;gBACI,IAAI,EAAE,aAAa;gBACnB,QAAQ,EAAE,OAAO,IAAI,EAAE;gBACvB,IAAI,EAAE,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,MAAM;aAC/B;YACD;gBACI,IAAI,EAAE,QAAQ;gBACd,QAAQ,EAAE,KAAK;gBACf,IAAI,EAAE,KAAK,CAAC,MAAM;gBAClB,SAAS,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC;aACvC;YACD;gBACI,IAAI,EAAE,OAAO;gBACb,QAAQ,EAAE,cAAc;gBACxB,IAAI,EAAE,cAAc,CAAC,MAAM;aAC9B;YACD,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;SACxB,CAAC,CAAC;IACP,CAAC;CACJ"}

View File

@@ -0,0 +1,3 @@
import BaseTransferCliProgressBar, { BaseCliOptions } from "./base-transfer-cli-progress-bar.js";
export type AvailableCLIProgressStyle = "basic" | "fancy" | "ci" | "summary" | "auto";
export default function switchCliProgressStyle(cliStyle: AvailableCLIProgressStyle, options: BaseCliOptions): BaseTransferCliProgressBar;

View File

@@ -0,0 +1,27 @@
import BaseTransferCliProgressBar from "./base-transfer-cli-progress-bar.js";
import FancyTransferCliProgressBar from "./fancy-transfer-cli-progress-bar.js";
import SummaryTransferCliProgressBar from "./summary-transfer-cli-progress-bar.js";
import ci from "ci-info";
import CiTransferCliProgressBar from "./ci-transfer-cli-progress-bar.js";
export default function switchCliProgressStyle(cliStyle, options) {
switch (cliStyle) {
case "basic":
return new BaseTransferCliProgressBar(options);
case "fancy":
return new FancyTransferCliProgressBar(options);
case "summary":
return new SummaryTransferCliProgressBar(options);
case "ci":
return new CiTransferCliProgressBar(options);
case "auto":
if (ci.isCI || process.env.IPULL_USE_CI_STYLE) {
return switchCliProgressStyle("ci", options);
}
else {
return switchCliProgressStyle("fancy", options);
}
}
void cliStyle;
throw new Error(`Unknown CLI progress style: ${cliStyle}`);
}
//# sourceMappingURL=switch-cli-progress-style.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"switch-cli-progress-style.js","sourceRoot":"","sources":["../../../../../src/download/transfer-visualize/transfer-cli/progress-bars/switch-cli-progress-style.ts"],"names":[],"mappings":"AAAA,OAAO,0BAA4C,MAAM,qCAAqC,CAAC;AAC/F,OAAO,2BAA2B,MAAM,sCAAsC,CAAC;AAC/E,OAAO,6BAA6B,MAAM,wCAAwC,CAAC;AACnF,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,wBAAwB,MAAM,mCAAmC,CAAC;AAIzE,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAAC,QAAmC,EAAE,OAAuB;IACvG,QAAQ,QAAQ,EAAE,CAAC;QACf,KAAK,OAAO;YACR,OAAO,IAAI,0BAA0B,CAAC,OAAO,CAAC,CAAC;QAEnD,KAAK,OAAO;YACR,OAAO,IAAI,2BAA2B,CAAC,OAAO,CAAC,CAAC;QAEpD,KAAK,SAAS;YACV,OAAO,IAAI,6BAA6B,CAAC,OAAO,CAAC,CAAC;QAEtD,KAAK,IAAI;YACL,OAAO,IAAI,wBAAwB,CAAC,OAAO,CAAC,CAAC;QAEjD,KAAK,MAAM;YACP,IAAI,EAAE,CAAC,IAAI,IAAI,OAAO,CAAC,GAAG,CAAC,kBAAkB,EAAE,CAAC;gBAC5C,OAAO,sBAAsB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;YACjD,CAAC;iBAAM,CAAC;gBACJ,OAAO,sBAAsB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YACpD,CAAC;IACT,CAAC;IAED,KAAM,QAAyB,CAAC;IAChC,MAAM,IAAI,KAAK,CAAC,+BAA+B,QAAQ,EAAE,CAAC,CAAC;AAC/D,CAAC"}

View File

@@ -0,0 +1,42 @@
import UpdateManager from "stdout-update";
import { TransferCliProgressBar } from "./progress-bars/base-transfer-cli-progress-bar.js";
import cliSpinners from "cli-spinners";
import CliSpinnersLoadingAnimation from "./loading-animation/cli-spinners-loading-animation.js";
import { FormattedStatus } from "../format-transfer-status.js";
import { BaseMultiProgressBar } from "./multiProgressBars/BaseMultiProgressBar.js";
export type TransferCliOptions = {
action?: string;
name?: string;
maxViewDownloads: number;
truncateName: boolean | number;
debounceWait: number;
maxDebounceWait: number;
createProgressBar: TransferCliProgressBar;
createMultiProgressBar: typeof BaseMultiProgressBar;
loadingAnimation: cliSpinners.SpinnerName;
loadingText?: string;
};
export declare const DEFAULT_TRANSFER_CLI_OPTIONS: TransferCliOptions;
export declare enum CLI_LEVEL {
LOW = 0,
HIGH = 2
}
export default class TransferCli {
static activeCLILevel: CLI_LEVEL;
readonly loadingAnimation: CliSpinnersLoadingAnimation;
protected options: TransferCliOptions;
protected stdoutManager: UpdateManager;
protected myCLILevel: number;
protected latestProgress: [FormattedStatus[], FormattedStatus];
private _cliStopped;
private readonly _updateStatuesDebounce;
private _multiProgressBar;
private _isFirstPrint;
constructor(options: Partial<TransferCliOptions>, myCLILevel?: CLI_LEVEL);
start(): void;
stop(): void;
private _processExit;
updateStatues(statues: FormattedStatus[], oneStatus: FormattedStatus): void;
private _updateStatues;
protected _logUpdate(text: string): void;
}

View File

@@ -0,0 +1,99 @@
import UpdateManager from "stdout-update";
import debounce from "lodash.debounce";
import cliSpinners from "cli-spinners";
import CliSpinnersLoadingAnimation from "./loading-animation/cli-spinners-loading-animation.js";
import switchCliProgressStyle from "./progress-bars/switch-cli-progress-style.js";
import { BaseMultiProgressBar } from "./multiProgressBars/BaseMultiProgressBar.js";
export const DEFAULT_TRANSFER_CLI_OPTIONS = {
maxViewDownloads: 10,
truncateName: true,
debounceWait: 20,
maxDebounceWait: process.platform === "win32" ? 500 : 100,
createProgressBar: switchCliProgressStyle("auto", { truncateName: true }),
loadingAnimation: "dots",
loadingText: "Gathering information",
createMultiProgressBar: BaseMultiProgressBar
};
export var CLI_LEVEL;
(function (CLI_LEVEL) {
CLI_LEVEL[CLI_LEVEL["LOW"] = 0] = "LOW";
CLI_LEVEL[CLI_LEVEL["HIGH"] = 2] = "HIGH";
})(CLI_LEVEL || (CLI_LEVEL = {}));
export default class TransferCli {
static activeCLILevel = CLI_LEVEL.LOW;
loadingAnimation;
options;
stdoutManager = UpdateManager.getInstance();
myCLILevel;
latestProgress = null;
_cliStopped = true;
_updateStatuesDebounce;
_multiProgressBar;
_isFirstPrint = true;
constructor(options, myCLILevel = CLI_LEVEL.LOW) {
TransferCli.activeCLILevel = this.myCLILevel = myCLILevel;
this.options = { ...DEFAULT_TRANSFER_CLI_OPTIONS, ...options };
this._multiProgressBar = new this.options.createProgressBar.multiProgressBar(this.options);
const maxDebounceWait = this._multiProgressBar.updateIntervalMs || this.options.maxDebounceWait;
this._updateStatuesDebounce = debounce(this._updateStatues.bind(this), maxDebounceWait, {
maxWait: maxDebounceWait
});
this.loadingAnimation = new CliSpinnersLoadingAnimation(cliSpinners[this.options.loadingAnimation], {
loadingText: this.options.loadingText,
updateIntervalMs: this._multiProgressBar.updateIntervalMs,
logType: this._multiProgressBar.printType
});
this._processExit = this._processExit.bind(this);
}
start() {
if (this.myCLILevel !== TransferCli.activeCLILevel)
return;
this._cliStopped = false;
if (this._multiProgressBar.printType === "update") {
this.stdoutManager.hook();
}
process.on("SIGINT", this._processExit);
}
stop() {
if (this._cliStopped || this.myCLILevel !== TransferCli.activeCLILevel)
return;
this._updateStatues();
this._cliStopped = true;
if (this._multiProgressBar.printType === "update") {
this.stdoutManager.unhook(false);
}
process.off("SIGINT", this._processExit);
}
_processExit() {
this.stop();
process.exit(0);
}
updateStatues(statues, oneStatus) {
this.latestProgress = [statues, oneStatus];
if (this._isFirstPrint) {
this._isFirstPrint = false;
this._updateStatues();
}
else {
this._updateStatuesDebounce();
}
}
_updateStatues() {
if (this._cliStopped || this.myCLILevel !== TransferCli.activeCLILevel) {
return; // Do not update if there is a higher level CLI, meaning that this CLI is sub-CLI
}
const printLog = this._multiProgressBar.createMultiProgressBar(...this.latestProgress);
if (printLog) {
this._logUpdate(printLog);
}
}
_logUpdate(text) {
if (this._multiProgressBar.printType === "update") {
this.stdoutManager.update(text.split("\n"));
}
else {
console.log(text);
}
}
}
//# sourceMappingURL=transfer-cli.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"transfer-cli.js","sourceRoot":"","sources":["../../../../src/download/transfer-visualize/transfer-cli/transfer-cli.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,eAAe,CAAC;AAC1C,OAAO,QAAQ,MAAM,iBAAiB,CAAC;AAEvC,OAAO,WAAW,MAAM,cAAc,CAAC;AACvC,OAAO,2BAA2B,MAAM,uDAAuD,CAAC;AAEhG,OAAO,sBAAsB,MAAM,8CAA8C,CAAC;AAClF,OAAO,EAAC,oBAAoB,EAAC,MAAM,6CAA6C,CAAC;AAejF,MAAM,CAAC,MAAM,4BAA4B,GAAuB;IAC5D,gBAAgB,EAAE,EAAE;IACpB,YAAY,EAAE,IAAI;IAClB,YAAY,EAAE,EAAE;IAChB,eAAe,EAAE,OAAO,CAAC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