class CalloutRenderer extends Renderer

Traits

Properties

protected string $output

The output to be rendered.

from  Renderer
protected int $minWidth from  DrawsBoxes

Methods

string
reset(string $text)

Reset all colors and styles.

from  Colors
string
bold(string $text)

Make the text bold.

from  Colors
string
dim(string $text)

Make the text dim.

from  Colors
string
italic(string $text)

Make the text italic.

from  Colors
string
underline(string $text)

Underline the text.

from  Colors
string
inverse(string $text)

Invert the text and background colors.

from  Colors
string
hidden(string $text)

Hide the text.

from  Colors
string
strikethrough(string $text)

Strike through the text.

from  Colors
string
black(string $text)

Set the text color to black.

from  Colors
string
red(string $text)

Set the text color to red.

from  Colors
string
green(string $text)

Set the text color to green.

from  Colors
string
yellow(string $text)

Set the text color to yellow.

from  Colors
string
blue(string $text)

Set the text color to blue.

from  Colors
string
magenta(string $text)

Set the text color to magenta.

from  Colors
string
cyan(string $text)

Set the text color to cyan.

from  Colors
string
white(string $text)

Set the text color to white.

from  Colors
string
bgBlack(string $text)

Set the text background to black.

from  Colors
string
bgRed(string $text)

Set the text background to red.

from  Colors
string
bgGreen(string $text)

Set the text background to green.

from  Colors
string
bgYellow(string $text)

Set the text background to yellow.

from  Colors
string
bgBlue(string $text)

Set the text background to blue.

from  Colors
string
bgMagenta(string $text)

Set the text background to magenta.

from  Colors
string
bgCyan(string $text)

Set the text background to cyan.

from  Colors
string
bgWhite(string $text)

Set the text background to white.

from  Colors
string
gray(string $text)

Set the text color to gray.

from  Colors
string
truncate(string $string, int $width)

Truncate a value with an ellipsis if it exceeds the given width.

__construct(Prompt $prompt)

Create a new renderer instance.

from  Renderer
line(string $message)

Render a line of output.

from  Renderer
newLine(int $count = 1)

Render a new line.

from  Renderer
warning(string $message)

Render a warning message.

from  Renderer
error(string $message)

Render an error message.

from  Renderer
hint(string $message)

Render an hint message.

from  Renderer
when(mixed $value, callable $callback, callable|null $default = null)

Apply the callback if the given "value" is truthy.

from  Renderer
string
__toString()

Render the output with a blank line above and below.

from  Renderer
int
longest(array $lines, int $padding = 0)

Get the length of the longest line.

string
pad(string $text, int $length, string $char = ' ')

Pad text ignoring ANSI escape sequences.

string
replaceLastVisibleGrapheme(string $line, string $replacement)

Replace the last visible grapheme while preserving trailing formatting.

string
stripEscapeSequences(string $text)

Strip ANSI escape sequences from the given text.

string
mbWordwrap(string $string, int $width = 75, string $break = "\n", bool $cut_long_words = false)

Multi-byte version of wordwrap.

array
ansiWordwrap(string $text, int $width, bool $cutLongWords = false)

Word wrap text while preserving ANSI escape sequences.

array
parseAnsiText(string $text)

Parse text into segments with their associated ANSI codes.

void
updateSgrState(array $activeSgr, string $escape)

Update the bounded set of active SGR attributes.

box(string $title, string $body, string $footer = '', string $color = 'gray', string $info = '')

Draw a box.

string
__invoke(Callout $prompt)

Render the callout.

string|array
resolvePart(string|ElementContract $part)

Resolve a part of the callout content into a string or array of strings.

array
renderBulletedList(BulletedList $part)

Render a bulleted list element.

array
renderNumberedList(NumberedList $part)

Render a numbered list element.

array
renderKeyValueList(KeyValueList $part)

Render a key-value list element.

string
renderLink(Link $part)

Render a link element.

string
autoFormat(string $text)

Auto-format the text by applying styles to specific patterns, such as inline code blocks.

Details

in Colors at line 12
string reset(string $text)

Reset all colors and styles.

Parameters

string $text

Return Value

string

in Colors at line 20
string bold(string $text)

Make the text bold.

Parameters

string $text

Return Value

string

in Colors at line 28
string dim(string $text)

Make the text dim.

Parameters

string $text

Return Value

string

in Colors at line 36
string italic(string $text)

Make the text italic.

Parameters

string $text

Return Value

string

in Colors at line 44
string underline(string $text)

Underline the text.

Parameters

string $text

Return Value

string

in Colors at line 52
string inverse(string $text)

Invert the text and background colors.

Parameters

string $text

Return Value

string

in Colors at line 60
string hidden(string $text)

Hide the text.

Parameters

string $text

Return Value

string

in Colors at line 68
string strikethrough(string $text)

Strike through the text.

Parameters

string $text

Return Value

string

in Colors at line 76
string black(string $text)

Set the text color to black.

Parameters

string $text

Return Value

string

in Colors at line 84
string red(string $text)

Set the text color to red.

Parameters

string $text

Return Value

string

in Colors at line 92
string green(string $text)

Set the text color to green.

Parameters

string $text

Return Value

string

in Colors at line 100
string yellow(string $text)

Set the text color to yellow.

Parameters

string $text

Return Value

string

in Colors at line 108
string blue(string $text)

Set the text color to blue.

