visionmedia / node-progress Goto Github PK
View Code? Open in Web Editor NEWFlexible ascii progress bar for nodejs
License: MIT License
Flexible ascii progress bar for nodejs
License: MIT License
[info] Fetching xulrunner, 53375323 bytes from ftp.mozilla.org
downloading [------------------------------------------------------------------------------------------------------------------------------] 0% 4.8s
downloading [---------------------------------------------------------------------------------------------------------------------------] 0% 2104.8s
downloading [---------------------------------------------------------------------------------------------------------------------------] 0% 3987.1s
downloading [---------------------------------------------------------------------------------------------------------------------------] 0% 3886.0s
downloading [---------------------------------------------------------------------------------------------------------------------------] 0% 5180.5s
downloading [---------------------------------------------------------------------------------------------------------------------------] 0% 6477.6s
downloading [---------------------------------------------------------------------------------------------------------------------------] 0% 6614.1s
downloading [---------------------------------------------------------------------------------------------------------------------------] 0% 7716.8s
downloading [---------------------------------------------------------------------------------------------------------------------------] 0% 8820.7s
downloading [---------------------------------------------------------------------------------------------------------------------------] 0% 9923.4s
downloading [--------------------------------------------------------------------------------------------------------------------------] 0% 11026.1s
downloading [--------------------------------------------------------------------------------------------------------------------------] 0% 12127.7s
downloading [--------------------------------------------------------------------------------------------------------------------------] 0% 13231.5s
downloading [--------------------------------------------------------------------------------------------------------------------------] 0% 15435.9s
downloading [--------------------------------------------------------------------------------------------------------------------------] 0% 16539.7s
downloading [--------------------------------------------------------------------------------------------------------------------------] 0% 16650.0s
downloading [--------------------------------------------------------------------------------------------------------------------------] 0% 11319.3s
downloading [--------------------------------------------------------------------------------------------------------------------------] 0% 11180.0s
downloading [--------------------------------------------------------------------------------------------------------------------------] 0% 11057.0s
downloading [--------------------------------------------------------------------------------------------------------------------------] 0% 10193.8s
downloading [---------------------------------------------------------------------------------------------------------------------------] 0% 9759.8s
downloading [---------------------------------------------------------------------------------------------------------------------------] 0% 9080.8s
downloading [---------------------------------------------------------------------------------------------------------------------------] 0% 9086.8s
downloading [---------------------------------------------------------------------------------------------------------------------------] 0% 8732.9s
downloading [---------------------------------------------------------------------------------------------------------------------------] 0% 8588.0s
downloading [---------------------------------------------------------------------------------------------------------------------------] 0% 8849.1s
downloading [---------------------------------------------------------------------------------------------------------------------------] 0% 8136.9s
downloading [---------------------------------------------------------------------------------------------------------------------------] 0% 8043.2s
downloading [---------------------------------------------------------------------------------------------------------------------------] 0% 8202.7s
downloading [---------------------------------------------------------------------------------------------------------------------------] 0% 7879.8s
downloading [---------------------------------------------------------------------------------------------------------------------------] 0% 7861.5s
downloading [=--------------------------------------------------------------------------------------------------------------------------] 0% 7897.5s
downloading [=--------------------------------------------------------------------------------------------------------------------------] 0% 7828.9s
downloading [=--------------------------------------------------------------------------------------------------------------------------] 0% 7963.6s
downloading [=--------------------------------------------------------------------------------------------------------------------------] 0% 7847.4s
downloading [=--------------------------------------------------------------------------------------------------------------------------] 0% 7832.8s
downloading [=--------------------------------------------------------------------------------------------------------------------------] 0% 8002.8s
downloading [=--------------------------------------------------------------------------------------------------------------------------] 0% 7983.9s
downloading [=--------------------------------------------------------------------------------------------------------------------------] 0% 8010.6s
downloading [=--------------------------------------------------------------------------------------------------------------------------] 1% 8036.2s
downloading [=--------------------------------------------------------------------------------------------------------------------------] 1% 8192.4s
downloading [=--------------------------------------------------------------------------------------------------------------------------] 1% 8084.0s
downloading [=--------------------------------------------------------------------------------------------------------------------------] 1% 7863.4s
downloading [=--------------------------------------------------------------------------------------------------------------------------] 1% 7927.7s
downloading [=--------------------------------------------------------------------------------------------------------------------------] 1% 7951.5s
downloading [=--------------------------------------------------------------------------------------------------------------------------] 1% 8128.4s
downloading [=--------------------------------------------------------------------------------------------------------------------------] 1% 8304.9s
downloading [=--------------------------------------------------------------------------------------------------------------------------] 1% 8481.8s
downloading [=--------------------------------------------------------------------------------------------------------------------------] 1% 8658.3s
downloading [=--------------------------------------------------------------------------------------------------------------------------] 1% 8835.2s
downloading [=--------------------------------------------------------------------------------------------------------------------------] 1% 9012.1s
downloading [=--------------------------------------------------------------------------------------------------------------------------] 1% 9188.6s
downloading [=--------------------------------------------------------------------------------------------------------------------------] 1% 9365.5s
downloading [=--------------------------------------------------------------------------------------------------------------------------] 1% 9496.4s
downloading [=--------------------------------------------------------------------------------------------------------------------------] 1% 8982.3s
downloading [=--------------------------------------------------------------------------------------------------------------------------] 1% 9024.8s
downloading [=--------------------------------------------------------------------------------------------------------------------------] 1% 9145.7s
downloading [=--------------------------------------------------------------------------------------------------------------------------] 1% 9306.7s
downloading [=--------------------------------------------------------------------------------------------------------------------------] 1% 9224.3s
downloading [=--------------------------------------------------------------------------------------------------------------------------] 1% 9301.2s
downloading [=--------------------------------------------------------------------------------------------------------------------------] 1% 9456.3s
downloading [=--------------------------------------------------------------------------------------------------------------------------] 1% 9490.6s
downloading [=--------------------------------------------------------------------------------------------------------------------------] 1% 9643.6s
downloading [=--------------------------------------------------------------------------------------------------------------------------] 1% 9796.6s
downloading [=--------------------------------------------------------------------------------------------------------------------------] 1% 9826.4s
downloading [=--------------------------------------------------------------------------------------------------------------------------] 1% 9815.3s
downloading [=--------------------------------------------------------------------------------------------------------------------------] 1% 9804.7s
downloading [=--------------------------------------------------------------------------------------------------------------------------] 1% 9832.8s
downloading [=--------------------------------------------------------------------------------------------------------------------------] 1% 9977.5s
downloading [=--------------------------------------------------------------------------------------------------------------------------] 1% 9925.7s
downloading [=-------------------------------------------------------------------------------------------------------------------------] 1% 10067.5s
Wrong math:
replace eta = elapsed * (1 - (this.curr / this.total))
to eta = elapsed * (this.total / this.curr - 1);
:eta
is Infinity
if bar.tick(0)
is called.
The cursor can sometimes be really annoying especially in long running progress bars is there a way to remove it
progress/lib/node-progress.js:131
incomplete = Array(width - complete.length).join(this.chars.incomplete);
^
RangeError: Invalid array length
at ProgressBar.render progress/lib/node-progress.js:131:16)
basically this is caused because the length of incomplete is calculated by taking the string length of complete:
incomplete = Array(width - complete.length).join(this.chars.incomplete);
I am running darwin(10.8.4) and [email protected]
I am seeing inconsistent behavior that results generally in the progress bar staying on one line for the first few seconds then it seemingly stops clearing the line and just outputs numerous progress bars one after another sometimes stopping to behave normally again (with the wall of progress bar text above and around it) as if the clearLine
function was not being called some or most of the time.
When I removed the darwin specific code in the clearLine
function and left it to only call this.write(null, {ctrl: true, name: 'u'});
the progress bar behaved as expected.
The progress bar doesn't seem to show up when run with grunt-shell. Any idea what is going on?
Just an idea:
Using the progress bar for a simple counter - if total not set :percent
etc. would not make sense but :current
could still be useful:
var buildbar = new ProgressBar('Build run (x:current)', {
// total: 9999 // Would be nice if we didn't have to set this
});
// Add a tick every time the server boots
runForever(program.host, program.port, function() {
buildbar.tick(1);
});
This is not a issue at all =), but more a request to add the information about installation using npm to the 'readme'.
AFAIK, this module is called progress and new version progress2 in the npm database,
thanks.
Patrick Marques
when it is, the clearLine / cursorTo trick doesn't work, so maybe we should handle this is render? like, cut the output so only relevant parts of the progress is shown?
(using cygwin)
$ node test.js
events.js:72
throw er; // Unhandled 'error' event
^
Error: read ENOTCONN
at errnoException (net.js:901:11)
at Socket._read (net.js:391:21)
at Socket.Readable.read (_stream_readable.js:320:10)
at Socket.read (net.js:293:43)
at new Socket (net.js:185:10)
at process.stdin (node.js:660:19)
at new ProgressBar (C:\cygwin64\home\Thomas Anderson\hyperloop\node_modules\progress\lib\node-progress.js:42:19)
at ClientRequest.<anonymous> (C:\cygwin64\home\Thomas Anderson\hyperloop\test.js:14:13)
at ClientRequest.EventEmitter.emit (events.js:95:17)
at HTTPParser.parserOnIncomingClient [as onIncoming] (http.js:1669:21)
seems to be related to setting up process.stdin in readline.
works fine under normal windows console.
In .terminate()
, you call this.rl.resume()
, which AFAICT calls process.stdin.resume()
since you're wrapping process.stdin
This makes scripts not exit on their own, because they're waiting for more input to appear on stdin.
Any reason for calling this? (If anything I'd imagine on terminate you'd want to call this.rl.pause()
)
@jdan and everyone else, do you have good suggestions on where to take this for version 2?
so far:
once we've cleaned up the issues, i'll publish version 1.1 on npm
Output looks like this on cmd.exe
[====--------------------------------------------] 10%
[=========---------------------------------------] 20%
[==============----------------------------------] 30%
[===================-----------------------------] 40%
[========================------------------------] 50%
[=============================-------------------] 60%
[==================================--------------] 70%
[=======================================---------] 80%
[============================================----] 90%
[=================================================] 100%
Hello, the width is not computed correctly when ansi colors are used
https://github.com/tj/node-progress/blob/master/lib/node-progress.js#L139
ansi-regex should be considered, something like that
var ansiRegex = require('ansi-regex');
var availableSpace = Math.max(0, this.stream.columns - str.replace(ansiRegex(), '').replace(':bar', '').length);
With this code of mine:
var bar = new ProgressBar(' :status [:bar] :percent :etas', { total: 100 });
// Later as part of a `request()` call
.pipe(progressStream({time: 100}))
.on('progress', function(p) {
bar.update(p.progress / 100, {status: 'Downloading'});
})
First problem. Bar updates appear on new lines instead of being updated. Perhaps an incompatibility with OSX's terminal.
Second problem. There is currently a bug with request+progress-stream when gzip is in use (as in my case) that causes the progress event to not know what the actual progress is and as a result have to report progress: 0
until the end when it can finally report one progress: 100
.
This means the bar should stay at 0% the whole time and then jump all the way to 100%. However this bar is instead incrementing by one tick each time as if it's completely ignoring the argument to .update
.
If I have a progressbar that needs to tick 500 times, I cannot seem to tell progress
that I need a bar with total: 500
, but visual size 50
, for instance. It just creates 500 dashes that it replaces with equal signs. Did I miss something in the readme, or is this not currently supported?
Options could as a minimum default to an empty object, or maybe we should warn if required options are missing.
For example if you start the progress bar with no options, it will fail on line 42 in the main library because of options being null, and we're trying to reference options.stream.
This screencast shows the problem and is easier to follow than trying to explain it,
https://docs.google.com/file/d/0B8AqVMFNVTUwYmQtZkowNkZ4bUU/edit?usp=sharing
Seems like odd behaviour. I tried setting RawMode, no difference. Interestingly, at certain terminal sizes it works just fine, although sometimes hangs at 99% even through bar.curr === bar.total
and bar.complete === true
I've noticed having more than 10 progress bars in one CLI triggers an event-emitter leak. Traced it to the readline module and I'm not sure how/if I can increase the limit there.
We have a data importer and for big files, the remaining time reaches a high amount of seconds (>100'000). That makes the timing tough to estimate.
When the timing reaches say more than 5 minutes, would it be possible to display the time in minutes ? Same for minutes to hours and hours to days ?
reference: senecajs-labs/seneca-import-csv#1
The readline module is very buggy. If you're using an instance in your script and then you use a progress bar, when it closes, the instance in your script is also closed. Can you avoid the readline module and use the functions process.stdout.clearLine()
and process.stdout.cursorTo(<position>)
?
For example, a "Waiting..." message: http://stackoverflow.com/questions/11600890/how-to-erase-characters-printed-in-console
This module does not work at all for me on osx, first in the render method this line evaluates to true: if (!this.stream.isTTY) return;
(my stream is process.stdout).
I removed that line to debug, and next it broke on this.stream.clearLine();
because clearLine
does not appear to be a method on writeable streams in node. I couldn't find what version it was removed in :P
Would it be possible to add a token that would not be updated by the progress bar itself but by the user? it would be doing something like:
var bar = new ProgressBar(':bar :custom', { total: 10 });
bar.render();
// later
bar.custom('here is my custom text');
the progress bar does not compute / report the :elapsed correctly.
bar = new progressBar (
' progress [:bar] :elapsed',
total : 10,
width : 10,
callback : function ()
{
process.exit(0);
}
);
setInterval(
function () { bar.tick(); }.
5000);
will report completion in 45 seconds, as opposed to 50 seconds (10 ticks x 5 seconds).
I wanted to display the progress bar before having the first tick()
, therefore I looked up in the code to see that I could use render()
to do it. I think it would be nice to have the methods in the README file like the options and tokens.
Hi, I've succesfully implemented a progress bar to show progress on what will be a substantial download. It works great but after finishing it does not release the terminal and seems to hang. The only way to get a prompt back is by hitting ctrl+c. I tried calling console.log('\n'); and console.log(); and sys.puts('download complete'); in the res.on('end', function(){...}); but no luck. Any ideas?
12:46:13 ~/Sites/branches/node-onboarding: node vm.js
downloading [=================================================] 100% 0.0sDownload completed.
Thank you
This is a regression in 0.1.0 from 0.0.5.
Since progress
now uses readline
, it resume
s stdin when you start your bar and tries to pause
it again (via this.rl.close()
) when the bar is complete. However, due to an off-by-one error, it doesn't actually call this.rl.close
until 1 tick past total. So if you are using progress
in a simple command-line tool which otherwise doesn't use stdin, using progress
0.1.0 means that stdin
will be left resume
d and your program will hang. For example, the following program:
var ProgressBar = require('progress');
var bar = new ProgressBar(':bar', {total: 2});
bar.tick();
hangs with 0.1.0 but not with 0.0.5.
The simplest fix for this would be to change the // progress complete
code from
if ((this.curr += len) > this.total) {
to
if ((this.curr += len) >= this.total) {
However, it seems unfortunate that progress has to interact with stdin at all. Maybe just don't use readline
? Or instead of passing process.stdin
to readline
, pass a dummy object that ignores the methods that are called on it?
I'm happy to submit a pull request to do any of the above, depending on which makes most sense to you.
hello, Great Work!!!
i using grunt with nodemon and the progress bar are not showing any idea?
thanks
readline needs to be closed at the end or the program doesn't exit, tried doing bar.rl.close()
but doesn't seem to help :(
I'm wondering if node-progress can support multiple progress bars. I have found a gist showing show how to do so but I think it's good it can be built in the lib.
Thanks
npm ERR! Error: No compatible version found: progress@'^1.1.5'
npm ERR! Valid install targets:
npm ERR! ["0.0.1","0.0.2","0.0.3","0.0.4","0.0.5","0.1.0","1.0.0","1.0.1","1.1.0
","1.1.2","1.1.3","1.1.4","1.1.5","1.1.6","1.1.7","1.1.8"]
npm ERR! at installTargetsError (C:\Program Files (x86)\nodejs\node_modules\
npm\lib\cache.js:682:10)
npm ERR! at C:\Program Files (x86)\nodejs\node_modules\npm\lib\cache.js:597:
10
npm ERR! at saved (C:\Program Files (x86)\nodejs\node_modules\npm\node_modul
es\npm-registry-client\lib\get.js:138:7)
npm ERR! at Object.oncomplete (fs.js:297:15)
npm ERR! If you need help, you may report this log at:
npm ERR! <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR! <[email protected]>
npm ERR! System Windows_NT 6.2.9200
npm ERR! command "C:\\Program Files (x86)\\nodejs\\\\node.exe" "C:\\Program File
s (x86)\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install"
npm ERR! cwd C:\Users\user.domain\Downloads\openwapp-1815a3ce730d100b64d7
3044c1986b069d48ef12.tar\openwapp.git
npm ERR! node -v v0.8.22
npm ERR! npm -v 1.2.14
the 1.1.5 version of progress (which isn't actually a tag on github?) has a horrible regression where instead of updating the bar in place, it prints a new bar for every tick.
anything else @jdan?
multi-progress is now a package on npm
This module adds a layer on top of the API of progress that allows for multiple progress bars. It is based on the gist by @nuxlli
I used it in my rslashimg package, and it seems to work just fine.
Should I send in a PR adding this to the progress readme?
instead of .tick( by_amt )
A CLI tool was controlled as part of a grunt process. For whatever reason, this caused the terminal flag to be set to false.
node-progress.js:114 has the is the following line:
this.rl.write(null, {ctrl: true, name: 'u'});
When terminal is false, node throws an exception because it has an explicit check for undefined, but not for null. When terminal is true, node is using a more general check.
Changing the line to:
this.rl.write(undefined, {ctrl: true, name: 'u'});
appears to address the issue without affecting the progress bar.
tick() is always showing "[2K" characters before bar string. I've changed this line in tick():
this.stream.write('\r\033[2K' + str);
to
this.stream.write('\r\033' + str);
Works well.
[email protected], node 0.8.8, MacOS X 10.8.1
I'm getting this error when used progress inside a service called Shippable. (a CI server)
I'm using [email protected].
What should be the issue?
/usr/lib/node_modules/mup/node_modules/nodemiral/node_modules/progress/lib/node-progress.js:168
this.stream.clearLine();
^
TypeError: Object # has no method 'clearLine'
at ProgressBar.terminate (/usr/lib/node_modules/mup/node_modules/nodemiral/node_modules/progress/lib/node-progress.js:168:17)
at ProgressBar.tick (/usr/lib/node_modules/mup/node_modules/nodemiral/node_modules/progress/lib/node-progress.js:91:10)
at ProgressBar.update (/usr/lib/node_modules/mup/node_modules/nodemiral/node_modules/progress/lib/node-progress.js:157:8)
There is a console.log() on the termination fn
https://github.com/visionmedia/node-progress/blob/master/lib/node-progress.js#L170
this make the node process to add new lines on the stdout/log, is there for any reason ?
var colors = require("colors");
var ProgressBar = require("progress");
var bar = new ProgressBar(":bar", {complete:"=".green, total:100});
bar.tick(10);
bar.tick(50);
bar.tick(100);
causes
/project/node_modules/progress/lib/node-progress.js:131
incomplete = Array(width - complete.length).join(this.chars.incomplete);
^
RangeError: Invalid array length
at ProgressBar.render (/project/node_modules/progress/lib/node-progress.js:131:16)
at ProgressBar.tick (/project/node_modules/progress/lib/node-progress.js:86:8)
at Object.<anonymous> (/project/lib/index.js:6:5)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:906:3
Does the terminal need to have any special settings? Using zsh...
Nothing happens when I use the example in the repo.
The progress bar works totally fine when I run my node script like this:
node somefile -c someconfig
However, if I do the same with .spawn(), the task works, but I don't see any progress bar output.
My task prints things to the console via Winston logger's console transport.
Here is what I see:
node tasks/users_1.js --config config.local
Warning!>Warning! This will drop all user data! Are you sure?> y
info: Dropped users..
info: Processing 93647 records..
info:
done
info: Processing xxxx meta key, found 93640 records..
(progress bar should be here)
Hi there,
we just found an error in the "node-progress" module. If you print out the current progress of a file upload using grunt-ssh the progressbar throws an error if the mac terminal window is to small.
We tracked the error down to the node-progress module in version 1.1.6.
In line 127 it is possible for the width to become a negative value.
We fixed this by wrapping the variable assignment with a "Math.max(value, 0)"
Old line:
var width = Math.min(this.width, availableSpace);
New line:
var width = Math.max(Math.min(this.width, availableSpace), 0);
It would be great if this could be implemented.
on OSX if I use a progress bar that's wider than the terminal I'm running my script in the progress bar doesn't update in place, but instead writes new lines every time it updates, so that I get something like
[-----]
[=----]
[==---]
[===--]
[====-]
which for a 100 element progress bar means 100 lines of screen clutter =(
On windows, this seems to work just fine, the progress bar updates in place and then disappears once it's full.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.