Overview

Namespaces

  • None
  • splitbrain
    • phpcli
      • tests

Classes

  • CLI
  • Colors
  • Options
  • PSR3CLI
  • TableFormatter

Exceptions

  • Exception
  • Overview
  • Namespace
  • Class

Class TableFormatter

Class TableFormatter

Output text in multiple columns

Direct known subclasses

splitbrain\phpcli\tests\TableFormatter
Namespace: splitbrain\phpcli
License: MIT
Author: Andreas Gohr andi@splitbrain.org
Located at src/TableFormatter.php
Methods summary
public
# __construct( splitbrain\phpcli\Colors $colors = null )

TableFormatter constructor.

TableFormatter constructor.

Parameters

$colors
public string
# getBorder( )

The currently set border (defaults to ' ')

The currently set border (defaults to ' ')

Returns

string
public
# setBorder( string $border )

Set the border. The border is set between each column. Its width is added to the column widths.

Set the border. The border is set between each column. Its width is added to the column widths.

Parameters

$border
public integer
# getMaxWidth( )

Width of the terminal in characters

Width of the terminal in characters

initially autodetected

Returns

integer
public
# setMaxWidth( integer $max )

Set the width of the terminal to assume (in characters)

Set the width of the terminal to assume (in characters)

Parameters

$max
protected integer
# getTerminalWidth( )

Tries to figure out the width of the terminal

Tries to figure out the width of the terminal

Returns

integer
terminal width, 0 if unknown
protected int[]
# calculateColLengths( array $columns )

Takes an array with dynamic column width and calculates the correct width

Takes an array with dynamic column width and calculates the correct width

Column width can be given as fixed char widths, percentages and a single * width can be given for taking the remaining available space. When mixing percentages and fixed widths, percentages refer to the remaining space after allocating the fixed width

Parameters

$columns

Returns

int[]

Throws

splitbrain\phpcli\Exception
public string
# format( int[] $columns, string[] $texts, array $colors = array() )

Displays text in multiple word wrapped columns

Displays text in multiple word wrapped columns

Parameters

$columns
list of column widths (in characters, percent or '*')
$texts
list of texts for each column
$colors
A list of color names to use for each column. use empty string for default

Returns

string

Throws

splitbrain\phpcli\Exception
protected string
# pad( string $string, integer $len )

Pad the given string to the correct length

Pad the given string to the correct length

Parameters

$string
$len

Returns

string
protected integer
# strlen( $string )

Measures char length in UTF-8 when possible

Measures char length in UTF-8 when possible

Parameters

$string

Returns

integer
protected string
# substr( string $string, integer $start = 0, integer|null $length = null )

Parameters

$string
$start
$length

Returns

string
protected string
# wordwrap( string $str, integer $width = 75, string $break = "\n", boolean $cut = false )

Parameters

$str
$width
$break
$cut

Returns

string

Link

http://stackoverflow.com/a/4988494
Properties summary
protected string $border

border between columns

border between columns

# ' '
protected integer $max

the terminal width

the terminal width

# 74
protected splitbrain\phpcli\Colors $colors

for coloring output

for coloring output

#
API documentation generated by ApiGen