Skip to content

Events

Classes in the Phui\Events namespace. Events are passed to the handlers registered by bindings and by the mouse setters on nodes.

Event

abstract readonly class Phui\Events\Event

Extended by every event.

php
public string $raw

The bytes the event was parsed from.

php
getEventType(): string

Returns the identifier the event is routed by.

KeypressEvent

final readonly class Phui\Events\Keyboard\KeypressEvent extends Event

php
public string $key
public array $modifiers
public bool $isSpecial

The key pressed, the Keypress modifiers held with it, and whether the key is a named key rather than a character.

php
isChar(string $char): bool

Returns whether the event is the given character.

php
hasModifier(Keypress $modifier): bool

Returns whether the modifier was held.

PasteEvent

final readonly class Phui\Events\Keyboard\PasteEvent extends Event

php
public string $content

The pasted text.

MouseEvent

abstract readonly class Phui\Events\Mouse\MouseEvent extends Event

Extended by every mouse event.

php
public int $x
public int $y

The pointer's position in screen cells.

php
public array $modifiers

The Keypress modifiers held.

php
public ?Point $contentPosition

The position relative to the handling element's content box, or null before the event reaches an element.

php
abstract atContentPosition(Point $position): static

Returns a copy carrying a content-relative position.

MouseClickEvent

final readonly class Phui\Events\Mouse\MouseClickEvent extends MouseEvent

php
public string $button
public bool $isPress

Which button the event came from, and whether it is a press rather than a release.

php
const LEFT = 'left'
const RIGHT = 'right'
const MIDDLE = 'middle'

The values $button takes.

php
isLeftClick(): bool
isRightClick(): bool
isMiddleClick(): bool

Return whether the event came from that button.

MouseScrollEvent

final readonly class Phui\Events\Mouse\MouseScrollEvent extends MouseEvent

php
public string $direction
public int $amount

The scroll direction and the number of steps.

php
const UP = 'up'
const DOWN = 'down'
const LEFT = 'left'
const RIGHT = 'right'

The values $direction takes.

MouseMoveEvent

final readonly class Phui\Events\Mouse\MouseMoveEvent extends MouseEvent

php
public int $prevX
public int $prevY

The pointer's previous position.

php
getDelta(): array

Returns the movement since the previous position.

EmitEvent

final readonly class Phui\Events\EmitEvent extends Event

Carries a value emitted by a component with emit().

php
public string $name
public Component $emitter
public mixed $data

The event name, the component that emitted it, and the payload.

php
getEventType(): string

Returns the emit name rather than the class name, so handlers are registered with the name string rather than EmitEvent::class.

System events

php
WindowSizeEvent(
    public int $width,
    public int $height,
)

The terminal was resized.

php
FocusEvent(
    public bool $focused,
)

The terminal window gained or lost focus.

php
ColourDepthEvent(
    public ColourDepth $depth,
)

The terminal reported its colour depth.

php
SyncSupportEvent(
    public bool $supported,
)

The terminal reported whether it supports synchronised output.

php
CursorPositionEvent(
    public int $row,
    public int $col,
)

The terminal reported its cursor position.

php
StrayOutputEvent(
    public string $line,
)

Output reached the terminal from outside the renderer.

Enums

MouseTracking

enum Phui\Events\Mouse\MouseTracking

How much mouse activity the terminal reports, set with mouse().

php
MouseTracking::CLICK

Reports button presses and releases only.

php
MouseTracking::DRAG

Reports presses, releases and movement while a button is held.

php
MouseTracking::MOTION

Reports presses, releases and all movement, whether or not a button is held.

ColourDepth

enum Phui\Events\System\ColourDepth

The colour range the terminal reported, carried by a ColourDepthEvent and mapped to a ColourMode.

php
ColourDepth::TrueColour

24-bit colour.

php
ColourDepth::Colour256

The 256-colour palette.

php
ColourDepth::Ansi16

The 16 base ANSI colours.

Released under the MIT License.