Last Updated: February 25, 2016
·
752
· joetannenbaum

Style terminal output when running PHP

If you're running PHP from the command line, it's useful to be able to style the output in some way to differentiate and debug.

Whether it's outputting different colors, displaying information as tables, or even adding a progress bar for a task, CLImate can help you out.

https://github.com/joetannenbaum/climate

Some examples:

$climate->red('Whoa now this text is red.');
$climate->bold('Bold? Wow!');
$climate->lightGreen('It\'s not easy being (light) green.');
$climate->backgroundRed('Whoa now this background is red.');
$climate->backgroundRedBold('Whoa now this background is red and bold.');

And for something a little more complex:

$climate->table([
    [
      'Walter White',
      'Father',
      'Teacher',
    ],
    [
      'Skyler White',
      'Mother',
      'Accountant',
    ],
    [
      'Walter White Jr.',
      'Son',
      'Student',
    ],
]);

You get this:

------------------------------------------
| Walter White     | Father | Teacher    |
------------------------------------------
| Skyler White     | Mother | Accountant |
------------------------------------------
| Walter White Jr. | Son    | Student    |
------------------------------------------

There are a bunch of different options, including:

$climate->border();

$climate->json([
  'name' => 'Gary',
  'age'  => 52,
  'job'  => 'Engineer',
]);

$climate->dump([
  'This',
  'That',
  'Other Thing',
]);

$climate->flank('Look at me. Now.');

For installation and documentation, head over here.