Skip to content
docsv0.3.0

KillRing

Ring buffer for Emacs-style kill/yank operations. The PHP port of pi-tui's `KillRing`. Tracks killed (deleted) text entries so the user can yank (paste) them back. Consecutive kills can accumulate into a single entry — backward deletion prepends, forward deletion appends — matching the Emacs behavior a `Ctrl+W` / `Ctrl+U` / `Alt+D` key handler chain expects. Pure state holder — not a renderer, not a contract. A `text-input` or `editor` key handler owns one instance and feeds it as the user deletes text; the yank handler reads from it. The ring is bounded only by usage; in practice a few entries are enough.

KillRing::push()

public function push(string $text, array $opts): void

Adds killed text to the ring. When `accumulate` is true and the ring is non-empty, merges with the most recent entry instead of pushing a new one — prepending for backward deletion, appending for forward deletion. Empty text is a no-op.

Parameters

Parameters of push()
NameTypeDescription
$textstring
$optsarray{prepend: bool, accumulate?: bool}

KillRing::peek()

public function peek(): ?string

Returns the most recent entry without modifying the ring, or `null` when empty.

KillRing::rotate()

public function rotate(): void

Rotates the last entry to the front so the next {@see peek()} returns the previous kill — the "yank-pop" cycle. A no-op when the ring holds fewer than two entries.

KillRing::length()

public function length(): int

How many entries the ring currently holds.

KillRing::clear()

public function clear(): void