Parameters

string $text

Return Value

string

in Colors at line 116
string magenta(string $text)

Set the text color to magenta.

Parameters

string $text

Return Value

string

in Colors at line 124
string cyan(string $text)

Set the text color to cyan.

Parameters

string $text

Return Value

string

in Colors at line 132
string white(string $text)

Set the text color to white.

Parameters

string $text

Return Value

string

in Colors at line 140
string bgBlack(string $text)

Set the text background to black.

Parameters

string $text

Return Value

string

in Colors at line 148
string bgRed(string $text)

Set the text background to red.

Parameters

string $text

Return Value

string

in Colors at line 156
string bgGreen(string $text)

Set the text background to green.

Parameters

string $text

Return Value

string

in Colors at line 164
string bgYellow(string $text)

Set the text background to yellow.

Parameters

string $text

Return Value

string

in Colors at line 172
string bgBlue(string $text)

Set the text background to blue.

Parameters

string $text

Return Value

string

in Colors at line 180
string bgMagenta(string $text)

Set the text background to magenta.

Parameters

string $text

Return Value

string

in Colors at line 188
string bgCyan(string $text)

Set the text background to cyan.

Parameters

string $text

Return Value

string

in Colors at line 196
string bgWhite(string $text)

Set the text background to white.

Parameters

string $text

Return Value

string

in Colors at line 204
string gray(string $text)

Set the text color to gray.

Parameters

string $text

Return Value

string

in Truncation at line 14
protected string truncate(string $string, int $width)

Truncate a value with an ellipsis if it exceeds the given width.

Parameters

string $string
int $width

Return Value

string

in Renderer at line 25
__construct(Prompt $prompt)

Create a new renderer instance.

Parameters

Prompt $prompt

in Renderer at line 32
protected Renderer line(string $message)

Render a line of output.

Parameters

string $message

Return Value

Renderer

in Renderer at line 42
protected Renderer newLine(int $count = 1)

Render a new line.

Parameters

int $count

Return Value

Renderer

in Renderer at line 52
protected Renderer warning(string $message)

Render a warning message.

Parameters

string $message

Return Value

Renderer

in Renderer at line 60
protected Renderer error(string $message)

Render an error message.

Parameters

string $message

Return Value

Renderer

in Renderer at line 68
protected Renderer hint(string $message)

Render an hint message.

Parameters

string $message

Return Value

Renderer

in Renderer at line 84
protected Renderer when(mixed $value, callable $callback, callable|null $default = null)

Apply the callback if the given "value" is truthy.

Parameters

mixed $value
callable $callback
callable|null $default

Return Value

Renderer

in Renderer at line 98
string __toString()

Render the output with a blank line above and below.

Return Value

string

protected int longest(array $lines, int $padding = 0)

Get the length of the longest line.

Parameters

array $lines
int $padding

Return Value

int

protected string pad(string $text, int $length, string $char = ' ')

Pad text ignoring ANSI escape sequences.

Parameters

string $text
int $length
string $char

Return Value

string

protected string replaceLastVisibleGrapheme(string $line, string $replacement)

Replace the last visible grapheme while preserving trailing formatting.

Parameters

string $line
string $replacement

Return Value

string

protected string stripEscapeSequences(string $text)

Strip ANSI escape sequences from the given text.

Parameters

string $text

Return Value

string

protected string mbWordwrap(string $string, int $width = 75, string $break = "\n", bool $cut_long_words = false)

Multi-byte version of wordwrap.

Parameters

string $string
int $width
string $break
bool $cut_long_words

Return Value

string

in InteractsWithStrings at line 172
protected array ansiWordwrap(string $text, int $width, bool $cutLongWords = false)

Word wrap text while preserving ANSI escape sequences.

Parameters

string $text
int $width
bool $cutLongWords

Return Value

array

in InteractsWithStrings at line 267
protected array parseAnsiText(string $text)

Parse text into segments with their associated ANSI codes.

Parameters

string $text

Return Value

array

in InteractsWithStrings at line 379
protected void updateSgrState(array $activeSgr, string $escape)

Update the bounded set of active SGR attributes.

Parameters

array $activeSgr
string $escape

Return Value

void

in DrawsBoxes at line 20
protected DrawsBoxes box(string $title, string $body, string $footer = '', string $color = 'gray', string $info = '')

Draw a box.

Parameters

string $title
string $body
string $footer
string $color
string $info

Return Value

DrawsBoxes

at line 23
string __invoke(Callout $prompt)

Render the callout.

Parameters

Callout $prompt

Return Value

string

at line 73
protected string|array resolvePart(string|ElementContract $part)

Resolve a part of the callout content into a string or array of strings.

Parameters

string|ElementContract $part

Return Value

string|array

at line 91
protected array renderBulletedList(BulletedList $part)

Render a bulleted list element.

Parameters

BulletedList $part

Return Value

array

at line 126
protected array renderNumberedList(NumberedList $part)

Render a numbered list element.

Parameters

NumberedList $part

Return Value

array

at line 165
protected array renderKeyValueList(KeyValueList $part)

Render a key-value list element.

Parameters

KeyValueList $part

Return Value

array

Render a link element.

Parameters

Link $part

Return Value

string

at line 211
protected string autoFormat(string $text)

Auto-format the text by applying styles to specific patterns, such as inline code blocks.

Parameters

string $text

Return Value

string