console-visualizer

Visualization in the console

Usage no npm install needed!

<script type="module">
  import consoleVisualizer from 'https://cdn.skypack.dev/console-visualizer';
</script>

README

The visualizer for the Node.js console

Logo


Installation

NPM

npm install console-visualizer --save

Usage

Example

var Visualizer = require('console-visualizer');

var visual = new Visualizer({
    progress: {
        scale: {
            fill: "|",
            half: false
        }
    }
});

var loadMin = 0;
var loadCur = 0;
var loadMax = 100;

loadInterval = setInterval(function() {
    if (loadCur <= loadMax) {
        visual.clear(); // Clear console
        visual.drawProgress(loadMin, loadCur, loadMax); // Draw progress bar
        
        loadCur++;
    } else {
        clearInterval(loadInterval);
    }
}, 100);

/* Output:
[||||||||||          ] 50%
*/

Methods

constructor(opts)

Object constructor

  • Object opts
    • Object progress - Progress bar
      • Integer max_chars - The maximum characters length in the console. default: 80
      • Boolean|Char arrow - default: false
      • Object text
        • Boolean draw - default: true
        • Boolean floor - default: true
      • Object braces
        • Boolean|Char open - default: "["
        • Boolean|Char close - default: "]"
      • Object scale
        • Char fill - default: "="
        • Boolean|Char half - default: "-"
        • Char empty - default: " "

clear()

Clear console

getProgress(min, cur, max)

Generate progress bar like this

[==========          ] 50%
  • Integer min - start of range

  • Integer cur - current value

  • Integer max - end of range

  • return String - progress bar

drawProgress(min, cur, max)

Draw progress bar in console. Based on the method Visualizer#getProgress

  • Integer min - start of range
  • Integer cur - current value
  • Integer max - end of range

Build form coffee source

Build project

The source code in the folder development. They should be compiled in the bin folder

# With watching
gulp

or

gulp build

Build gulpfile

coffee -c gulpfile.coffee

Roadmap

  • Add more visual progress bars. Like this
###
      ________
     `.______,'
      (______)
      <      >
       )    (
      /`----.\
     /        \
    / _    _   \
   :,' `-.' `.' :
   | *    O   * |
   :    o   o   ;
    \ .  * .   /
     `.______.'
###

Changelog

1.0.0 [ Stable ]

  • Add - first realise