mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-18 12:08:59 +08:00
Add declarations for cli-progress package (#25661)
* Add declarations for cli-progress package * Add missing property * Close comment * Fix lint failure
This commit is contained in:
committed by
Sheetal Nandi
parent
9cd7841a26
commit
fd28954b07
92
types/cli-progress/cli-progress-tests.ts
Normal file
92
types/cli-progress/cli-progress-tests.ts
Normal file
@@ -0,0 +1,92 @@
|
||||
import progress = require('cli-progress');
|
||||
|
||||
function test0() {
|
||||
// Usage
|
||||
// Multiple examples are available e.g.example.js - just try it $ node example.js
|
||||
|
||||
const _cliProgress = require('cli-progress');
|
||||
|
||||
// create a new progress bar instance and use shades_classic theme
|
||||
const bar1 = new _cliProgress.Bar({}, _cliProgress.Presets.shades_classic);
|
||||
|
||||
// start the progress bar with a total value of 200 and start value of 0
|
||||
bar1.start(200, 0);
|
||||
|
||||
// update the current value in your application..
|
||||
bar1.update(100);
|
||||
|
||||
// stop the progress bar
|
||||
bar1.stop();
|
||||
}
|
||||
|
||||
function test1() {
|
||||
// Examples
|
||||
// Example 1 - Set Options
|
||||
|
||||
// change the progress characters
|
||||
// set fps limit to 5
|
||||
// change the output stream and barsize
|
||||
const bar = new progress.Bar({
|
||||
barCompleteChar: '#',
|
||||
barIncompleteChar: '.',
|
||||
fps: 5,
|
||||
stream: process.stdout,
|
||||
barsize: 65
|
||||
});
|
||||
}
|
||||
|
||||
function test2() {
|
||||
// Example 2 - Change Styles defined by Preset
|
||||
// uee shades preset
|
||||
// change the barsize
|
||||
const bar = new progress.Bar({
|
||||
barsize: 65
|
||||
}, progress.Presets.shades_grey);
|
||||
}
|
||||
|
||||
function test3() {
|
||||
// Example 3 - Custom Payload
|
||||
// create new progress bar with custom token "speed"
|
||||
const bar = new progress.Bar({
|
||||
format: 'progress [{bar}] {percentage}% | ETA: {eta}s | {value}/{total} | Speed: {speed} kbit'
|
||||
});
|
||||
|
||||
// initialize the bar - set payload token "speed" with the default value "N/A"
|
||||
bar.start(200, 0, {
|
||||
speed: "N/A"
|
||||
});
|
||||
|
||||
// some code/update loop
|
||||
// ...
|
||||
|
||||
// update bar value. set custom token "speed" to 125
|
||||
bar.update(5, {
|
||||
speed: '125'
|
||||
});
|
||||
|
||||
// process finished
|
||||
bar.stop();
|
||||
}
|
||||
|
||||
function test4() {
|
||||
// Example 4 - Custom Presets
|
||||
// File mypreset.js
|
||||
|
||||
const _colors = require('colors');
|
||||
|
||||
module.exports = {
|
||||
format: _colors.red(' {bar}') + ' {percentage}% | ETA: {eta}s | {value}/{total} | Speed: {speed} kbit',
|
||||
barCompleteChar: '\u2588',
|
||||
barIncompleteChar: '\u2591'
|
||||
};
|
||||
}
|
||||
|
||||
function test5() {
|
||||
// Application
|
||||
|
||||
const _mypreset = require('./mypreset.js');
|
||||
|
||||
const bar = new progress.Bar({
|
||||
barsize: 65
|
||||
}, _mypreset);
|
||||
}
|
||||
114
types/cli-progress/index.d.ts
vendored
Normal file
114
types/cli-progress/index.d.ts
vendored
Normal file
@@ -0,0 +1,114 @@
|
||||
// Type definitions for cli-progress 1.8
|
||||
// Project: https://github.com/AndiDittrich/Node.CLI-Progress
|
||||
// Definitions by: My Self <https://github.com/mhegazy>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.2
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
export interface Options {
|
||||
/**
|
||||
* progress bar output format.
|
||||
* The progressbar can be customized by using the following build-in placeholders. They can be combined in any order.
|
||||
* {bar} - the progress bar, customizable by the options barsize, barCompleteString and barIncompleteString
|
||||
* {percentage} - the current progress in percent (0-100)
|
||||
* {total} - the end value
|
||||
* {value} - the current value set by last update() call
|
||||
* {eta} - expected time of accomplishment in seconds
|
||||
* {duration} - elapsed time in seconds
|
||||
* {eta_formatted} - expected time of accomplishment formatted into appropriate units
|
||||
* {duration_formatted} - elapsed time formatted into appropriate units
|
||||
*
|
||||
* Example:
|
||||
* progress [{bar}] {percentage}% | ETA: {eta}s | {value}/{total}
|
||||
* is rendered as
|
||||
* progress [========================================] 100% | ETA: 0s | 200/200
|
||||
*/
|
||||
format?: string;
|
||||
|
||||
/** the maximum update rate (default: 10) */
|
||||
fps?: number;
|
||||
|
||||
/** output stream to use (default: process.stderr) */
|
||||
stream?: NodeJS.WritableStream;
|
||||
|
||||
/** automatically call stop() when the value reaches the total (default: false) */
|
||||
stopOnComplete?: boolean;
|
||||
|
||||
/** clear the progress bar on complete / stop() call (default: false) */
|
||||
clearOnComplete?: boolean;
|
||||
|
||||
/** the length of the progress bar in chars (default: 40) */
|
||||
barsize?: number;
|
||||
|
||||
/** character to use as "complete" indicator in the bar (default: "=") */
|
||||
barCompleteString?: string;
|
||||
|
||||
/** character to use as "incomplete" indicator in the bar (default: "-") */
|
||||
barIncompleteString?: string;
|
||||
|
||||
/** character to use as "complete" indicator in the bar (default: "=") */
|
||||
barCompleteChar?: string;
|
||||
|
||||
/** character to use as "incomplete" indicator in the bar (default: "-") */
|
||||
barIncompleteChar?: string;
|
||||
|
||||
/** hide the cursor during progress operation; restored on complete (default: false) */
|
||||
hideCursor?: boolean;
|
||||
|
||||
/** number of updates with which to calculate the eta; higher numbers give a more stable eta (default: 10) */
|
||||
etaBuffer?: number;
|
||||
|
||||
/** disable line wrapping (default: false) - pass null to keep terminal settings; pass true to trim the output to terminal width */
|
||||
linewrap?: boolean | null;
|
||||
}
|
||||
|
||||
export interface Preset {
|
||||
barCompleteChar: string;
|
||||
barIncompleteChar: string;
|
||||
format: string;
|
||||
}
|
||||
|
||||
export class Bar {
|
||||
/** Initialize a new Progress bar. An instance can be used multiple times! it's not required to re-create it! */
|
||||
constructor(opt: Options, preset?: Preset);
|
||||
|
||||
calculateETA(): void;
|
||||
|
||||
formatTime(t: any, roundToMultipleOf: any): any;
|
||||
|
||||
getTotal(): any;
|
||||
|
||||
/** Increases the current progress value by a specified amount (default +1). Update payload optionally */
|
||||
increment(step: number, payload?: object): void;
|
||||
|
||||
render(): void;
|
||||
|
||||
/** Sets the total progress value while progressbar is active. Especially useful handling dynamic tasks. */
|
||||
setTotal(total: number): void;
|
||||
|
||||
/** Starts the progress bar and set the total and initial value */
|
||||
start(total: number, startValue: number, payload?: object): void;
|
||||
|
||||
/** Stops the progress bar and go to next line */
|
||||
stop(): void;
|
||||
|
||||
stopTimer(): void;
|
||||
|
||||
/** Sets the current progress value and optionally the payload with values of custom tokens as a second parameter */
|
||||
update(current: number, payload?: object): void;
|
||||
}
|
||||
|
||||
export const Presets: {
|
||||
/** Styles as of cli-progress v1.3.0 */
|
||||
legacy: Preset;
|
||||
|
||||
/** Unicode Rectangles */
|
||||
rect: Preset;
|
||||
|
||||
/** Unicode background shades are used for the bar */
|
||||
shades_classic: Preset;
|
||||
|
||||
/** Unicode background shades with grey bar */
|
||||
shades_grey: Preset;
|
||||
};
|
||||
23
types/cli-progress/tsconfig.json
Normal file
23
types/cli-progress/tsconfig.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"strictFunctionTypes": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"cli-progress-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/cli-progress/tslint.json
Normal file
1
types/cli-progress/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user