class Utils

internal  
 

Constants

MAX_UNBREAKABLE_BYTES

private OSC8_PATTERN

TERMINAL_FORMATTING_PATTERN

The terminal formatting sequences preserved by decorated renderers.

private WRITE_CHUNK_BYTES

The largest chunk offered to a single write attempt.

private MEMORY_STREAM_TYPE

The stream type that always accepts a full write and cannot be selected on.

Methods

static bool
allMatch(array $values, Closure $callback)

Determine if all items in an array match a truth test.

static mixed
last(array $array)

Get the last item from an array or null if it doesn't exist.

static false|int|string
search(array $array, Closure $callback)

Returns the key of the first element in the array that satisfies the callback.

static string
stripEscapeSequences(string $text)

Strip terminal escape sequences and Symfony style tags.

static array
graphemes(string $text)

Split text into bounded Unicode grapheme units.

static int|null
continuedGraphemeBytes(string $text, string $next)

Return the byte length when a fragment continues the trailing grapheme.

static string
sanitizeTerminalFormatting(string $text)

Remove terminal controls other than SGR and OSC 8 formatting.

static string|null
resolveOsc8Link(string $escape)

Resolve a complete OSC 8 sequence to its active hyperlink state.

static void
writeAll(resource $stream, string $payload, float $timeout = 10.0)

Write an entire payload to a stream, waiting up to a timeout for a blocked reader.

Details

at line 39
static bool allMatch(array $values, Closure $callback)

Determine if all items in an array match a truth test.

Parameters

array $values
Closure $callback

Return Value

bool

at line 55
static mixed last(array $array)

Get the last item from an array or null if it doesn't exist.

Parameters

array $array

Return Value

mixed

Returns the key of the first element in the array that satisfies the callback.

Parameters

array $array
Closure $callback

Return Value

false|int|string

at line 79
static string stripEscapeSequences(string $text)

Strip terminal escape sequences and Symfony style tags.

Parameters

string $text

Return Value

string

at line 96
static array graphemes(string $text)

Split text into bounded Unicode grapheme units.

Parameters

string $text

Return Value

array

at line 125
static int|null continuedGraphemeBytes(string $text, string $next)

Return the byte length when a fragment continues the trailing grapheme.

Parameters

string $text
string $next

Return Value

int|null

at line 139
static string sanitizeTerminalFormatting(string $text)

Remove terminal controls other than SGR and OSC 8 formatting.

Parameters

string $text

Return Value

string

Resolve a complete OSC 8 sequence to its active hyperlink state.

Parameters

string $escape

Return Value

string|null

at line 172
static void writeAll(resource $stream, string $payload, float $timeout = 10.0)

Write an entire payload to a stream, waiting up to a timeout for a blocked reader.

The stream is driven in non-blocking mode because stream_set_timeout() only governs reads. A blocking write into a full buffer parks in the underlying send syscall on macOS and BSD, where no timeout applies and no signal can interrupt it, so the caller would wait for the reader forever.

Parameters

resource $stream
string $payload
float $timeout

seconds to wait for a stalled reader to accept more output

Return Value

void