Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cli-progress

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cli-progress - npm Package Compare versions

Comparing version 3.5.0 to 3.6.0

lib/format-bar.js

9

CHANGES.md
## Branch 3.x ##
### 3.6.0 ###
* Added: support for custom time-format function
* Added: support for custom bar-format function
* Added: support for custom value-format function
* Added: auto-padding option to enforce fixed size of values - feature [requested on GitHub](https://github.com/AndiDittrich/Node.CLI-Progress/issues/60)
* Added: `barGlue` option to insert ascii escape sequences (e.g. for colorization) between the bar complete/incomplete elements - feature [requested on GitHub](https://github.com/AndiDittrich/Node.CLI-Progress/issues/53)
* Bugfix: `eta` value can be negative for multibars in case the bar is alredy completed
### 3.5.0 ###

@@ -4,0 +13,0 @@

4

lib/eta.js

@@ -62,2 +62,6 @@

// negative ?
}else if (eta < 0){
this.eta = 0;
}else{

@@ -64,0 +68,0 @@ // assign

58

lib/formatter.js
const _stringWidth = require('string-width');
const _defaultFormatValue = require('./format-value');
const _defaultFormatBar = require('./format-bar');
const _defaultFormatTime = require('./format-time');
// format a number of seconds into hours and minutes as appropriate
function formatTime(t, roundToMultipleOf){
function round(input) {
if (roundToMultipleOf) {
return roundToMultipleOf * Math.round(input / roundToMultipleOf);
} else {
return input
}
}
if (t > 3600) {
return Math.floor(t / 3600) + 'h' + round((t % 3600) / 60) + 'm';
} else if (t > 60) {
return Math.floor(t / 60) + 'm' + round((t % 60)) + 's';
} else if (t > 10) {
return round(t) + 's';
} else {
return t + 's';
}
}
// generic formatter

@@ -29,8 +12,10 @@ module.exports = function defaultFormatter(options, params, payload){

// generate bar string by stripping the pre-rendered strings
let b = options.barCompleteString.substr(0, Math.round(params.progress*options.barsize)) +
options.barIncompleteString.substr(0, Math.round((1.0-params.progress)*options.barsize));
// custom time format set ?
const formatTime = options._formatTime || _defaultFormatTime;
// custom value format set ?
const formatValue = options.formatValue || _defaultFormatValue;
// limit the bar-size (can cause n+1 chars in some numerical situation)
b = b.substr(0, options.barsize);
// custom bar format set ?
const formatBar = options.formatBar || _defaultFormatBar;

@@ -42,17 +27,16 @@ // calculate progress in percent

const elapsedTime = Math.round((Date.now() - params.startTime)/1000);
const elapsedTimef = formatTime(elapsedTime, 1);
// calculate eta
const etaf = formatTime(params.eta, 5);
// merges data from payload and calcuated
const context = Object.assign({}, payload, {
bar: b,
percentage: percentage,
total: params.total,
value: params.value,
eta: params.eta,
eta_formatted: etaf,
duration: elapsedTime,
duration_formatted: elapsedTimef
bar: formatBar(params.progress, options),
percentage: formatValue(percentage, options, 'percentage'),
total: formatValue(params.total, options, 'total'),
value: formatValue(params.value, options, 'value'),
eta: formatValue(params.eta, options, 'eta'),
eta_formatted: formatTime(params.eta, options, 5),
duration: formatValue(elapsedTime, options, 'duration'),
duration_formatted: formatTime(elapsedTime, options, 1)
});

@@ -59,0 +43,0 @@

@@ -51,5 +51,17 @@ // global options storage

// glue sequence (control chars) between bar elements ?
_options.barGlue = mergeOption(opt.barGlue, '');
// the bar format
_options.format = mergeOption(opt.format, 'progress [{bar}] {percentage}% | ETA: {eta}s | {value}/{total}');
// external time-format provided ?
_options.formatTime = mergeOption(opt.formatTime, null);
// external value-format provided ?
_options.formatValue = mergeOption(opt.formatValue, null);
// external bar-format provided ?
_options.formatBar = mergeOption(opt.formatBar, null);
// the number of results to average ETA over

@@ -73,2 +85,8 @@ _options.etaBufferLength = mergeOption(opt.etaBuffer, 10);

// automated padding to fixed width ?
_options.autopadding = mergeOption(opt.autopadding, false);
// autopadding character - empty in case autopadding is disabled
_options.autopaddingChar = _options.autopadding ? mergeOption(opt.autopaddingChar, ' ') : '';
return _options;

@@ -75,0 +93,0 @@ },

{
"name": "cli-progress",
"version": "3.5.0",
"version": "3.6.0",
"description": "easy to use progress-bar for command-line/terminal applications",

@@ -5,0 +5,0 @@ "keywords": [

@@ -228,2 +228,8 @@ [![Build Status](https://travis-ci.org/AndiDittrich/Node.CLI-Progress.svg?branch=master)](https://travis-ci.org/AndiDittrich/Node.CLI-Progress)

- `forceRedraw` (type:boolean) - trigger redraw on every frame even if progress remains the same; can be useful if progress bar gets overwritten by other concurrent writes to the terminal (default: false)
- `barGlue` (type:string) - a "glue" string between the complete and incomplete bar elements used to insert ascii control sequences for colorization (default: empty) - Note: in case you add visible "glue" characters the barsize will be increased by the length of the glue!
- `autopadding` (type: boolean) - add padding chars to formatted time and percentage to force fixed width (default: false) - Note: handled standard format functions!
- `autopaddingChar` (type: string) - the character sequence used for autopadding (default: " ") - Note: due to performance optimizations this value requies a length of 3 identical chars
- `formatBar` (type: function) - a custom bar formatter function which renders the bar-element (default: [format-bar.js](lib/format-bar.js))
- `formatTime` (type: function) - a custom timer formatter function which renders the formatted time elements like `eta_formatted` and `duration-formatted` (default: [format-time.js](lib/format-time.js))
- `formatValue` (type: function) - a custom value formatter function which renders all other values (default: [format-value.js](lib/format-value.js))

@@ -230,0 +236,0 @@ Events

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc