StreamTerminal
Terminal backed by PHP input/output streams. The PHP analog of pi-tui's `ProcessTerminal`. Defaults to `STDIN` / `STDOUT` and uses `stty` to toggle raw mode, so it works on any POSIX terminal the way the existing `RetainedTuiLoop::run()` does — but now behind a contract the loop can swap out. A `StreamTerminal` owns no state beyond the streams it was given and the saved `stty` settings; it is safe to construct one per loop session and discard it on {@see stop()}.
StreamTerminal::__construct()
public function __construct(?string $title = null, ?mixed $input = null, ?mixed $output = null):Parameters
| Name | Type | Description |
|---|---|---|
| $title | ?string | |
| $input | (resource | null) | Stream the terminal reads input bytes from. |
| $output | (resource | null) | Stream the terminal writes ANSI output to. |
StreamTerminal::start()
public function start(callable $onInput, callable $onResize): voidPuts the terminal in raw mode and begins delivering input and resize events. Saves the previous terminal settings so {@see self::stop()} can restore them.
Parameters
| Name | Type | Description |
|---|---|---|
| $onInput | callable | |
| $onResize | callable |
StreamTerminal::stop()
public function stop(): voidRestores the terminal to how it was found: previous settings, visible cursor, default resize handling.
StreamTerminal::write()
public function write(string $data): voidWrites raw bytes to the output stream, unmodified.
Parameters
| Name | Type | Description |
|---|---|---|
| $data | string |
StreamTerminal::columns()
public function columns(): intThe terminal's current width in columns.
StreamTerminal::rows()
public function rows(): intThe terminal's current height in rows.
StreamTerminal::moveBy()
public function moveBy(int $lines): voidMoves the cursor by the given number of lines, negative being upwards.
Parameters
| Name | Type | Description |
|---|---|---|
| $lines | int |
StreamTerminal::hideCursor()
public function hideCursor(): voidHides the hardware cursor.
StreamTerminal::showCursor()
public function showCursor(): voidShows the hardware cursor.
StreamTerminal::clearLine()
public function clearLine(): voidClears the line the cursor is on.
StreamTerminal::clearFromCursor()
public function clearFromCursor(): voidClears from the cursor to the end of the screen.
StreamTerminal::clearScreen()
public function clearScreen(): voidClears the whole screen.
StreamTerminal::setTitle()
public function setTitle(string $title): voidSets the terminal window title.
Parameters
| Name | Type | Description |
|---|---|---|
| $title | string |
StreamTerminal::pollInput()
public function pollInput(): stringReturns the current input byte chunk waiting on the input stream, or `''` when nothing is pending. The loop polls this on each tick; the method is intentionally non-blocking so a busy loop stays responsive.
StreamTerminal::atEndOfInput()
public function atEndOfInput(): boolTrue once the input stream is drained. A real terminal never reaches this: `feof()` on a TTY stays false for as long as the device is open.
StreamTerminal::dispatchInput()
public function dispatchInput(string $bytes): voidFeeds raw input bytes to the registered handler, used to drive the terminal from a test or another source instead of the real stream.
Parameters
| Name | Type | Description |
|---|---|---|
| $bytes | string |