Socket
Socket
Sign inDemoInstall

tty-table

Package Overview
Dependencies
15
Maintainers
1
Versions
89
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.0 to 2.0.1

automattic-cli-table.js

2

examples/auttomatic-cli-table-tests.js
//var Table = require('cli-table');
var Table = require('../cli-table-adapter.js');
var Table = require('../automattic-cli-table.js');

@@ -4,0 +4,0 @@ /* col widths */

@@ -15,1 +15,6 @@ var baseline = {

},500)
process.stdout.on('error',function(){
process.exit(1);
});

@@ -12,3 +12,2 @@ /**

// Project configuration.

@@ -192,3 +191,2 @@ grunt.initConfig({

grunt.loadNpmTasks('grunt-contrib-uglify');

@@ -195,0 +193,0 @@ grunt.loadNpmTasks('grunt-shell');

{
"name": "tty-table",
"version": "2.0.0",
"version": "2.0.1",
"description": "Command line table generator.",
"main": "src/main.js",
"bin": {
"tty-table": "src/terminal-adapter.js"
},
"preferGlobal": false,
"scripts": {

@@ -15,2 +19,3 @@ "test": "grunt t"

"table",
"table in bash",
"cli-table",

@@ -24,3 +29,3 @@ "terminal table",

"author": "Tecfu",
"license": "GPL3",
"license": "LGPL-3.0",
"bugs": {

@@ -27,0 +32,0 @@ "url": "https://github.com/tecfu/tty-table/issues"

@@ -9,5 +9,12 @@ # tty-table

- Nodejs
- As a terminal application:
```
$ sudo apt-get install nodejs //if not already installed
$ npm install tty-table -g
```
- As a Nodejs module:
```
npm install tty-table

@@ -26,6 +33,13 @@ ```

## Why
## Why would someone do such a thing?
- Automatic text wrapping
- Colors (nodejs)
### Drop-in replacement for [Automattic/cli-table](docs/automattic-cli-table.md):
- Fixes these known issues with Automattic/cli-table:
- Automatic text wrapping
- [Supports Asian characters](https://github.com/tecfu/tty-table/pull/5)
- [Automatically resizes to terminal width](https://github.com/tecfu/tty-table/issues/4)
### Beyond that, the native API also supports:
- Optional callbacks on column values

@@ -35,6 +49,6 @@ - Header, body column alignment

- Pass rows as either arrays or objects
- [Works in the browser as well as nodejs](http://htmlpreview.github.io/?https://raw.githubusercontent.com/tecfu/tty-table/master/examples/browser-example.html)
- [Supports Asian characters](https://github.com/tecfu/tty-table/pull/5)
- [Automatically resizes to terminal width](https://github.com/tecfu/tty-table/issues/4)
- [Footer support](https://github.com/tecfu/tty-table/issues/6)
- Colors (not supported in browser)
- [Footer](https://github.com/tecfu/tty-table/issues/6)
- [Works in the browser as well as nodejs](https://cdn.rawgit.com/tecfu/tty-table/master/examples/browser-example.html)
- [Can be run as a standalone terminal application](docs/terminal.md)

@@ -44,8 +58,8 @@ ## Example Output

### Terminal
![Terminal Example](examples/images/node-example.png "Terminal Example")
![Terminal Example](https://cloud.githubusercontent.com/assets/7478359/15691679/07142030-273f-11e6-8f1e-25728d558a2d.png "Terminal Example")
### Browser & Browser Console
![Browser Console Example](examples/images/browser-example.png "Browser Console Example")
![Browser Console Example](https://cloud.githubusercontent.com/assets/7478359/15691676/043a47ea-273f-11e6-8889-df03e8a25e26.png "Browser Console Example")
[Working example](http://htmlpreview.github.io/?https://raw.githubusercontent.com/tecfu/tty-table/master/examples/browser-example.html)
[Working example](https://cdn.rawgit.com/tecfu/tty-table/master/examples/browser-example.html)

@@ -59,3 +73,3 @@ > Note that neither ASCI colors nor default borders are rendered in the browser.

## Example Usage
## Default API Usage

@@ -194,3 +208,3 @@ <!--EXAMPLE-USAGE-->

## API Reference
## Default API Reference
<!--API-REF-->

@@ -293,2 +307,2 @@

Copyright 2015, Tecfu.
Copyright 2015-2016, Tecfu.

@@ -1,77 +0,102 @@

module.exports = (function(){
//get arguments
var argv = require('minimist')(process.argv.slice(2));
#!/usr/bin/env node
//note that this is the first run
var alreadyRendered = false;
var Chalk = require('chalk');
var sendError = function(msg){
msg = '\ntty-table says: ' + msg + '\n';
console.log(msg);
process.exit(1);
};
//check format of input data
var dataFormat = 'csv' //default
//get arguments
var argv = require('minimist')(process.argv.slice(2));
if(argv.format){
dataFormat = argv.format
}
//check if help called
if(argv.help){
var msg = '\n';
msg += Chalk.bgBlack.green('OPTIONS')+'\n';
msg += '-------\n\n';
msg += '--format (JSON,csv)\n';
console.log(msg);
process.exit();
}
switch(true){
case(dataFormat==='json'):
break;
default:
var csv = require('csv');
}
//note that this is the first run
var alreadyRendered = false;
//because diffent dataFormats
var runTable = function(input){
var header = [],
body = input,
//footer = [],
options = {};
//check format of input data
var dataFormat = 'csv' //default
var Table = require('./public.js');
var t1 = Table.setup(header,body,options);
//wipe existing if already rendered
if(alreadyRendered){
//delete to end of terminal
console.log('\u001b[0J');
if(argv.format){
dataFormat = argv.format
}
//move cursor up number of spaces equal to table height + 1
console.log('\u001b['+(input.length+7)+'A');
}
else{
alreadyRendered = true;
}
console.log(t1.render());
};
switch(true){
case(dataFormat.toString().match(/json/i) !== null):
dataFormat = 'json';
break;
default:
var csv = require('csv');
}
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
//because diffent dataFormats
var runTable = function(input){
var header = [],
body = input,
//footer = [],
options = {};
//handle dataFormats
switch(true){
case(dataFormat==='json'):
var Table = require('./public.js');
var t1 = Table.setup(header,body,options);
//wipe existing if already rendered
if(alreadyRendered){
//delete to end of terminal
console.log('\u001b[0J');
//move cursor up number of spaces equal to table height + 1
console.log('\u001b['+(input.length+7)+'A');
}
else{
alreadyRendered = true;
}
console.log(t1.render());
};
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
//handle dataFormats
switch(true){
case(dataFormat==='json'):
try {
var data = JSON.parse(chunk);
if(data === null){
console.error("JSON parse error");
process.exit();
}
catch(e){
var msg = "JSON parse error.";
msg = Chalk.bgRed.white(msg);
msg = msg + "\n\nPlease check to make sure that your input data consists of JSON or specify a different format with the --format flag.";
sendError(msg);
}
runTable(data);
break;
default:
csv.parse(chunk, function(err, data){
//validate csv
if(typeof data === 'undefined'){
var msg = "CSV parse error.";
msg = Chalk.bgRed.white(msg);
msg = msg + "\n\nPlease check to make sure that your input data consists of comma separated values or specify a different format with the --format flag.";
sendError(msg);
}
runTable(data);
break;
default:
csv.parse(chunk, function(err, data){
//validate csv
if(typeof data === 'undefined'){
console.error("CSV parse error");
process.exit();
}
runTable(data);
});
}
});
});
}
});
process.stdin.on('end', function() {
//nothing
});
}())
process.stdin.on('end', function() {
//nothing
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc