pixl-cli
Advanced tools
Comparing version 1.0.18 to 1.0.19
21
cli.js
@@ -435,3 +435,7 @@ // Tools for writing command-line apps in Node. | ||
// print message to console | ||
if (!this.args.quiet) process.stdout.write(msg); | ||
if (!this.args.quiet) { | ||
if (this.progress.running) this.progress.erase(); | ||
process.stdout.write(msg); | ||
if (this.progress.running) this.progress.draw(); | ||
} | ||
this.log(msg); | ||
@@ -458,3 +462,7 @@ }, | ||
// print to stderr | ||
if (!this.args.quiet) process.stderr.write(msg); | ||
if (!this.args.quiet) { | ||
if (this.progress.running) this.progress.erase(); | ||
process.stderr.write(msg); | ||
if (this.progress.running) this.progress.draw(); | ||
} | ||
this.log(msg); | ||
@@ -470,2 +478,3 @@ }, | ||
// print to stderr and exit with non-zero code | ||
if (this.progress.running) this.progress.end(); | ||
this.warn(msg); | ||
@@ -602,4 +611,4 @@ process.exit(1); | ||
// draw progress bar, spinner | ||
if (!this.running) return; | ||
if (!cli.tty()) return; | ||
if (!this.running) return; | ||
@@ -667,4 +676,4 @@ var args = this.args; | ||
update: function(args) { | ||
if (!this.running) return; | ||
if (!cli.tty()) return; | ||
if (!this.running) return; | ||
@@ -686,2 +695,3 @@ if (typeof(args) == 'number') { | ||
// erase progress | ||
if (!this.running) return; | ||
if (!cli.tty()) return; | ||
@@ -695,4 +705,4 @@ if (this.lastLine && !this.args.quiet) { | ||
// end of progress session | ||
if (!this.running) return; | ||
if (!cli.tty()) return; | ||
if (!this.running) return; | ||
@@ -705,2 +715,3 @@ if (erase !== false) { | ||
this.args = {}; | ||
this.lastLine = ''; | ||
@@ -707,0 +718,0 @@ // restore CLI cursor |
{ | ||
"name": "pixl-cli", | ||
"version": "1.0.18", | ||
"version": "1.0.19", | ||
"description": "Tools for building command-line apps for Node.js.", | ||
@@ -5,0 +5,0 @@ "author": "Joseph Huckaby <jhuckaby@gmail.com>", |
@@ -515,9 +515,9 @@ <details><summary>Table of Contents</summary> | ||
If you need to temporarily erase the progress bar, presumably to write some lines of output to the console, you can call the `cli.progress.erase()` method. Just note that after `freq` milliseconds (or less), the bar will be redrawn. | ||
If you need to temporarily erase the progress bar, presumably to write some lines of output to the console, you can call the `cli.progress.erase()` method. To reduce flickering, you can force a redraw just after outputting your lines by calling `cli.progress.draw()`. | ||
To reduce flickering, you can force a redraw just after outputting your lines by calling `cli.progress.draw()`. Example: | ||
However, if you use the built-in CLI `print()`, `println()`, `verbose()` or `verboseln()` functions, the progress bar is automatically hidden and redrawn for you. You should only need to manually erase and redraw it if you are calling some other code that outputs to STDOUT or STDERR. Example: | ||
```js | ||
cli.progress.erase(); | ||
cli.print("We're now in phase 2 of 3: Updating DB indexes...\n\n"); | ||
console.log( some_large_object ); | ||
cli.progress.draw(); | ||
@@ -524,0 +524,0 @@ ``` |
54302
613