Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

barcli

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

barcli - npm Package Compare versions

Comparing version 0.0.24 to 0.0.25

71

index.js

@@ -7,2 +7,3 @@ var chalk = require("chalk");

var maxValueLength = 0;
var windowWidth = process.stdout.columns || 80;

@@ -26,6 +27,2 @@ // fmap() and constrain() are lifted from Rick Waldron's awesome

if (barclis.length === 0){
clearScreen();
}
if (typeof opts === "undefined") {

@@ -47,2 +44,4 @@ opts = {};

this.precision = opts.precision || 0;
this.inline = opts.inline || false;
this.width = opts.width || windowWidth;

@@ -63,10 +62,24 @@ if (!opts.range || opts.range[0] === null || opts.range[1] === null) {

if (barclis.length === 0 && !this.inline){
clearScreen();
}
barclis.push(this);
resize(opts.width || process.stdout.columns);
resize(this.width);
}
Barcli.halt = function() {
barclis.forEach(function(barcli) {
barcli.finish();
});
}
Barcli.prototype.finish = function() {
process.stdout.write("\n");
};
Barcli.prototype.update = function(data) {
var prepend = "", append = "", bar = "", postbar = "";
var prepend = append = bar = postbar = "";

@@ -83,3 +96,3 @@ this.data = data;

maxValueLength = String(data).length;
resize(process.stdout.columns);
resize(this.width);
}

@@ -90,2 +103,3 @@

if (type === "number") {
if (this.autoRange) {

@@ -103,11 +117,12 @@ if (isNaN(this.inputRange[0]) || data < this.inputRange[0]) {

data = fmap(data, this.inputRange[0], this.inputRange[1], 0, this.width);
data = constrain(data, 0, this.width);
// Make our "bar"
for (i = 0; i < data; i++) {
bar = bar + " ";
for (i = 0; i <= data; i++) {
bar = bar + "\u2588";
}
// Make the space after our bar
for (i = data; i <= this.width; i++) {
for (i = data; i < this.width; i++) {
postbar += " ";

@@ -124,8 +139,19 @@ }

// Hide the cursor, put it on the correct line and clear right
process.stdout.write("\033[?25l\033["+String(this.index+1)+";" + String(maxLabelLength + 4) + "H\033[K");
// Hide the cursor
process.stdout.write("\033[?25l");
// Put cursor on the correct line and clear right
if (this.inline) {
process.stdout.write("\r");
} else {
process.stdout.write("\033["+String(this.index + 1)+";0H\033[K");
}
// Output the label
process.stdout.write(chalk[this.color](this.label+": "));
process.stdout.write(chalk.white("|"));
// Ouput the bar
if (type === "number") {
process.stdout.write(chalk[this.color].inverse(bar));
process.stdout.write(chalk[this.color](bar));
} else {

@@ -166,4 +192,5 @@ process.stdout.write(chalk[this.color](bar));

// Move the cursor to the end and make it visible again
process.stdout.write("\033["+String(barclis.length + 1)+";0H\033[K\033[?25h");
// Move the cursor to its previous position and make it visible again
// process.stdout.write("\033["+position.row+";"+position.column+"H\033[?25h");
if (!this.inline) process.stdout.write("\033[?25h");
};

@@ -180,3 +207,3 @@

process.stdout.on('resize', function() {
resize(process.stdout.columns);
resize();
});

@@ -186,4 +213,6 @@

var resize = function(size) {
var resize = function() {
windowWidth = process.stdout.columns || 80;
// Update our labels so the formatting is consistent

@@ -197,9 +226,5 @@ barclis.forEach(function(barcli, index) {

barcli.width = size - maxLabelLength - maxValueLength - 10;
barcli.width = windowWidth - maxLabelLength - maxValueLength - 10;
barcli.update(barcli.data);
// Output the label
process.stdout.write("\033["+String(barcli.index+1)+";0H");
process.stdout.write(chalk[barcli.color](barcli.label + ": "));
process.stdout.write(chalk.white("|\n"));
barcli.update(barcli.data);

@@ -206,0 +231,0 @@

{
"name": "barcli",
"version": "0.0.24",
"version": "0.0.25",
"description": "A simple tool for displaying real time bar graphs in the console",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -58,2 +58,4 @@ <img width="50%" align="right" src="https://cloud.githubusercontent.com/assets/854911/11871688/bbc225b2-a496-11e5-90f9-7a28631dd42b.png" />

**inline** (Boolean) - When true, Barcli will not clear the console. This is ideal for single barcli instances that occur inline and maintain stdout output before and after the bar (i.e. an install or large data download). Note that you must call ```barcli.finish()``` to bump the cursor down when done with the bar graph.
### Examples

@@ -60,0 +62,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc