Comparing version 1.0.0 to 1.0.1
44
cli.js
@@ -7,2 +7,3 @@ // Tools for writing command-line apps in Node. | ||
var readline = require('readline'); | ||
var path = require('path'); | ||
var chalk = require('chalk'); | ||
@@ -167,2 +168,41 @@ var stringWidth = require('string-width'); | ||
tree: function(dir, indent, args) { | ||
// render dir/file tree view based on array of files/dirs | ||
var self = this; | ||
if (!dir) dir = "."; | ||
if (!indent) indent = ""; | ||
if (!args) args = {}; | ||
var output = []; | ||
args.folderStyles = args.folderStyles || ["bold", "yellow"]; | ||
args.fileStyles = args.fileStyles || ["green"]; | ||
args.symlinkStyles = args.symlinkStyles || ["purple"]; | ||
args.lineStyles = args.lineStyles || ["gray"]; | ||
if (!indent) { | ||
output.push( this.applyStyles( path.basename(dir) + "/", args.folderStyles ) ); | ||
} | ||
fs.readdirSync(dir).forEach( function(filename, idx, arr) { | ||
var file = path.join( dir, filename ); | ||
var stats = fs.statSync(file); | ||
var last = (idx == arr.length - 1); | ||
var prefix = indent + self.applyStyles( " " + (last ? "└" : "├"), args.lineStyles ) + " "; | ||
if (stats.isDirectory()) { | ||
output.push( prefix + self.applyStyles(filename + "/", args.folderStyles) ); | ||
var results = self.tree(file, indent + self.applyStyles( last ? " " : " │", args.lineStyles ) + " ", args ); | ||
if (results) output.push( results ); | ||
} | ||
else if (stats.isSymbolicLink()) { | ||
output.push( prefix + self.applyStyles(filename, args.symlinkStyles) ); | ||
} | ||
else { | ||
output.push( prefix + self.applyStyles(filename, args.fileStyles) ); | ||
} | ||
} ); | ||
return output.length ? output.join("\n") : ""; | ||
}, | ||
table: function(rows, args) { | ||
@@ -364,3 +404,3 @@ // render table of cols/rows with unicode borders | ||
// hide CLI cursor | ||
process.stdout.write('\u001b[?25l'); | ||
cli.print('\u001b[?25l'); | ||
@@ -491,3 +531,3 @@ // just in case | ||
// restore CLI cursor | ||
process.stdout.write('\u001b[?25h'); | ||
cli.print('\u001b[?25h'); | ||
} | ||
@@ -494,0 +534,0 @@ } // progress |
{ | ||
"name": "pixl-cli", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Tools for building command-line apps for Node.js.", | ||
@@ -5,0 +5,0 @@ "author": "Joseph Huckaby <jhuckaby@gmail.com>", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
44091
455