Merge pull request #31379 from bkendall/bk-fix-progress

Fix `progress` and `multi-progress`
This commit is contained in:
Nathan Shively-Sanders
2018-12-14 11:12:27 -08:00
committed by GitHub
4 changed files with 115 additions and 93 deletions
+9 -3
View File
@@ -5,10 +5,14 @@
/// <reference types="node"/>
import ProgressBar, { ProgressBarOptions } from 'progress';
import * as ProgressBar from 'progress';
import { Stream } from 'stream';
export default class MultiProgress {
export as namespace MultiProgress;
export = MultiProgress;
declare class MultiProgress {
/**
* Create a new @see MultiProgress with the given stream, or stderr by default
* @param stream A stream to write the progress bars to
@@ -18,7 +22,7 @@ export default class MultiProgress {
/**
* Add a new bar
*/
newBar: (format: string, options: ProgressBarOptions) => ProgressBar;
newBar: (format: string, options: ProgressBar.ProgressBarOptions) => ProgressBar;
/**
* Close all bars
@@ -40,3 +44,5 @@ export default class MultiProgress {
*/
update: (index: number, value: number, options?: any) => void;
}
declare namespace MultiProgress {}
+1 -1
View File
@@ -3,7 +3,7 @@
*/
// require the library
import MultiProgress from 'multi-progress';
import * as MultiProgress from 'multi-progress';
// spawn an instance with the optional stream to write to
// use of `new` is optional
+72 -62
View File
@@ -1,67 +1,13 @@
// Type definitions for node-progress v2.0.0
// Project: https://github.com/tj/node-progress
// Type definitions for node-progress 2.0
// Project: https://github.com/visionmedia/node-progress
// Definitions by: Sebastian Lenz <https://github.com/sebastian-lenz>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node"/>
export as namespace ProgressBar;
/**
* These are keys in the options object you can pass to the progress bar along with total as seen in the example above.
*/
export interface ProgressBarOptions {
/**
* Total number of ticks to complete.
*/
total: number;
/**
* current completed index
*/
curr?: number;
/**
* head character defaulting to complete character
*/
head?: string;
/**
* The displayed width of the progress bar defaulting to total.
*/
width?: number;
/**
* minimum time between updates in milliseconds defaulting to 16
*/
renderThrottle?: number;
/**
* The output stream defaulting to stderr.
*/
stream?: NodeJS.WritableStream;
/**
* Completion character defaulting to "=".
*/
complete?: string;
/**
* Incomplete character defaulting to "-".
*/
incomplete?: string;
/**
* Option to clear the bar on completion defaulting to false.
*/
clear?: boolean;
/**
* Optional function to call when the progress bar completes.
*/
callback?: Function;
}
export = ProgressBar;
/**
* Flexible ascii progress bar.
@@ -90,7 +36,7 @@ declare class ProgressBar {
* - `:eta` eta in seconds
*/
constructor(format: string, total: number);
constructor(format: string, options: ProgressBarOptions);
constructor(format: string, options: ProgressBar.ProgressBarOptions);
/**
@@ -135,7 +81,71 @@ declare class ProgressBar {
* Completed status of progress (Boolean)
*/
complete: boolean;
}
declare namespace ProgressBar { }
export default ProgressBar;
/**
* Current tick number.
*/
curr: number;
/**
* Total number of ticks to complete.
*/
total: number;
}
declare namespace ProgressBar {
/**
* These are keys in the options object you can pass to the progress bar along with total as seen in the example above.
*/
interface ProgressBarOptions {
/**
* Total number of ticks to complete.
*/
total: number;
/**
* current completed index
*/
curr?: number;
/**
* head character defaulting to complete character
*/
head?: string;
/**
* The displayed width of the progress bar defaulting to total.
*/
width?: number;
/**
* minimum time between updates in milliseconds defaulting to 16
*/
renderThrottle?: number;
/**
* The output stream defaulting to stderr.
*/
stream?: NodeJS.WritableStream;
/**
* Completion character defaulting to "=".
*/
complete?: string;
/**
* Incomplete character defaulting to "-".
*/
incomplete?: string;
/**
* Option to clear the bar on completion defaulting to false.
*/
clear?: boolean;
/**
* Optional function to call when the progress bar completes.
*/
callback?: Function;
}
}
+33 -27
View File
@@ -1,42 +1,48 @@
var ProgressBar = require('progress');
import * as ProgressBar from 'progress';
/**
* Usage example from https://github.com/tj/node-progress
* Usage example from https://github.com/visionmedia/node-progress
* (in Typescript)
*/
var bar = new ProgressBar(':bar', { total: 10 });
var timer = setInterval(function () {
bar.tick();
if (bar.complete) {
const usageBar = new ProgressBar(':bar', { total: 10 });
const timer = setInterval(function () {
usageBar.tick();
if (usageBar.complete) {
console.log('\ncomplete\n');
clearInterval(timer);
}
}, 100);
/**
* Custom token example from https://github.com/tj/node-progress
* Custom token example from https://github.com/visionmedia/node-progress
* (in Typescript)
*/
var bar = new ProgressBar(':current: :token1 :token2', { total: 3 });
bar.tick({
'token1': "Hello",
'token2': "World!\n"
});
bar.tick(2, {
'token1': "Goodbye",
'token2': "World!"
});
const list = [
'image01.jpg', 'image02.jpg', 'image03.jpg', 'image04.jpg', 'image05.jpg',
'image06.jpg', 'image07.jpg', 'image08.jpg', 'image09.jpg', 'image10.jpg'
];
const customTokenBar = new ProgressBar(':percent eta: :eta downloading :current/:total :file', {
total: list.length
});
const customInterval = setInterval(function (){
customTokenBar.tick({
'file': list[customTokenBar.curr]
})
if (customTokenBar.complete) {
clearInterval(customInterval)
}
}, 500)
/**
* Interrupt example from https://github.com/visionmedia/node-progress
* (in Typescript)
*/
var bar = new ProgressBar(':bar :current/:total', { total: 10 });
var timer = setInterval(function () {
bar.tick();
if (bar.complete) {
clearInterval(timer);
} else if (bar.curr === 5) {
bar.interrupt('this message appears above the progress bar\ncurrent progress is ' + bar.curr + '/' + bar.total);
const interruptBar = new ProgressBar(':bar :current/:total', { total: 10 });
const interruptTimer = setInterval(function () {
interruptBar.tick();
if (interruptBar.complete) {
clearInterval(interruptTimer);
} else if (interruptBar.curr === 5 || interruptBar.curr === 8) {
interruptBar.interrupt('interrupt: current progress is ' + interruptBar.curr + '/' + interruptBar.total);
}
}, 1000);
}, 1000);