Skip to content
docsv0.3.0

InputBuffer

Buffers raw stdin bytes and emits complete terminal sequences. The PHP port of pi-tui's `StdinBuffer`. Necessary because stdin reads can return partial chunks — a mouse event `\x1b[<35;20;5m` might arrive as three reads, and a CSI sequence `\x1b[A` might share a chunk with the next keypress. Without buffering, partial escape sequences get misinterpreted as regular keypresses. The buffer accumulates bytes in `feed()` and returns any *completed* sequences. A bare ESC that is not followed by anything more is held for one more feed — it might be the start of a longer escape sequence, or a bare Escape key. The caller should call `flush()` on idle to emit a pending bare ESC as a complete key. Recognized sequence families (mirrors pi-tui): - CSI: `\x1b[...` (arrow keys, mouse, F-keys, …) - OSC: `\x1b]...\x07` or `\x1b]...\x1b\\` (title, color, …) - DCS: `\x1bP...\x1b\\` (kitty graphics, …) - APC: `\x1b_...\x1b\\` (kitty image responses, …) - SS3: `\x1bO?` (F1-F4, …) - Meta: `\x1b<char>` (Alt+key) - Bracketed paste: `\x1b[200~...\x1b[201~` (passed through intact so `BracketedPaste` can detect it downstream)

InputBuffer::feed()

public function feed(string $bytes): string

Feeds raw bytes and returns any completed sequences. The returned string contains zero or more complete sequences concatenated in arrival order; anything that is still incomplete is held in the internal buffer for the next call.

Parameters

Parameters of feed()
NameTypeDescription
$bytesstring

InputBuffer::flush()

public function flush(): string

Emits any pending bare ESC as a complete key. Call on idle — e.g. when the read loop times out with no new input — so a lone Escape is not held forever waiting for a non-coming continuation.

InputBuffer::pending()

public function pending(): string

InputBuffer::clear()

public function clear(): void