1.0.6 • Published 9 years ago

yapb v1.0.6

Weekly downloads
3
License
MIT
Repository
github
Last release
9 years ago

CLI-Progress

Progress bars, spinners and updating statistics for CLI processes!

Features

  • Progress bar that auto-sizes to the terminal width using window-size
  • Spinner support via cli-spinners
  • Proper support for clearing up after itself
  • Mustache templating support
  • Very simple syntax where any setting can be changed at any time - even the template
  • 'Lazy' initialization of values, you can setup the progress bar before knowing any of the data you will be feeding into it (setting the 'maximum' is usually required by all other progress libraries)
  • Works fully without any 'raw' values - use it purely for spinners or other dynamic text
  • Works in a fully synchronous environment
var progress = require('cli-progress');

var myProgress = progress('{{spinner}} Loading widgets... [{{bar}}] {{percent}}%', {max: 300});

var current = 0;
var tick = function() {
	if (current == 300) { // Stop at 300 ticks
		myProgress.remove();
	} else {
		myProgress.update(++current);
		setTimeout(tick, 50);
	}
};
setTimeout(tick, 50);

See the examples folder for more.

Settings

Settings are simple keys stored in progressBar.settings. You can define your own properties, tokens and templates as needed at any time. See the Mustache documentation for more information.

KeyTypeDefaultDescription
textstring'{{current}} / {{max}} [{{bar}}] {{percent}}%'The template to use when rendering the object
currentnumber0The 'current' progress. This can be any number lower than max
maxnumber100The 'max' progress value. This should always be higher or equal to current
streamStreamprocess.stderrWhat output stream to use
renderFunctionsee codeThe render function used to output the object to the screen. The default version clears the active line and paints the output with the result of format()
clearFunctionsee codeThe function to invoke on any remove() call. The default version resets the current line
widthnumberresult of windowSize.widthThe terminal width. This should be automatically calculated
completeCharstring=The character to use when rendering a progress bar. This character represents the left-most 'done' portion of the bar
incompleteCharstring=The character to use when rendering a progress bar. This character represents the right-most 'not done' portion of the bar
percentFunctionsee codeSimple pre-prepared template function to return a number between 0 - 100 representing the process of current / max * 100
throttlenumber50Restrict redrawing to this many milliseconds. Set this to any falsy value to disable throttling
throttleSyncbooleanfalseSet this to true if the bar needs redrawing in a synchronous environment where tick'd redraws are unavailable
spinnerFunctionsee codeSpinner rendering function. This function is called on each draw phase to return the current spinner
spinnerThemestringdotsThe spinner theme within cli-spinners to use when drawing the spinner
spinnerFramenumber0The current spinner animation frame. This is used by the spinner callback to store its current position
startTimenumberDate.now()Timestamp in milliseconds when the object was created (used to calculate eta)
etaFunctionsee codeThe render function used to calculate and output the estimated completion time using startTime and current as a guide
etaFormatstringautoFormatting for the ETA display. This broadly follows the moment convention. Options: auto, H:M:s.S, H:M:s, M:s.S, M:s, s, s.S

API

update(settings|current value)

Main function to accept optional updated settings or a single new current value. This function will also redraw the object on the screen after update. If you wish to update settings without redrawing use set() instead.

set(settings|current value)

Update the settings or a new current value. Unlike update() this function does not redraw the object. Use update() for that.

remove()

Remove the object from the screen.

format()

Return the current, formatted text representing the object.

updateNow()

Function to force an update, even if its not scheduled (because of throttling).

1.0.6

9 years ago

1.0.5

9 years ago

1.0.4

9 years ago

1.0.3

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago