Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CNAME
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
awesome-progress.ahmadassaf.com
9 changes: 9 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
License: MIT

Copyright (C) 2012 Terra Eclipse, Inc. (http://www.terraeclipse.com), Ahmad Assaf (http://ahmadassaf.com)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
145 changes: 62 additions & 83 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
Pace
====
# awesome-progress

A node.js module that outputs a progress bar and other metrics to the command-line.
It was originally conceived to help measure the 'pace' of long running scripts.
We've used it to optimize scripts that would have taken hours to complete down
to minutes, without having to wait the hours before knowing that the script
could use some optimization.
A node.js module that outputs a progress bar and other metrics to the command-line. It was originally conceived to help measure the 'pace' of long running scripts.

We've used it to optimize scripts that would have taken hours to complete down to minutes, without having to wait the hours before knowing that the script could use some optimization.

![Screenshot with Error Feature](https://s22.postimg.cc/5mdxlrsk1/awesome-progress.gif)

> **Note**: This module is not longer maintained but you are welcome to PR or fork. You might want to check:
> - [ascii-progress - Ascii progress-bar(s) in the terminal](https://github.com/bubkoo/ascii-progress)
> - [node-multimeter - render multiple progress bars at once on the terminal](https://github.com/substack/node-multimeter)

**Installation**

Installation
------------
```
$ npm install pace
```

Example
-------
**Example**

Running the following code:

```js
Expand All @@ -32,20 +35,15 @@ while (count++ < total) {
}
```

Will cause output to your console similar to:
## Usage

### `Pace` object

![Sample progress bar output](https://github.com/cpsubrian/pace/raw/master/screenshot.png)
The module exports a factory function to generate instances of `Pace` objects. So `require('pace')(<options>)` creates an instance of `Pace`, passing `options` to the constructor.

Usage
-----
### `Pace` object ###
The module exports a factory function to generate instances of `Pace` objects.
So `require('pace')(<options>)` creates an instance of `Pace`, passing
`options` to the constructor.
### Options

### Options ###
Options can either be an object literal, or an integer. If its an integer then
it is the same as passing options with only the `total` specified.
Options can either be an object literal, or an integer. If its an integer then it is the same as passing options with only the `total` specified.

```js
require('pace')(100);
Expand All @@ -60,65 +58,46 @@ Supported Options:
* `total` - The total number of operations that _YOUR_ script will execute.
* `maxBurden` - The maximum 'burden' that the progress bar should incur. See more about burden below.
* `showBurden` - Mostly for debugging. Show the current burden / skipped steps with the other metrics.
* `hideFinishMessage` - Hides the message displayed when the progress bar finishes. Default: `False`
* `finishMessage` - Pass a custom message to display when the progress bar finishes. Default: `Finished!`
* `errorMessage` - Pass a custom message to display when a signal error has been passed.

### pace.op([count])

Signal to pace that an operation was completed in your script by calling `pace.op()`.

If you would rather track the progress in your own logic, you can call `pace.op(<count>)` where `<count>` is the current operation interation (for example step # 50 of a 100 step process).

### pace.op({errors: count})

Signal to pace that an error has happened. This will automatically signal a normal `count` increase but will also increase the error counter shown under the progress bar.
**Note:** The errors count can be passed to be more than one, however each error signal triggers one `op()` count.

### pace.total

If your script has a dynamic amount of work to do (for example, depending on the results of previous operation there may be more steps to complete), you can freely change the value of pace.total. Just set the value like: `pace.total = 200`.

### Burden


Depending on how intensive your operations are, calculating, formatting, and printing the progress bar might be much more expensive than the work you are doing. It would be silly if printing a progress bar caused your job to take significantly longer than it would have otherwise. _Pace_ tracks a stat called 'burden', which is basically a percentage of the overall execution time that is being spent inside the progress bar logic itself.

The default `maxBurden` is `0.5`, which translates to `0.5% of the total execution time`. If this low burden is causing you to see progress reported less often than you would prefer, you can raise it to something like `20` (20%) via the `maxBurden` option.

### Examples

The `test/` folder contains some simple test scripts you can run to see the progress bar in action.

## Common Issues

### Multiple writes and wrong progress bar rendering

If you have multiple instances of `pace` running in various parts of your application, from the second run onwards you might notice that the progress bar is not rendered correctly with duplicate output.
This effect is additive for each time `pace` is required with the same stream.

**Cause:** The problem is with `pace` dependency `charm`. In node.js 0.10 the EventEmitter constructor explicitly initializes `this._events`, so going `Charm.prototype = new Stream;` causes all Charm instances to share the same _events property.

**Fix:** Change the `charm` main module file `index.js` and replace `Charm.prototype = new Stream;` with `Charm.prototype = Stream.prototype;`

### pace.op([count]) ###
Signal to pace that an operation was completed in your script by calling
`pace.op()`.

If you would rather track the progress in your own logic, you can call
`pace.op(<count>)` where `<count>` is the current operation interation
(for example step # 50 of a 100 step process).

### pace.total ###
If your script has a dynamic amount of work to do (for example, depending on the
results of previous operation there may be more steps to complete), you can
freely change the value of pace.total. Just set the value like: `pace.total = 200`.

Burden
------
Depending on how intensive your operations are, calculating, formatting, and
printing the progress bar might be much more expensive than the work you
are doing. It would be silly if printing a progress bar caused your
job to take significantly longer than it would have otherwise. _Pace_ tracks
a stat called 'burden', which is basically a percentage of the overall
execution time that is being spent inside the progress bar logic itself.

The default `maxBurden` is `0.5`, which translates to `0.5% of the total execution
time`. If this low burden is causing you to see progress reported less
often than you would prefer, you can raise it to something like `20` (20%) via
the `maxBurden` option.

Examples
--------
The `test/` folder contains some simple test scripts you can run to see the
progress bar in action.


- - -

### Developed by [Terra Eclipse](http://www.terraeclipse.com)
Terra Eclipse, Inc. is a nationally recognized political technology and
strategy firm located in Aptos, CA and Washington, D.C.

- - -

### License: MIT
Copyright (C) 2012 Terra Eclipse, Inc. ([http://www.terraeclipse.com](http://www.terraeclipse.com))

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
**References:**
* [substack/node-charm/#18](https://github.com/substack/node-charm/pull/18)
3 changes: 3 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
theme: jekyll-theme-cayman
show_downloads: "true"
google_analytics: UA-11075253-1
48 changes: 48 additions & 0 deletions _layouts/default.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="UTF-8">
<title>{{ page.title | default: site.title }}</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#157878">
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,700' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="{{ '/assets/css/style.css?v=' | append: site.github.build_revision | relative_url }}">
</head>
<body>
<section class="page-header">
<a href="http://ahmadassaf.com" class="logo "><img alt="logo" src="http://ahmadassaf.com/images/logo.svg"></a>
<h1 class="project-name">{{ site.title | default: site.github.repository_name }}</h1>
<h2 class="project-tagline">{{ site.description | default: site.github.project_tagline }}</h2>
{% if site.github.is_project_page %}
<a href="{{ site.github.repository_url }}" class="btn">View on GitHub</a>
{% endif %}
{% if site.show_downloads %}
<a href="{{ site.github.zip_url }}" class="btn">Download .zip</a>
<a href="{{ site.github.tar_url }}" class="btn">Download .tar.gz</a>
{% endif %}
</section>

<section class="main-content">
{{ content }}

<footer class="site-footer">
{% if site.github.is_project_page %}
<span class="site-footer-owner"><a href="{{ site.github.repository_url }}">{{ site.github.repository_name }}</a> is maintained by <a href="{{ site.github.owner_url }}">{{ site.github.owner_name }}</a>.</span>
{% endif %}
<span class="site-footer-credits">This page was generated by <a href="https://pages.github.com">GitHub Pages</a>.</span>
</footer>
</section>

{% if site.google_analytics %}
<script type="text/javascript">
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

ga('create', '{{ site.google_analytics }}', 'auto');
ga('send', 'pageview');
</script>
{% endif %}
</body>
</html>
73 changes: 73 additions & 0 deletions assets/css/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
---
---

@import "{{ site.theme }}";

.page-header {
background: none !important;
color: #000 !important;
border-top: 10px solid #399f62 !important;
background-image:none !important;
}

.logo {
position: absolute;
left: 15px;
width: 80px;
}

.btn {
color: #fff !important;
background-color: #399f62 !important;
border-color: none !important;
border-width: 0 !important;
border-radius: 0 !important;
}

a {
color: #268bd2 !important;
}

.main-content pre {
background: #fff !important;
border: none !important;
}

footer {
display: none !important;
}

@media screen and (min-width: 64em) {
.page-header {
padding: 1rem 6rem !important;
}
}

.highlight .hll { background-color: #ffffcc !important}
.highlight .c { color: #008000 !important}
.highlight .err { border: 0 !important; background: none !important}
.highlight .k { color: #0000ff !important}
.highlight .cm { color: #008000 !important}
.highlight .cp { color: #0000ff !important}
.highlight .c1 { color: #008000 !important}
.highlight .cs { color: #008000 !important}
.highlight .kc { color: #0000ff !important}
.highlight .kd { color: #0000ff !important}
.highlight .kn { color: #0000ff !important}
.highlight .kp { color: #0000ff !important}
.highlight .kr { color: #0000ff !important}
.highlight .kt { color: #2b91af !important}
.highlight .s { color: #a31515 !important}
.highlight .nc { color: #2b91af !important}
.highlight .ow { color: #0000ff !important}
.highlight .sb { color: #a31515 !important}
.highlight .sc { color: #a31515 !important}
.highlight .sd { color: #a31515 !important}
.highlight .s2 { color: #a31515 !important}
.highlight .se { color: #a31515 !important}
.highlight .sh { color: #a31515 !important}
.highlight .si { color: #a31515 !important}
.highlight .sx { color: #a31515 !important}
.highlight .sr { color: #a31515 !important}
.highlight .s1 { color: #a31515 !important}
.highlight .ss { color: #a31515 !important}
15 changes: 15 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"use strict";

const charm = require('charm');

const Pace = require('./pace.js');

module.exports = function(options) {

if (typeof options === 'number') {
options = {
total: options
};
}
return new Pace(options);
};
Loading