pixl-cli 1.0.18 → 1.0.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/cli.js +16 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -512,13 +512,13 @@ If you call `cli.progress.update()` and pass in a number, the library assumes yo
|
|
|
512
512
|
|
|
513
513
|
### Temporarily Erasing The Bar
|
|
514
514
|
|
|
515
|
-
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.
|
|
515
|
+
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()`.
|
|
516
516
|
|
|
517
|
-
|
|
517
|
+
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:
|
|
518
518
|
|
|
519
519
|
```js
|
|
520
520
|
cli.progress.erase();
|
|
521
|
-
|
|
521
|
+
console.log( some_large_object );
|
|
522
522
|
cli.progress.draw();
|
|
523
523
|
```
|
|
524
524
|
|
package/cli.js
CHANGED
|
@@ -432,7 +432,11 @@ var cli = module.exports = {
|
|
|
432
432
|
|
|
433
433
|
print: function(msg) {
|
|
434
434
|
// print message to console
|
|
435
|
-
if (!this.args.quiet)
|
|
435
|
+
if (!this.args.quiet) {
|
|
436
|
+
if (this.progress.running) this.progress.erase();
|
|
437
|
+
process.stdout.write(msg);
|
|
438
|
+
if (this.progress.running) this.progress.draw();
|
|
439
|
+
}
|
|
436
440
|
this.log(msg);
|
|
437
441
|
},
|
|
438
442
|
|
|
@@ -454,7 +458,11 @@ var cli = module.exports = {
|
|
|
454
458
|
|
|
455
459
|
warn: function(msg) {
|
|
456
460
|
// print to stderr
|
|
457
|
-
if (!this.args.quiet)
|
|
461
|
+
if (!this.args.quiet) {
|
|
462
|
+
if (this.progress.running) this.progress.erase();
|
|
463
|
+
process.stderr.write(msg);
|
|
464
|
+
if (this.progress.running) this.progress.draw();
|
|
465
|
+
}
|
|
458
466
|
this.log(msg);
|
|
459
467
|
},
|
|
460
468
|
|
|
@@ -465,6 +473,7 @@ var cli = module.exports = {
|
|
|
465
473
|
|
|
466
474
|
die: function(msg) {
|
|
467
475
|
// print to stderr and exit with non-zero code
|
|
476
|
+
if (this.progress.running) this.progress.end();
|
|
468
477
|
this.warn(msg);
|
|
469
478
|
process.exit(1);
|
|
470
479
|
},
|
|
@@ -596,8 +605,8 @@ var cli = module.exports = {
|
|
|
596
605
|
|
|
597
606
|
draw: function() {
|
|
598
607
|
// draw progress bar, spinner
|
|
599
|
-
if (!cli.tty()) return;
|
|
600
608
|
if (!this.running) return;
|
|
609
|
+
if (!cli.tty()) return;
|
|
601
610
|
|
|
602
611
|
var args = this.args;
|
|
603
612
|
var line = args.indent;
|
|
@@ -660,8 +669,8 @@ var cli = module.exports = {
|
|
|
660
669
|
},
|
|
661
670
|
|
|
662
671
|
update: function(args) {
|
|
663
|
-
if (!cli.tty()) return;
|
|
664
672
|
if (!this.running) return;
|
|
673
|
+
if (!cli.tty()) return;
|
|
665
674
|
|
|
666
675
|
if (typeof(args) == 'number') {
|
|
667
676
|
// just updating the amount
|
|
@@ -678,6 +687,7 @@ var cli = module.exports = {
|
|
|
678
687
|
|
|
679
688
|
erase: function() {
|
|
680
689
|
// erase progress
|
|
690
|
+
if (!this.running) return;
|
|
681
691
|
if (!cli.tty()) return;
|
|
682
692
|
if (this.lastLine && !this.args.quiet) {
|
|
683
693
|
process.stdout.write( cli.space( stringWidth(this.lastLine) ) + "\r" );
|
|
@@ -686,8 +696,8 @@ var cli = module.exports = {
|
|
|
686
696
|
|
|
687
697
|
end: function(erase) {
|
|
688
698
|
// end of progress session
|
|
689
|
-
if (!cli.tty()) return;
|
|
690
699
|
if (!this.running) return;
|
|
700
|
+
if (!cli.tty()) return;
|
|
691
701
|
|
|
692
702
|
if (erase !== false) {
|
|
693
703
|
this.erase();
|
|
@@ -695,6 +705,7 @@ var cli = module.exports = {
|
|
|
695
705
|
clearTimeout( this.timer );
|
|
696
706
|
this.running = false;
|
|
697
707
|
this.args = {};
|
|
708
|
+
this.lastLine = '';
|
|
698
709
|
|
|
699
710
|
// restore CLI cursor
|
|
700
711
|
if (!this.args.quiet) process.stdout.write('\u001b[?25h');
|
package/package.json
CHANGED