PHPackages                             eznio/tabler - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [CLI &amp; Console](/categories/cli)
4. /
5. eznio/tabler

ActiveLibrary[CLI &amp; Console](/categories/cli)

eznio/tabler
============

CLI ASCII table drawer

1.0.3(8y ago)0312↓100%1MITPHPPHP &gt;=5.4.0

Since Sep 9Pushed 8y ago1 watchersCompare

[ Source](https://github.com/eznio/tabler)[ Packagist](https://packagist.org/packages/eznio/tabler)[ Docs](https://github.com/eznio/tabler)[ RSS](/packages/eznio-tabler/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (3)Versions (5)Used By (0)

ASCII-table formatter and renderer
==================================

[](#ascii-table-formatter-and-renderer)

Overview
--------

[](#overview)

Simple (in the beginning) helper which can format and render ASCII tables for CLI tools.

Basic usage:

```
$tabler = (new \eznio\tabler\Tabler())
    ->setHeaders(['a' => 'Column A', 'b' => 'Column B', 'c' => 'Column C'])
    ->setData([
        ['a' => '123', 'b' => '456', 'c' => '7'],
        ['a' => '123', 'b' => '456', 'c' => '7'],
        ['a' => '123', 'b' => '456', 'c' => '7']
    ])
    ->setRenderer(new \eznio\tabler\renderers\MysqlStyleRenderer());
```

which produces

```
+----------+----------+----------+
| Column A | Column B | Column C |
+----------+----------+----------+
| 123      | 456      | 7        |
| 123      | 456      | 7        |
| 123      | 456      | 7        |
+----------+----------+----------+

```

Basic classes and interfaces
----------------------------

[](#basic-classes-and-interfaces)

Classes:

- `Tabler` - facade class for the whole package. Holds some shortcut calls for setting table data, generating, styling and rendering
- `Composer` - scans headers and data arrays, gathers maximum lengths, composes column structure and tries to get column names if missing
- `LayoutBuilder` - gets `Composer` with parsed table data and generates TableLayout structure(-s) (see below)
- `Styler` - helper to set styles (bg color, fg color, some text styles) for the line of text
- `Element` - basic class of TableLayout structure

Interfaces:

- `Renderer` - interface to be implemented by rendering classes

Table elements
--------------

[](#table-elements)

### What and what for

[](#what-and-what-for)

TableLayout is a metastructure representing the whole table and its elements - rows and cells.

This one is useful mostly for styling purposes. For example, if we want to display 2nd column in red color:

```
$layout = $tabler->getTableLayout();
$layout->getHeaderLine()->getHeaderCell('column2')
    ->setForegroundColor(\eznio\tabler\references\ForegroundColors::RED);
```

### Schema

[](#schema)

Overall elements layout and nesting:

```
+-----------------------------------------+
| TableLayout                             |
|                                         |
| +-------------------------------------+ |
| | HeaderLine                          | |
| |                                     | |
| | +------------+ +------------+       | |
| | | HeaderCell | | HeaderCell | . . . | |
| | +------------+ +------------+       | |
| +-------------------------------------+ |
|                                         |
| +-------------------------------------+ |
| | DataGrid                            | |
| |                                     | |
| | +---------------------------------+ | |
| | | DataRow                         | | |
| | |                                 | | |
| | | +----------+ +----------+       | | |
| | | | DataCell | | DataCell | . . . | | |
| | | +----------+ +----------+       | | |
| | +---------------------------------+ | |
| |                                     | |
| | +---------------------------------+ | |
| | | DataRow                         | | |
| | |                                 | | |
| | | +----------+ +----------+       | | |
| | | | DataCell | | DataCell | . . . | | |
| | | +----------+ +----------+       | | |
| | +---------------------------------+ | |
| |                                     | |
| |  . . .                              | |
| +-------------------------------------+ |
+-----------------------------------------+

```

### Short element reference

[](#short-element-reference)

- `TableLayout` - the whole table. Border colors are set here
- `HeaderLine` - first row with column headers
- `HeaderCell` - single heading row's cell.
- `DataGrid` - overall data part
- `DataRow` - single data row
- `DataCell` - single data cell

### Getting/setting child elements

[](#gettingsetting-child-elements)

1. Getting TableLayout:

```
/** @var Tabler $tabler */
$tableLayout = $tabler->getTableLayout();
```

2. Getting top elements:

```
/** @var HeaderLine $headerLine */
$headerLine = $tableLayout->getheaderLine();

/** @var DataGrid $dataGrid */
$dataGrid = $tableLayout->getDataGrid();
```

3. Getting HeaderLine cells

```
/** @var HeaderCell $headerCellA */
$headerCellA = $headerLine->getHeaderCell('a');
```

4. Getting data rows and cells

```
/** @var DataRow $firstDataRow */
$firstDataRow = $dataGrid->getRow(0);

/** @var DataCell $dataCellA */
$dataCellA = $firstDataRow->getCell('a');
```

Facade public API reference
---------------------------

[](#facade-public-api-reference)

```
$tabler = new \eznio\tabler\Tabler();
```

Main part:

- `setData(array $data)`

    Sets table data 2-level nested array:

    - Top-level array elements are treated as rows and should be arrays too
    - Row elements are considered cells. Their array keys are column IDs
- `setHeaders(array $headers)`

    Sets table headers array. Its elements are counted as column headers, and their array keys are column IDs.
- `getTableLayout()`

    Returns TableLayout structure. If no one is built - builds it before returning.
- `setRenderer(Renderer $renderer)`

    Sets rendering class to render table
- `setGuessHeaderNames(bool $guessHeaderNames)`

    Setting $guessHeaderNames to true means using columnd IDs as header titles if no titles are provided

    If $guessHeaderNames is set to false - column names without provided titles are rendered as empty strings
- `render(TableLayout $tableLayout = null)`

    Renders current (if no TableLayout is passed), or given TableLayout component into table string representation and returns it

Styling shortcuts:

Descriptions are available in source code if needed

- `setBorderBackgroundColor($color)`
- `getBorderBackgroundColor()`
- `setBorderForegroundColor($color)`
- `getBorderForegroundColor()`
- `setHeadingLineStyles(array $styles)`
- `getHeadingLineStyles()`
- `setHeadingCellStyles($columnId, array $styles)`
- `getHeadingCellStyles($columnId)`
- `setColumnStyles($columnId, array $styles)`
- `setColumnTextAlignment($columnId, $alignment)`
- `setColumnMinLength($columnId, $minLength)`
- `setColumnLeftPadding($columnId, $leftPadding)`
- `getColumnLeftPadding($columnId)`
- `setColumnRightPadding($columnId, $rightPadding)`
- `getColumnRightPadding($columnId)`
- `setColumnPadding($columnId, $padding)`
- `setRowStyles($rowId, array $styles)`
- `setOddRowsStyles(array $styles)`
- `setEvenRowsStyles(array $styles)`
- `getRowStyles($rowId)`
- `setCellStyles($columnId, $rowId, array $styles)`
- `getCellStyles($columnId, $rowId)`
- `setCellTextAlignment($columnId, $rowId, $alignment)`
- `getCellTextAlignment($columnId, $rowId)`

Styling
-------

[](#styling)

### Style arrays

[](#style-arrays)

Styles can be set as single value:

```
$cell->setStyle(ForegroundColors::RED);
```

or array:

```
$cell->setStyle([
    ForegroundColors::RED,
    BacgroundColors::WHITE,
    TextStyles::BOLD
]);
```

If more that one array element is set from the bg or fg colors - last one is being used. Text styles are free to use in cojunction.

### Style reference classes

[](#style-reference-classes)

- `references\ForegroundColors`
- `references\BackgroundColors`
- `references\TextStyles`

### Styling elements

[](#styling-elements)

- `TableLayout` - set border bg and fg colors
- `HeaderLine` - set bg/fg/text styles for the whole headers, can be override at `HeaderCell` level
- `HeaderCell` - set bg/fg/text styles, minimum length, text alignment and paddings for single header cell, overrides `HeaderLine`-level settings
- `DataRow` - set bg/fg/text styles and text alignment for single data row, can be override in `DataCell`
- `DataCell` - set bg/fg/text styles, minimum length, text alignment and paddings for single data cell, overrides `DataRow`-level settings

Renderers
---------

[](#renderers)

### Table data

[](#table-data)

In examples in this part the following Tabler setup will be used:

```
$tabler = (new \eznio\tabler\Tabler())
    ->setHeaders(['a' => 'Column A', 'b' => 'Column B', 'c' => 'Column C'])
    ->setData([
        ['a' => '123', 'b' => '456', 'c' => '7'],
        ['a' => '234', 'b' => '567', 'c' => '8'],
        ['a' => '345', 'b' => '6789', 'c' => '']
    ]);
```

### MySQL-style renderer

[](#mysql-style-renderer)

```
$tabler->setRenderer(new MysqlStyleRenderer());
```

```
+----------+----------+----------+
| Column A | Column B | Column C |
+----------+----------+----------+
| 123      | 456      | 7        |
| 234      | 567      | 8        |
| 345      | 6789     |          |
+----------+----------+----------+

```

### MC-style renderer

[](#mc-style-renderer)

```
$tabler->setRenderer(new McStyleRenderer());
```

```
╔══════════╦══════════╦══════════╗
║ Column A ║ Column B ║ Column C ║
╠══════════╬══════════╬══════════╣
║ 123      ║ 456      ║ 7        ║
║ 234      ║ 567      ║ 8        ║
║ 345      ║ 6789     ║          ║
╚══════════╩══════════╩══════════╝

```

### "Clear" styled renderer

[](#clear-styled-renderer)

```
$tabler->setRenderer(new ClearStyleRenderer());
```

```
 Column A  Column B  Column C

 123       456       7
 234       567       8
 345       6789

```

### "Single line" styled renderer

[](#single-line-styled-renderer)

```
$tabler->setRenderer(new SingleLineRenderer());
```

```
┌──────────┬──────────┬──────────┐
│ Column A │ Column B │ Column C │
├──────────┼──────────┼──────────┤
│ 123      │ 456      │ 7        │
│ 234      │ 567      │ 8        │
│ 345      │ 6789     │          │
└──────────┴──────────┴──────────┘

```

More radical example
--------------------

[](#more-radical-example)

```
$tabler = (new \eznio\tabler\Tabler())
    ->setHeaders(['a' => 'Column A', 'b' => 'Column B', 'c' => 'Column C'])
    ->setData([
        ['a' => '123', 'b' => '456', 'c' => '7'],
        ['a' => '234', 'b' => '567', 'c' => '8'],
        ['a' => '345', 'b' => '6789', 'c' => '']
    ])
    ->setRenderer(new \eznio\tabler\renderers\SingleLineRenderer())
    ->setGuessHeaderNames(false);

$layout = $tabler->getTableLayout();

$layout->getHeaderLine()->getHeaderCell('a')
    ->setTextAlignment(\eznio\tabler\references\TextAlignments::TEXT_ALIGN_LEFT)
    ->setForegroundColor(\eznio\styler\references\ForegroundColors::RED);

$layout->getHeaderLine()->getHeaderCell('b')
    ->setTextAlignment(\eznio\tabler\references\TextAlignments::TEXT_ALIGN_CENTER)
    ->setForegroundColor(\eznio\styler\references\ForegroundColors::YELLOW);

$layout->getHeaderLine()->getHeaderCell('c')
    ->setTextAlignment(\eznio\tabler\references\TextAlignments::TEXT_ALIGN_RIGHT)
    ->setForegroundColor(\eznio\styler\references\ForegroundColors::GREEN);

$layout->getDataGrid()->getRow(1)->getCell('c')
    ->setTextAlignment(\eznio\tabler\references\TextAlignments::TEXT_ALIGN_CENTER);

echo $tabler->render($layout);
```

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~90 days

Total

4

Last Release

3259d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d81a9338efaa22b0fd0e98575091f89f86190ab34354e3a555655a7b5a2a6f75?d=identicon)[evgeny-zinder](/maintainers/evgeny-zinder)

---

Top Contributors

[![evgeny-zinder](https://avatars.githubusercontent.com/u/6049024?v=4)](https://github.com/evgeny-zinder "evgeny-zinder (12 commits)")

---

Tags

cliconsoleasciitable

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/eznio-tabler/health.svg)

```
[![Health](https://phpackages.com/badges/eznio-tabler/health.svg)](https://phpackages.com/packages/eznio-tabler)
```

###  Alternatives

[symfony/console

Eases the creation of beautiful and testable command line interfaces

9.8k1.1B11.2k](/packages/symfony-console)[nunomaduro/collision

Cli error handling for console/command-line PHP applications.

4.6k331.8M8.4k](/packages/nunomaduro-collision)[nunomaduro/termwind

It's like Tailwind CSS, but for the console.

2.5k239.8M285](/packages/nunomaduro-termwind)[wp-cli/php-cli-tools

Console utilities for PHP

68325.0M364](/packages/wp-cli-php-cli-tools)[php-school/cli-menu

A command line menu helper in PHP

2.0k1.1M27](/packages/php-school-cli-menu)[seld/cli-prompt

Allows you to prompt for user input on the command line, and optionally hide the characters they type

24725.8M17](/packages/seld-cli-prompt)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
