Stream
class Stream extends Prompt
Traits
Constants
| protected OUTPUT_CONTEXT_KEY |
Context key for the output instance override. |
| protected VALIDATE_USING_CONTEXT_KEY |
Context key for the custom validation callback override. |
Properties
| static protected bool | $cursorHidden | Indicates if the cursor has been hidden. |
from Cursor |
| protected Closure>> | $listeners | The registered event listeners. |
from Events |
| static protected bool | $shouldFallback | Whether to fallback to a custom implementation. |
from Fallback |
| static protected array<class-string, Closure(static): mixed> | $fallbacks | The fallback implementations. |
from Fallback |
| static protected bool|null | $interactive | Whether to render the prompt interactively. |
from Interactivity |
| static protected string | $theme | The name of the active theme. |
from Themes |
| static protected Prompt>, class-string<callable&object>>> | $themes | The available themes. |
from Themes |
| string | $state | The current state of the prompt. |
from Prompt |
| string | $error | The error message from the validator. |
from Prompt |
| string | $cancelMessage | The cancel message displayed when this prompt is cancelled. |
from Prompt |
| protected string | $prevFrame | The previously rendered frame. |
from Prompt |
| protected int | $newLinesWritten | How many new lines were written by the last output. |
from Prompt |
| bool|string | $required | Whether user input is required. |
from Prompt |
| Closure|null | $transform | The transformation callback. |
from Prompt |
| mixed | $validate | The validator callback or rules. |
from Prompt |
| static protected Closure|null | $cancelUsing | The cancellation callback. |
from Prompt |
| protected bool | $validated | Indicates if the prompt has been validated. |
from Prompt |
| protected bool | $terminalStateRestored | Indicates whether this prompt's terminal state has been restored. |
from Prompt |
| static protected Closure|null | $validateUsing | The custom validation callback. |
from Prompt |
| static protected Closure|null | $revertUsing | The revert handler from the StepBuilder. |
from Prompt |
| static protected OutputInterface|null | $output | The output instance. |
from Prompt |
| static protected Terminal|null | $terminal | The terminal instance. |
from Prompt |
| protected int | $minWidth | ||
| protected string | $message | ||
| protected array<int, string> | $currentlyFading | ||
| protected int | $maxWidth | ||
| protected array<int, Closure(string): string> | $fadingOutColors | ||
| protected bool | $direct | Whether chunks should be written directly without terminal animation. |
Methods
Erase the given number of lines downwards from the cursor position.
Fake the terminal and queue key presses to be simulated.
Implementation of the looping mechanism for simulating key presses.
Assert that the output contains the given string.
Assert that the output doesn't contain the given string.
Assert that the stripped output contains the given string.
Assert that the stripped output doesn't contain the given string.
Get the buffered console output, stripped of escape sequences.
Whether the prompt should fallback to a custom implementation.
Get the value of the prompt.
Validate rules intrinsic to the prompt type.
Disable prompting for input.
Capture the number of new lines written by the last output.
Write output directly, bypassing newline capture.
Determine whether the given value is invalid when the prompt is required.
Get the length of the longest line.
Pad text ignoring ANSI escape sequences.
Replace the last visible grapheme while preserving trailing formatting.
Strip ANSI escape sequences from the given text.
Multi-byte version of wordwrap.
Word wrap text while preserving ANSI escape sequences.
Parse text into segments with their associated ANSI codes.
Update the bounded set of active SGR attributes.
Create a new Stream instance.
Close the stream and finish rendering its output.
Get the rendered stream lines.
Get an array of closures that progressively fade text from full color to nearly invisible.
Details
in
Colors at line 12
string
reset(string $text)
Reset all colors and styles.
in
Colors at line 20
string
bold(string $text)
Make the text bold.
in
Colors at line 28
string
dim(string $text)
Make the text dim.
in
Colors at line 36
string
italic(string $text)
Make the text italic.
in
Colors at line 44
string
underline(string $text)
Underline the text.
in
Colors at line 52
string
inverse(string $text)
Invert the text and background colors.
in
Colors at line 60
string
hidden(string $text)
Hide the text.
in
Colors at line 68
string
strikethrough(string $text)
Strike through the text.
in
Colors at line 76
string
black(string $text)
Set the text color to black.
in
Colors at line 84
string
red(string $text)
Set the text color to red.
in
Colors at line 92
string
green(string $text)
Set the text color to green.
in
Colors at line 100
string
yellow(string $text)
Set the text color to yellow.
in
Colors at line 108
string
blue(string $text)
Set the text color to blue.
in
Colors at line 116
string
magenta(string $text)
Set the text color to magenta.
in
Colors at line 124
string
cyan(string $text)
Set the text color to cyan.
in
Colors at line 132
string
white(string $text)
Set the text color to white.
in
Colors at line 140
string
bgBlack(string $text)
Set the text background to black.
in
Colors at line 148
string
bgRed(string $text)
Set the text background to red.
in
Colors at line 156
string
bgGreen(string $text)
Set the text background to green.
in
Colors at line 164
string
bgYellow(string $text)
Set the text background to yellow.
in
Colors at line 172
string
bgBlue(string $text)
Set the text background to blue.
in
Colors at line 180
string
bgMagenta(string $text)
Set the text background to magenta.
in
Colors at line 188
string
bgCyan(string $text)
Set the text background to cyan.
in
Colors at line 196
string
bgWhite(string $text)
Set the text background to white.
in
Colors at line 204
string
gray(string $text)
Set the text color to gray.
in
Cursor at line 17
void
hideCursor()
Hide the cursor.
in
Cursor at line 33
void
showCursor()
Show the cursor.
in
Cursor at line 49
void
restoreCursor()
Restore the cursor if it was hidden.
in
Cursor at line 59
void
moveCursor(int $x, int $y = 0)
Move the cursor.
in
Cursor at line 85
void
moveCursorToColumn(int $column)
Move the cursor to the given column.
in
Cursor at line 97
void
moveCursorUp(int $lines)
Move the cursor up by the given number of lines.
in
Cursor at line 113
static void
resetCursor()
Reset cursor state to defaults.
Boot or tests only. Clears worker-wide cursor visibility tracking; concurrent prompts may restore cursor state differently depending on timing.
in
Erase at line 12
void
eraseLines(int $count)
Erase the given number of lines downwards from the cursor position.
in
Erase at line 31
void
eraseDown()
Erase from cursor until end of screen.
in
Events at line 29
void
emit(string $event, mixed ...$data)
Emit an event.
in
Events at line 39
void
clearListeners()
Clean the event listeners.
in
FakesInputOutput at line 25
static void
fake(array $keys = [])
Fake the terminal and queue key presses to be simulated.
Tests only. Swaps prompt terminal and output state for the worker lifetime.
in
FakesInputOutput at line 62
static void
fakeKeyPresses(array $keys, callable $callable)
Implementation of the looping mechanism for simulating key presses.
By ignoring the $callable parameter which contains the default logic
for simulating fake key presses, we can use a custom implementation
to emit key presses instead, allowing us to use different inputs.
in
FakesInputOutput at line 72
static void
assertOutputContains(string $string)
Assert that the output contains the given string.
in
FakesInputOutput at line 80
static void
assertOutputDoesntContain(string $string)
Assert that the output doesn't contain the given string.
in
FakesInputOutput at line 88
static void
assertStrippedOutputContains(string $string)
Assert that the stripped output contains the given string.
in
FakesInputOutput at line 96
static void
assertStrippedOutputDoesntContain(string $string)
Assert that the stripped output doesn't contain the given string.
in
FakesInputOutput at line 104
static string
content()
Get the buffered console output.
in
FakesInputOutput at line 116
static string
strippedContent()
Get the buffered console output, stripped of escape sequences.
in
Fallback at line 39
static void
fallbackWhen(bool $condition)
Enable the fallback implementation.
in
Fallback at line 52
static bool
shouldFallback()
Whether the prompt should fallback to a custom implementation.
in
Fallback at line 69
static void
fallbackUsing(Closure $fallback)
Set the fallback implementation.
in
Fallback at line 83
mixed
fallback()
Call the registered fallback implementation.
in
Fallback at line 107
static void
resetFallback()
Reset fallback state to defaults.
Boot or tests only. Clears worker-wide prompt fallback configuration; concurrent prompts may render with different fallback behavior depending on timing.
in
Interactivity at line 28
static void
interactive(bool $interactive = true)
Set interactive mode.
in
Interactivity at line 40
static bool|null
isInteractive()
Determine if the prompt is interactive.
in
Interactivity at line 56
static void
resetInteractivity()
Reset interactivity state to defaults.
Boot or tests only. Clears worker-wide prompt interactivity configuration; concurrent prompts may render with different interactivity depending on timing.
in
Interactivity at line 65
protected mixed
default()
Return the default value if it passes validation.
in
Themes at line 117
static string
theme(string|null $name = null)
Get or set the active theme.
Boot-only when setting. The active theme persists in a static property for the worker lifetime and applies to every subsequent prompt render.
in
Themes at line 138
static void
addTheme(string $name, array $renderers)
Add a new theme.
Boot-only. Themes persist in a static property for the worker lifetime and are available to every subsequent prompt render.
in
Themes at line 150
protected callable
getRenderer()
Get the renderer for the current prompt.
in
Themes at line 165
protected string
renderTheme()
Render the prompt using the active theme.
in
Themes at line 179
static void
resetTheme()
Reset theme state to defaults.
Boot or tests only. Clears worker-wide prompt theme configuration; concurrent prompts may render with different themes depending on timing.
at line 148
mixed
value()
Get the value of the prompt.
in
Prompt at line 138
string|null
validateIntrinsic(mixed $value)
Validate rules intrinsic to the prompt type.
at line 140
mixed
prompt()
Disable prompting for input.
in
Prompt at line 238
mixed
runLoop(callable $callable)
Implementation of the prompt looping mechanism.
in
Prompt at line 261
static void
cancelUsing(Closure|null $callback)
Register a callback to be invoked when a user cancels a prompt.
Boot-only. The callback persists in a static property for the worker lifetime and runs on every subsequent prompt cancellation.
in
Prompt at line 269
int
newLinesWritten()
How many new lines were written by the last output.
in
Prompt at line 277
protected void
capturePreviousNewLines()
Capture the number of new lines written by the last output.
in
Prompt at line 287
static void
setOutput(OutputInterface $output)
Set the output instance.
in
Prompt at line 299
static protected OutputInterface
output()
Get the current output instance.
in
Prompt at line 311
static protected void
writeDirectly(string $message)
Write output directly, bypassing newline capture.
in
Prompt at line 331
protected void
restoreTerminalState()
Restore terminal state changed by the prompt operation.
in
Prompt at line 366
static void
validateUsing(Closure $callback)
Set the custom validation callback.
in
Prompt at line 378
static protected Closure|null
getValidateUsing()
Get the custom validation callback.
in
Prompt at line 392
static void
revertUsing(Closure $callback)
| internal |
Revert the prompt using the given callback.
in
Prompt at line 402
static void
preventReverting()
| internal |
Clear any previous revert callback.
in
Prompt at line 410
protected void
render()
Render the prompt.
in
Prompt at line 444
protected void
submit()
Submit the prompt.
in
Prompt at line 517
protected mixed
transformedValue()
Get the transformed value of the prompt.
in
Prompt at line 565
protected bool
isInvalidWhenRequired(mixed $value)
Determine whether the given value is invalid when the prompt is required.
in
Prompt at line 583
static void
flushState()
Flush all static state.
in
Prompt at line 603
__destruct()
Restore the cursor and terminal state.
in
InteractsWithStrings at line 16
protected int
longest(array $lines, int $padding = 0)
Get the length of the longest line.
in
InteractsWithStrings at line 27
protected string
pad(string $text, int $length, string $char = ' ')
Pad text ignoring ANSI escape sequences.
in
InteractsWithStrings at line 37
protected string
replaceLastVisibleGrapheme(string $line, string $replacement)
Replace the last visible grapheme while preserving trailing formatting.
in
InteractsWithStrings at line 68
protected string
stripEscapeSequences(string $text)
Strip ANSI escape sequences from the given text.
in
InteractsWithStrings at line 79
protected string
mbWordwrap(string $string, int $width = 75, string $break = "\n", bool $cut_long_words = false)
Multi-byte version of wordwrap.
in
InteractsWithStrings at line 172
protected array
ansiWordwrap(string $text, int $width, bool $cutLongWords = false)
Word wrap text while preserving ANSI escape sequences.
in
InteractsWithStrings at line 267
protected array
parseAnsiText(string $text)
Parse text into segments with their associated ANSI codes.
in
InteractsWithStrings at line 379
protected void
updateSgrState(array $activeSgr, string $escape)
Update the bounded set of active SGR attributes.
at line 37
__construct()
Create a new Stream instance.
at line 53
Stream
append(string $message)
Append a message to the stream.
at line 76
void
close()
Close the stream and finish rendering its output.
at line 110
array
lines()
Get the rendered stream lines.
at line 158
protected array
fadeOut(int $steps = 10)
Get an array of closures that progressively fade text from full color to nearly invisible.