Documentation

OutputFormatter
in package
implements WrappableOutputFormatterInterface

Formatter class for console output.

Tags
author

Konstantin Kudryashov ever.zet@gmail.com

Roland Franssen franssen.roland@gmail.com

Table of Contents

Interfaces

WrappableOutputFormatterInterface
Formatter interface for console output that supports word wrapping.

Constants

ANSI_PATTERN  : mixed = '\x1B(?:\[[0-9;:]*m|\]8;[^;]*;[^\x1B]*\x1B\\\\)'
ANSI_REGEX  : mixed = '/' . self::ANSI_PATTERN . '/'

Properties

$charWidths  : array<string|int, mixed>
$decorated  : bool
$styles  : array<string|int, mixed>
$styleStack  : OutputFormatterStyleStack

Methods

__clone()  : mixed
__construct()  : mixed
Initializes console output formatter.
escape()  : string
Escapes "<" and ">" special chars in given text.
format()  : string|null
Formats a message according to the given styles.
formatAndWrap()  : string
Formats a message according to the given styles, wrapping at `$width` (0 means no wrapping).
getStyle()  : OutputFormatterStyleInterface
Gets style options from style with specified name.
getStyleStack()  : OutputFormatterStyleStack
hasStyle()  : bool
Checks if output formatter has style with specified name.
isDecorated()  : bool
Whether the output will decorate messages.
setDecorated()  : void
Sets the decorated flag.
setStyle()  : void
Sets a new style.
addLineBreaks()  : string
applyCurrentStyle()  : string
Applies current style from stack to text, if must be applied.
createStyleFromString()  : OutputFormatterStyleInterface|null
Tries to create new style instance from string.
getTokens()  : iterable<string|int, mixed>
getWidths()  : array<int, int>
Returns the number of columns of each visible character, or an empty array when none uses more than one column.
substr()  : string
wordwrap()  : string
Wraps a mask like wordwrap() does when cutting long words, but using the number of columns of each character.

Constants

ANSI_PATTERN

private mixed ANSI_PATTERN = '\x1B(?:\[[0-9;:]*m|\]8;[^;]*;[^\x1B]*\x1B\\\\)'

ANSI_REGEX

private mixed ANSI_REGEX = '/' . self::ANSI_PATTERN . '/'

Properties

Methods

escape()

Escapes "<" and ">" special chars in given text.

public static escape(string $text) : string
Parameters
$text : string
Return values
string

format()

Formats a message according to the given styles.

public format(string|null $message) : string|null
Parameters
$message : string|null
Return values
string|null

formatAndWrap()

Formats a message according to the given styles, wrapping at `$width` (0 means no wrapping).

public formatAndWrap(string|null $message, int $width) : string
Parameters
$message : string|null
$width : int
Return values
string

hasStyle()

Checks if output formatter has style with specified name.

public hasStyle(string $name) : bool
Parameters
$name : string
Return values
bool

isDecorated()

Whether the output will decorate messages.

public isDecorated() : bool
Return values
bool

setDecorated()

Sets the decorated flag.

public setDecorated(bool $decorated) : void
Parameters
$decorated : bool

addLineBreaks()

private addLineBreaks(string $text, int $width) : string
Parameters
$text : string
$width : int
Return values
string

applyCurrentStyle()

Applies current style from stack to text, if must be applied.

private applyCurrentStyle(string $text, int $width, int &$currentLineLength, bool &$lineBreak) : string
Parameters
$text : string
$width : int
$currentLineLength : int
$lineBreak : bool
Return values
string

getTokens()

private getTokens(string $text) : iterable<string|int, mixed>
Parameters
$text : string
Return values
iterable<string|int, mixed>

getWidths()

Returns the number of columns of each visible character, or an empty array when none uses more than one column.

private getWidths(string $text) : array<int, int>
Parameters
$text : string
Return values
array<int, int>

substr()

private substr(string $text, int $from[, int|null $length = null ]) : string
Parameters
$text : string
$from : int
$length : int|null = null
Return values
string

wordwrap()

Wraps a mask like wordwrap() does when cutting long words, but using the number of columns of each character.

private wordwrap(string $mask, int $width, array<int, int> $widths) : string
Parameters
$mask : string
$width : int
$widths : array<int, int>
Return values
string
On this page

Search results