Giter Club home page Giter Club logo

clitable's Introduction

CLI Table Output for PHP

Example

  • Nice table output of data rows
  • Columns adjust to data size
  • Data manipulators for fields, formats raw data to a nice display output
  • Colors! When specifying a color, choose from these strings: blue, red, green, yellow, black, magenta, cyan, white, grey
  • Support for multi-line values.

Installing via Composer

# Install Composer
curl -sS https://getcomposer.org/installer | php

Next, run the Composer command to install the latest stable version:

composer.phar require jc21/clitable

After installing, you need to require Composer's autoloader:

require 'vendor/autoload.php';

Using

Class documentation

See the tests folder for some examples, but basically here's how to use it:

use jc21\CliTable;

// $data used below is an array of rows with fields. See tests/data.php for an example.

$table = new CliTable;
$table->setTableColor('blue');
$table->setHeaderColor('cyan');
$table->addField('First Name', 'firstName',    false,                               'white');
$table->addField('Last Name',  'lastName',     false,                               'white');
$table->addField('DOB',        'dobTime',      new CliTableManipulator('datelong'));
$table->addField('Admin',      'isAdmin',      new CliTableManipulator('yesno'),    'yellow');
$table->addField('Last Seen',  'lastSeenTime', new CliTableManipulator('nicetime'), 'red');
$table->addField('Expires',    'expires',      new CliTableManipulator('duetime'),  'green');
$table->injectData($data);
$table->display();

Manipulators

These are the manipulators provided in the package:

  • dollar: Formats 12300.23 to $12,300.23
  • date: Formats unix timestamp 1372132121 to AU date 25-06-2013 (because I'm an Aussie mate)
  • datelong: Formats unix timestamp 1372132121 to 25th June 2013
  • time: Formats unix timestamp 1372132121 to 1:48 pm
  • datetime: Formats unix timestamp 1372132121 to 25th June 2013, 1:48 pm
  • nicetime: Formats unix timestamp 1372132121 to one of the following, depending if it falls on Today or Yesterday or earlier:
    • Today, 1:48 pm
    • Yesterday, 1:48 pm
    • 25th June 2013, 1:48 pm
  • duetime: Formats unix timestamp to x years x days x hours x minutes x seconds
  • nicenumber: Formats 123456 to 123,456
  • month: Formats unix timestamp 1372132121 to June
  • year: Formats unix timestamp 1372132121 to 2013
  • monthyear: Formats unix timestamp 1372132121 to June 2013
  • percent: Formats 54 to 54%
  • yesno: Formats a boolean value to Yes or No
  • text: Strips HTML from the value before returning

If you want to create your own manipulators:

class MyManipulator extends CliTableManipulator {
	public function chucknorris($value)
	{
		return 'Chuck norris said: ' . $value;
	}
}

$table = new CliTable;
$table->setTableColor('blue');
$table->setHeaderColor('cyan');
$table->addField('First Name', 'firstName',    false,                               'white');
$table->addField('Last Name',  'lastName',     false,                               'white');
$table->addField('DOB',        'dobTime',      new CliTableManipulator('datelong'));
$table->addField('Admin',      'isAdmin',      new MyManipulator('chucknorris'),    'yellow');
$table->addField('Last Seen',  'lastSeenTime', new CliTableManipulator('nicetime'), 'red');
$table->addField('Expires',    'expires',      new CliTableManipulator('duetime'),  'green');
$table->injectData($data);
$table->display();

clitable's People

Contributors

biggianteye avatar conrad10781 avatar jc21 avatar jiangbianwanghai avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

clitable's Issues

Does it support real time data?

Hello,

Is it possible to render a table where the fields updates their values in real time according to what's happening in the CLI script?

For instance: 327/4272 records processed, where 327 is incremented for each record.

Thank you.

Tips

I would find usefull:

  • display() returns the number of rows
  • if the table is larger than screen it autoadapts

By the way, good job, thank you.

Table Alignment - Middle of Screen

Hi,

Can you tell me if there is a way to display the table at the middle of the screen, and if not do you think you can add this feature.

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.