BracketedPaste
Detects bracketed-paste markers in the raw terminal input stream and turns a paste into a single `paste.received` event on the {@see TuiEventBusInterface}, instead of letting the loop dispatch the pasted bytes one key at a time. The TUI analog of pi-tui's bracketed paste handling. Bracketed paste mode is a terminal feature where pastes are wrapped in `\x1b[200~` ... `\x1b[201~`; the application enables it (via the DECSET 2004 escape) and the terminal emits the markers around any pasted block, letting the app treat pastes specially (collapse to a `[paste +N lines]` marker, route to a single field, validate, …) instead of replaying the content as keystrokes. This class is a pure detector + event emitter: it does NOT enable DECSET 2004 itself — that is the loop's job, because enabling the mode belongs at TTY setup time alongside raw-mode toggles. The detector only inspects each incoming byte chunk and, when it sees a paste start marker, buffers everything until the matching end marker arrives, then publishes the event. Anything outside a paste window is returned to the caller as "passthrough" bytes so the loop can dispatch them as normal keys. When `collapse` is true, the event payload carries a short marker string (`[paste +N lines]`) instead of the raw content — matching pi-tui's behavior for pastes longer than 10 lines, useful when the TUI does not want to paste the content inline but show that a paste happened and let the user expand it.
BracketedPaste::__construct()
public function __construct(?Milpa\Live\Contracts\Tui\TuiEventBusInterface $events = null, bool $collapse = true, int $collapseThreshold = 10):Parameters
| Name | Type | Description |
|---|---|---|
| $events | ?Milpa\Live\Contracts\Tui\TuiEventBusInterface | |
| $collapse | bool | |
| $collapseThreshold | int |
BracketedPaste::feed()
public function feed(string $bytes): stringFeeds one chunk of raw terminal bytes to the detector. Returns the slice of those bytes that should be dispatched as normal keys — i.e. everything outside a paste window. Bytes inside a paste window are buffered and emitted as a `paste.received` event once the end marker arrives; they are NOT returned here.
Parameters
| Name | Type | Description |
|---|---|---|
| $bytes | string |
BracketedPaste::isInPaste()
public function isInPaste(): boolBracketedPaste::bufferedLength()
public function bufferedLength(): intHow many bytes of an in-flight paste are still buffered.