pax_global_header00006660000000000000000000000064131522300730014506gustar00rootroot0000000000000052 comment=03e2c193e4e181a117244f0d4d83364cf049551a ansi-color-table-1.0.1/000077500000000000000000000000001315223007300146405ustar00rootroot00000000000000ansi-color-table-1.0.1/.gitignore000066400000000000000000000000151315223007300166240ustar00rootroot00000000000000node_modules ansi-color-table-1.0.1/.travis.yml000066400000000000000000000000731315223007300167510ustar00rootroot00000000000000language: node_js node_js: - "0.8" - "0.10" - "0.11" ansi-color-table-1.0.1/LICENSE000066400000000000000000000020651315223007300156500ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2014 Quim Calpe Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ansi-color-table-1.0.1/README.md000066400000000000000000000044161315223007300161240ustar00rootroot00000000000000ANSI COLOR TABLE ================ Tables for cli/stdout supporting colors using [ansi](https://github.com/TooTallNate/ansi.js) npm module. Based on [text-table](https://github.com/substack/text-table) but using ansi cursor, not color codes. [![Build Status](https://travis-ci.org/quimcalpe/reusable-templates.png)](https://travis-ci.org/quimcalpe/ansi-color-table) ###Examples **Table with colors and default options** ```javascript var table = require('ansi-color-table'); var data = [ [ "Username".blue().underline(), "Email".blue().underline(), "active".blue().underline() ], [ "john.smith", "john@gimail.com".yellow(), "yes".green() ], [ "steve.balmes", "sbalmes@hotma.il".yellow(), "yes".green() ], [ "james.durango", "james.durango@greenvine.com".yellow(), "no".red() ], [ "elisa.polite", "epolite@".yellow(), "yes".green() ] ]; table(data); ``` **Custom align, custom separator, centered header** ```javascript var table = require('../'); var data = [ [ "Username".blue().underline(), "Email".blue().underline(), "Age".blue().underline(), "Active".blue().underline() ], [ "john.smith", "john@gimail.com".yellow(), "9".white(), "yes".green() ], [ "steve.balmes", "sbalmes@hotma.il".yellow(), "19".white(), "yes".green() ], [ "james.durango", "james.durango@greenvine.com".yellow(), "99".white(), "no".red() ], [ "elisa.polite", "epolite@".yellow(), "109".white(), "yes".green() ] ]; table(data, { align : [ "left", "left", "right", "center" ], separator : " | ", headerAlign: "center" }); ``` **Redirect output to custom stream instead of `process.stdout`** ```javascript var table = require('../'); var Stream = require('stream'); var tableData = [ [ "Username".blue().underline(), "Email".blue().underline(), "active".blue().underline() ], [ "john.smith", "john@gimail.com".yellow(), "yes".green() ], [ "steve.balmes", "sbalmes@hotma.il".yellow(), "yes".green() ] ]; var output_stream = new Stream(); var output_data = ""; output_stream.write = function (data) { output_data += data; }; output_stream.end = function () { // do something with data console.log(output_data); }; table(tableData, {}, output_stream); ``` ### Installation With [npm](https://npmjs.org) do: ```bash $ npm install ansi-color-table ``` ### Testing ```bash $ npm test ``` ### License MITansi-color-table-1.0.1/examples/000077500000000000000000000000001315223007300164565ustar00rootroot00000000000000ansi-color-table-1.0.1/examples/custom-opts.js000066400000000000000000000011231315223007300213060ustar00rootroot00000000000000var table = require('../'); var data = [ [ "Username".blue().underline(), "Email".blue().underline(), "Age".blue().underline(), "Active".blue().underline() ], [ "john.smith", "john@gimail.com".yellow(), "9".white(), "yes".green() ], [ "steve.balmes", "sbalmes@hotma.il".yellow(), "19".white(), "yes".green() ], [ "james.durango", "james.durango@greenvine.com".yellow(), "99".white(), "no".red() ], [ "elisa.polite", "epolite@".yellow(), "109".white(), "yes".green() ] ]; table(data, { align : [ "left", "left", "right", "center" ], separator : " | ", headerAlign: "center" }); ansi-color-table-1.0.1/examples/redirect_stream.js000066400000000000000000000010571315223007300221730ustar00rootroot00000000000000var table = require('../'); var Stream = require('stream'); var tableData = [ [ "Username".blue().underline(), "Email".blue().underline(), "active".blue().underline() ], [ "john.smith", "john@gimail.com".yellow(), "yes".green() ], [ "steve.balmes", "sbalmes@hotma.il".yellow(), "yes".green() ] ]; var output_stream = new Stream(); var output_data = ""; output_stream.write = function (data) { output_data += data; }; output_stream.end = function () { // do something with data console.log(output_data); }; table(tableData, {}, output_stream); ansi-color-table-1.0.1/examples/users.js000066400000000000000000000006361315223007300201620ustar00rootroot00000000000000var table = require('../'); var data = [ [ "Username".blue().underline(), "Email".blue().underline(), "active".blue().underline() ], [ "john.smith", "john@gimail.com".yellow(), "yes".green() ], [ "steve.balmes", "sbalmes@hotma.il".yellow(), "yes".green() ], [ "james.durango", "james.durango@greenvine.com".yellow(), "no".red() ], [ "elisa.polite", "epolite@".yellow(), "yes".green() ] ]; table(data); ansi-color-table-1.0.1/index.js000066400000000000000000000043141315223007300163070ustar00rootroot00000000000000var ansi = require("ansi"); var padSegments = require("./lib/padsegments"); var colors = [ "white", "black", "blue", "cyan", "green", "magenta", "red", "yellow", "grey", "brightBlack", "brightRed", "brightGreen", "brightYellow", "brightBlue", "brightMagenta", "brightCyan", "brightWhite" ]; var styles = [ "bold", "italic", "underline", "inverse" ]; colors.forEach(function (color) { String.prototype[color] = function () { this._color = color; return this; }; }); styles.forEach(function (style) { String.prototype[style] = function () { if ( !this._styles ) this._styles = []; this._styles.push(style); return this; }; }); function printTable(table, opts, stream) { opts = opts || { align : [] }; if ( opts.align === undefined ) opts.align = []; // compute row length if ( table.length === 0 ) return; // output stream stream = stream || process.stdout; var cursor = ansi(stream); var numCols = table.reduce(function (maxCols, col) { return ( col.length > maxCols ) ? col.length : maxCols; }, 0); var maxColumnLengths = Array(numCols); for ( var i = 0; i < numCols; i++ ) maxColumnLengths[i] = 0; table.map(function (row) { var i = 0; for ( ; i < numCols; i++ ) { if ( row[i] !== undefined && row[i].length > maxColumnLengths[i] ) { maxColumnLengths[i] = row[i].length; } } }); // print table var output = []; var segments; table.forEach(function (row, indexRow) { row.forEach(function (col, indexCol) { var align = ( opts.headerAlign && indexRow === 0 ) ? opts.headerAlign : opts.align[indexCol]; segments = padSegments(col.toString(), maxColumnLengths[indexCol], align); stream.write(segments.left); if ( col._color ) { cursor[col._color](); } if ( col._styles ) { col._styles.forEach( function (style) { cursor[style](); }); } stream.write(col.toString()); cursor.reset(); stream.write(segments.right); if ( indexCol < row.length-1 ) stream.write(opts.separator || " "); }); stream.write("\n"); }); if ( stream != process.stdout ) stream.end(); } module.exports = exports = printTable;ansi-color-table-1.0.1/lib/000077500000000000000000000000001315223007300154065ustar00rootroot00000000000000ansi-color-table-1.0.1/lib/padsegments.js000066400000000000000000000013701315223007300202570ustar00rootroot00000000000000module.exports = exports = function (str, padLen, align, padChar) { var left = ""; var right = ""; if ( str.length >= padLen ) return { left: left, right: right }; if ( padChar === undefined ) padChar = " "; if ( padChar.length > 1 ) padChar = padChar.substr(0, 1); switch ( align ) { case "center": var availableSlots = padLen - str.length; right = Math.ceil(availableSlots / 2); left = availableSlots - right; right = Array(right+1).join(padChar); left = Array(left+1).join(padChar); break; case "right": left = Array(padLen + 1 - str.length).join(padChar); break; default: right = Array(padLen + 1 - str.length).join(padChar); break; } return { left: left, right: right }; };ansi-color-table-1.0.1/package.json000066400000000000000000000011241315223007300171240ustar00rootroot00000000000000{ "name": "ansi-color-table", "version": "1.0.1", "description": "Borderless tables for console with ansi colors and formatting support", "main": "index.js", "scripts": { "test": "tap ./test", "start": "node index.js" }, "author": "Quim Calpe (https://github.com/quimcalpe)", "homepage": "https://github.com/quimcalpe/ansi-color-table", "license": "MIT", "dependencies": { "ansi": "~0.2.1" }, "devDependencies": { "tap": "~0.4.6" }, "repository": { "type": "git", "url": "git://github.com/quimcalpe/ansi-color-table.git" } } ansi-color-table-1.0.1/test/000077500000000000000000000000001315223007300156175ustar00rootroot00000000000000ansi-color-table-1.0.1/test/cells.js000066400000000000000000000016141315223007300172610ustar00rootroot00000000000000var test = require('tap').test; var table = require('../'); var Stream = require('stream'); var tableData = [ [ "Username".blue().underline(), "Email".blue().underline(), "active".blue().underline() ], [ "john.smith", "john@gimail.com".yellow(), "yes".green() ], [ "steve.balmes", "sbalmes@hotma.il".yellow(), "yes".green() ], [ "james.durango", "james.durango@greenvine.com".yellow(), "no".red() ], [ "elisa.polite", "epolite@1234.com".yellow(), "yes".green() ] ]; test('Read content from random cells', function (t) { t.plan(2); var output = new Stream(); output.writable = true; output.write = function (data) { console.log("write"+data); if ( data == tableData[0][0] && data == "Username" ) { t.pass(); } if ( data == tableData[4][1] && data == "epolite@1234.com" ) { t.pass(); } }; output.end = function () {}; table(tableData, {}, output); }); ansi-color-table-1.0.1/test/padsegments.js000066400000000000000000000027621315223007300204760ustar00rootroot00000000000000var test = require('tap').test; var padSegments = require('../lib/padsegments'); test('Left align', function (t) { var string = "Hello World!"; var segments = padSegments(string, 15); t.equal(segments.left, ""); t.equal(segments.right, " "); segments = padSegments(string, 15, "left"); t.equal(segments.left, ""); t.equal(segments.right, " "); t.end(); }); test('Right align', function (t) { var string = "Hello World!"; var segments = padSegments(string, 15, "right"); t.equal(segments.left, " "); t.equal(segments.right, ""); t.end(); }); test('Center align', function (t) { var string = "Hello World!"; var segments = padSegments(string, 15, "center"); t.equal(segments.left, " "); t.equal(segments.right, " "); segments = padSegments(string, 16, "center"); t.equal(segments.left, " "); t.equal(segments.right, " "); t.end(); }); test('String bigger than demanded pad', function (t) { var string = "Hello World!"; var segments = padSegments(string, 10); t.equal(segments.left, ""); t.equal(segments.right, ""); t.end(); }); test('Custom padChar', function (t) { var string = "Hello World!"; var segments = padSegments(string, 15, "left", "*"); t.equal(segments.left, ""); t.equal(segments.right, "***"); t.end(); }); test('Custom padChar discard extra-chars', function (t) { var string = "Hello World!"; var segments = padSegments(string, 15, "left", "AB"); t.equal(segments.left, ""); t.equal(segments.right, "AAA"); t.end(); });