包详细信息

ember-cli-deploy-progress

ember-cli-deploy125.1kMIT1.3.0

Flexible ascii progress bar (ember-cli-deploy fork incorporating cursor feature)

cli, progress

自述文件

Flexible ascii progress bar.

Installation

$ npm install progress

Usage

First we create a ProgressBar, giving it a format string as well as the total, telling the progress bar when it will be considered complete. After that all we need to do is tick() appropriately.

var ProgressBar = require('progress');

var bar = new ProgressBar(':bar', { total: 10 });
var timer = setInterval(function () {
  bar.tick();
  if (bar.complete) {
    console.log('\ncomplete\n');
    clearInterval(timer);
  }
}, 100);

Options

These are keys in the options object you can pass to the progress bar along with total as seen in the example above.

  • total total number of ticks to complete
  • width the displayed width of the progress bar defaulting to total
  • stream the output stream defaulting to stderr
  • complete completion character defaulting to "="
  • cursor last completion character defaulting to complete
  • incomplete incomplete character defaulting to "-"
  • renderThrottle minimum time between updates in milliseconds defaulting to 16
  • clear option to clear the bar on completion defaulting to false
  • callback optional function to call when the progress bar completes

Tokens

These are tokens you can use in the format of your progress bar.

  • :bar the progress bar itself
  • :current current tick number
  • :total total ticks
  • :elapsed time elapsed in seconds
  • :percent completion percentage
  • :eta estimated completion time in seconds

Custom Tokens

You can define custom tokens by adding a {'name': value} object parameter to your method (tick(), update(), etc.) calls.

var bar = new ProgressBar(':current: :token1 :token2', { total: 3 })
bar.tick({
  'token1': "Hello",
  'token2': "World!\n"
})
bar.tick(2, {
  'token1': "Goodbye",
  'token2': "World!"
})

The above example would result in the output below.

1: Hello World!
3: Goodbye World!

Examples

Download

In our download example each tick has a variable influence, so we pass the chunk length which adjusts the progress bar appropriately relative to the total length.

var ProgressBar = require('../');
var https = require('https');

var req = https.request({
  host: 'download.github.com',
  port: 443,
  path: '/visionmedia-node-jscoverage-0d4608a.zip'
});

req.on('response', function(res){
  var len = parseInt(res.headers['content-length'], 10);

  console.log();
  var bar = new ProgressBar('  downloading [:bar] :percent :etas', {
    complete: '=',
    cursor: '>',
    incomplete: ' ',
    width: 20,
    total: len
  });

  res.on('data', function (chunk) {
    bar.tick(chunk.length);
  });

  res.on('end', function () {
    console.log('\n');
  });
});

req.end();

The above example result in a progress bar like the one below.

downloading [====>             ] 29% 3.7s

You can see more examples in the examples folder.

License

MIT

更新日志

1.1.7 / 2014-06-30

  • fixed a bug that occurs when a progress bar attempts to draw itself on a console with very few columns

1.1.6 / 2014-06-16

  • now prevents progress bar from exceeding TTY width by limiting its width to the with of the TTY

1.1.5 / 2014-03-25

  • updated documentation and various other repo maintenance
  • updated makefile to run examples with make
  • removed dependency on readline module

1.1.4 / 2014-03-14

  • now supports streams, for example output progress bar to stderr, while piping stdout
  • increases performance and flicker by remembering the last drawn progress bar

1.1.3 / 2013-12-31

  • fixes a bug where bar would bug when initializing
  • allows to pass updated tokens when ticking or updating the bar
  • fixes a bug where the bar would throw if skipping to far

1.1.2 / 2013-10-17

  • lets you pass an fmt and a total instead of an options object

1.1.0 / 2013-09-18

  • eta and elapsed tokens default to 0.0 instead of ?.?
  • better JSDocs
  • added back and forth example
  • added method to update the progress bar to a specific percentage
  • added an option to hide the bar on completion

1.0.1 / 2013-08-07

  • on os x readline now works, reverting the terminal hack

1.0.0 / 2013-06-18

  • remove .version
  • merge pull request #15 from davglass/readline-osx
  • on OSX revert back to terminal hack to avoid a readline bug

0.1.0 / 2012-09-19

  • fixed logic bug that caused bar to jump one extra space at the end [davglass]
  • working with readline impl, even on Windows [davglass]
  • using readline instead of the \r hack [davglass]

0.0.5 / 2012-08-07

  • add ability to tick by zero chunks - tick(0)
  • fix ETA. Closes #4 [lwille]

0.0.4 / 2011-11-14

  • allow more recent versions of node

0.0.3 / 2011-04-20

  • changed; erase the line when complete

0.0.2 / 2011-04-20

  • added custom tokens support
  • fixed; clear line before writing

0.0.1 / 2010-01-03

  • initial release