| Server IP : 185.11.201.71 / Your IP : 192.168.7.18 Web Server : Apache/2.4.29 (Ubuntu) System : Linux tech-virtual-machine 4.15.0-213-generic #224-Ubuntu SMP Mon Jun 19 13:30:12 UTC 2023 x86_64 User : tech ( 1000) PHP Version : 7.4.28 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : OFF | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /usr/lib/nodejs/ansi-color-table/ |
Upload File : |
var 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;