Documentation
¶
Overview ¶
Package event defines Kite's UI events and listener interfaces. Events travel from the document to the target during capture; events that bubble then visit the target's ancestors. Listeners can handle keyboard, pointer, focus, scroll, and form events and cancel registration via a Subscription.
Index ¶
- Constants
- func RegisterImplementation(i Implementation)
- type BaseEvent
- func (b *BaseEvent) Bubbles() bool
- func (b *BaseEvent) CurrentTarget() EventTarget
- func (b *BaseEvent) DefaultPrevented() bool
- func (b *BaseEvent) OriginalTarget() EventTarget
- func (b *BaseEvent) Phase() EventPhase
- func (b *BaseEvent) PreventDefault()
- func (b *BaseEvent) PropagationStopped() bool
- func (b *BaseEvent) SetCurrentTarget(o EventTarget)
- func (b *BaseEvent) SetPhase(p EventPhase)
- func (b *BaseEvent) SetTarget(o EventTarget)
- func (b *BaseEvent) StopPropagation()
- func (b *BaseEvent) Target() EventTarget
- func (b *BaseEvent) Type() EventType
- type ChangeEvent
- type ClipboardEvent
- type ClipboardType
- type ColorSchemeEvent
- type DefaultActionHandler
- type Dispatcher
- type Event
- type EventPhase
- type EventTarget
- type EventType
- type FocusEvent
- type HitResult
- type HitTester
- type Implementation
- type InputEvent
- type InternalEvent
- type KeyEvent
- type Listener
- type Modifiers
- type MouseButton
- type MouseEvent
- type Option
- type OptionSetter
- type PasteEvent
- type ProgramStatusSupportEvent
- type ResizeEvent
- type ScrollEvent
- type Scrollable
- type SelectionChangeEvent
- type SelectionProvider
- type SubmitEvent
- type Subscription
- type WheelEvent
- type WindowFocusEvent
Constants ¶
const ( // ModCtrl is the Ctrl modifier. ModCtrl = key.ModCtrl // ModAlt is the Alt modifier. ModAlt = key.ModAlt // ModShift is the Shift modifier. ModShift = key.ModShift // ModMeta is the Meta (Cmd/Win) modifier. ModMeta = key.ModMeta )
const ( UnknownClipboard = 0 // An unknown or unsupported clipboard type. SystemClipboard = 'c' // The system clipboard (e.g. Ctrl+C/Ctrl+V). PrimaryClipboard = 'p' // The primary selection (e.g. mouse selection on Linux). )
const (
// MimeTextPlain is the standard MIME type for plain text.
MimeTextPlain = "text/plain"
)
Variables ¶
This section is empty.
Functions ¶
func RegisterImplementation ¶
func RegisterImplementation(i Implementation)
RegisterImplementation registers the concrete implementation of events. This is called by internal/event's init() function.
Types ¶
type BaseEvent ¶
type BaseEvent struct {
// contains filtered or unexported fields
}
BaseEvent holds common dispatch state shared by all event types. Concrete event types embed BaseEvent.
func NewBaseEvent ¶
func NewBaseEvent(typ EventType, target EventTarget, bubbles bool) *BaseEvent
NewBaseEvent creates a BaseEvent with the given type and target.
func (*BaseEvent) CurrentTarget ¶
func (b *BaseEvent) CurrentTarget() EventTarget
CurrentTarget returns the element whose listener is currently being invoked.
func (*BaseEvent) DefaultPrevented ¶
DefaultPrevented reports whether PreventDefault was called.
func (*BaseEvent) OriginalTarget ¶
func (b *BaseEvent) OriginalTarget() EventTarget
OriginalTarget returns the raw target that originally received the event.
func (*BaseEvent) Phase ¶
func (b *BaseEvent) Phase() EventPhase
Phase returns the current dispatch phase.
func (*BaseEvent) PreventDefault ¶
func (b *BaseEvent) PreventDefault()
PreventDefault signals that the default action should be suppressed.
func (*BaseEvent) PropagationStopped ¶
PropagationStopped reports whether StopPropagation was called.
func (*BaseEvent) SetCurrentTarget ¶
func (b *BaseEvent) SetCurrentTarget(o EventTarget)
func (*BaseEvent) SetPhase ¶
func (b *BaseEvent) SetPhase(p EventPhase)
func (*BaseEvent) SetTarget ¶
func (b *BaseEvent) SetTarget(o EventTarget)
func (*BaseEvent) StopPropagation ¶
func (b *BaseEvent) StopPropagation()
StopPropagation prevent the event from reaching further listeners.
func (*BaseEvent) Target ¶
func (b *BaseEvent) Target() EventTarget
Target returns the element that originally received the event.
type ChangeEvent ¶
ChangeEvent is dispatched when the value of an input or textarea changes.
type ClipboardEvent ¶
type ClipboardEvent struct {
BaseEvent
// ClipType identifies whether this is a copy, cut, or paste.
ClipType ClipboardType
// Items stores payloads keyed by their MIME type.
// Common keys include "text/plain".
Items map[string][]byte
}
ClipboardEvent is dispatched for copy, cut, and paste clipboard operations. ClipboardEvent bubbles.
func NewClipboardEvent ¶
func NewClipboardEvent(typ EventType, ct ClipboardType) *ClipboardEvent
NewClipboardEvent creates a ClipboardEvent.
func (*ClipboardEvent) SetText ¶
func (c *ClipboardEvent) SetText(text string)
SetText sets the "text/plain" item.
func (*ClipboardEvent) Text ¶
func (c *ClipboardEvent) Text() string
Text returns the "text/plain" item as a string, or an empty string if not present.
type ClipboardType ¶
type ClipboardType uint8
ClipboardType identifies the clipboard operation.
const ( // ClipboardCopy is a copy operation (Ctrl+C with active selection). ClipboardCopy ClipboardType = iota // ClipboardCut is a cut operation (Ctrl+X with active selection). ClipboardCut // ClipboardPaste is a paste operation (Ctrl+V or bracketed paste). ClipboardPaste )
type ColorSchemeEvent ¶
type ColorSchemeEvent struct {
BaseEvent
Scheme style.ColorScheme
}
func NewColorSchemeEvent ¶
func NewColorSchemeEvent(scheme style.ColorScheme) *ColorSchemeEvent
type DefaultActionHandler ¶
type DefaultActionHandler interface {
HandleDefaultAction(e Event)
}
DefaultActionHandler is implemented by event targets that perform a post-dispatch default action (e.g., <input> or <textarea> inserting pasted text) after capture, target, and bubble phases complete, unless a listener called PreventDefault().
type Dispatcher ¶
type Dispatcher interface {
// Dispatch routes e through the ancestor chain described by path.
// path must be ordered root → target (index 0 = root, last = target).
Dispatch(e Event, path []EventTarget)
// DispatchWheel routes a WheelEvent through the ancestor chain, stopping at
// the first ancestor that implements Scrollable.
DispatchWheel(e *WheelEvent, path []EventTarget, scrollables []Scrollable)
}
Dispatcher performs 3-phase (capture → target → bubble) event dispatch.
type Event ¶
type Event interface {
// Type returns the event type identifier.
Type() EventType
// Target returns the element that originally received the event.
// During dispatch, this may be retargeted as the event crosses
// shadow boundaries.
Target() EventTarget
// OriginalTarget returns the raw target that originally received the
// event, without retargeting. This is an engine-internal accessor used to
// build the dispatch path.
OriginalTarget() EventTarget
// CurrentTarget returns the element whose listener is currently
// being invoked.
CurrentTarget() EventTarget
// Phase returns the current dispatch phase.
Phase() EventPhase
// Bubbles reports whether the event bubbles through the ancestor chain.
Bubbles() bool
// StopPropagation prevent the event from reaching further listeners
// in subsequent phases.
StopPropagation()
// PropagationStopped reports whether StopPropagation was called.
PropagationStopped() bool
// PreventDefault signals that the default action should be suppressed.
PreventDefault()
// DefaultPrevented reports whether PreventDefault was called.
DefaultPrevented() bool
}
Event is the interface implemented by all event types. Concrete event embed BaseEvent which provides default implementations.
type EventPhase ¶
type EventPhase uint8
EventPhase represents the current dispatch phase.
const ( // PhaseNone is the default phase (not dispatching). PhaseNone EventPhase = iota // PhaseCapture is the top-down capture phase. PhaseCapture // PhaseTarget is the target phase. PhaseTarget // PhaseBubble is the bottom-up bubble phase. PhaseBubble )
type EventTarget ¶
type EventTarget interface {
// AddEventListener registers fn as a listener for event of type typ on this
// target. Options control the phase (capture vs bubble), auto-cancellation
// (once), and the passive hint. The returned Subscription can be used to
// remove the listener without pointer comparison.
AddEventListener(typ EventType, fn Listener, opts ...Option) Subscription
// DispatchTo fires listeners on this target for the given event. It
// respects the phase and the once flag.
DispatchTo(e Event)
// DispatchToTarget invokes capture-registered listeners followed by
// bubble-registered listeners for the target phase.
DispatchToTarget(e Event)
// RemoveRegistration removes the registration with the given id.
RemoveRegistration(id uint64)
// EventTarget returns the user-visible event target for this object.
// For logical nodes in a UA shadow subtree, this returns the host element;
// otherwise it returns the object itself.
EventTarget() EventTarget
}
EventTarget is the interface implemented by objects that can receive events and have listeners registered on them.
type EventType ¶
type EventType string
EventType is a typed string identifier for event.
const ( EventKeyDown EventType = "keydown" EventKeyUp EventType = "keyup" EventKeyPress EventType = "keypress" EventMouseDown EventType = "mousedown" EventMouseUp EventType = "mouseup" EventMouseMove EventType = "mousemove" EventMouseEnter EventType = "mouseenter" EventMouseLeave EventType = "mouseleave" EventMouseOver EventType = "mouseover" EventMouseOut EventType = "mouseout" EventClick EventType = "click" EventDrag EventType = "drag" EventWheel EventType = "wheel" EventFocus EventType = "focus" EventBlur EventType = "blur" EventFocusIn EventType = "focusin" EventFocusOut EventType = "focusout" EventColorSchemeChange EventType = "colorschemechange" EventResize EventType = "resize" EventWindowFocus EventType = "windowfocus" EventWindowBlur EventType = "windowblur" EventChange EventType = "change" EventInput EventType = "input" EventPaste EventType = "paste" EventCopy EventType = "copy" EventCut EventType = "cut" EventClipboard EventType = "clipboard" EventScroll EventType = "scroll" EventSelectionChange EventType = "selectionchange" EventReset EventType = "reset" EventSubmit EventType = "submit" EventProgramStatusSupport EventType = "programstatussupport" )
Standard event type constants.
type FocusEvent ¶
type FocusEvent struct {
BaseEvent
// RelatedTarget is the element losing focus (for focus event) or
// gaining focus (for blur event), or nil if none.
RelatedTarget EventTarget
}
FocusEvent is dispatched when an element gains or loses keyboard focus. "focus" and "blur" do not bubble; "focusin" and "focusout" do.
func NewFocusEvent ¶
func NewFocusEvent(typ EventType, related EventTarget) *FocusEvent
NewFocusEvent creates a FocusEvent of the given type.
type HitResult ¶
type HitResult struct {
// Target is the deepest event target at the hit point.
Target EventTarget
}
HitResult caches the hit-test result computed when a MouseEvent is synthesized. It is valid only for the lifetime of the event.
type HitTester ¶
type HitTester interface {
HitTest(x, y int) EventTarget
}
HitTester resolves the event target at a screen-space point. This is typically implemented by the engine.
type Implementation ¶
type Implementation struct {
NewDispatcher func() Dispatcher
NewTarget func() EventTarget
}
Implementation defines the set of factory functions provided by the internal/event package.
type InputEvent ¶
InputEvent is dispatched for every user-initiated change to an input or textarea value.
type InternalEvent ¶
type InternalEvent interface {
Event
// SetTarget sets the event target. Used internally by Dispatcher.
SetTarget(EventTarget)
// SetCurrentTarget sets the current target. Used internally by Dispatcher.
SetCurrentTarget(EventTarget)
// SetPhase sets the dispatch phase. Used internally by Dispatcher.
SetPhase(EventPhase)
}
InternalEvent is the interface implemented by event types that can be updated during the dispatch process. It is used by the Dispatcher and Synthesizer in internal/event.
type MouseButton ¶
type MouseButton uint8
MouseButton identifies which mouse button was involved in the event.
const ( // ButtonNone indicates no button (e.g. mouse move). ButtonNone MouseButton = iota // ButtonLeft is the primary mouse button. ButtonLeft // ButtonMiddle is the middle mouse button. ButtonMiddle // ButtonRight is the right mouse button. ButtonRight )
type MouseEvent ¶
type MouseEvent struct {
BaseEvent
// Screen holds the absolute screen-space coordinates.
Screen geom.Point
// Local holds the coordinates local to the Target's render bounds.
Local geom.Point
// Hit is the cached hit-test result from when the event was synthesized.
Hit HitResult
// Button is the mouse button involved.
Button MouseButton
// Mods holds the active modifier keys.
Mods Modifiers
}
MouseEvent is dispatched for mouse-button, move, and click event. MouseEvent bubbles.
func NewMouseEvent ¶
func NewMouseEvent(typ EventType, screen geom.Point, button MouseButton, mods Modifiers) *MouseEvent
NewMouseEvent creates a MouseEvent of the given type.
type Option ¶
type Option func(any)
Option configures how a listener is registered.
func Capture ¶
func Capture() Option
Capture returns an Option that registers the listener for the capture phase (default is bubble phase).
type OptionSetter ¶
OptionSetter is the interface implemented by internal registration objects to allow public options to configure them.
type PasteEvent ¶
PasteEvent is dispatched when the user pastes text (bracketed paste or Ctrl+V). PasteEvent does not bubble past the focused element.
func NewPasteEvent ¶
func NewPasteEvent(text string) *PasteEvent
NewPasteEvent creates a PasteEvent.
type ProgramStatusSupportEvent ¶
type ProgramStatusSupportEvent struct {
BaseEvent
}
ProgramStatusSupportEvent is dispatched when the terminal confirms support for the Program Status Protocol (OSC 7501). It does not bubble.
func NewProgramStatusSupportEvent ¶
func NewProgramStatusSupportEvent() *ProgramStatusSupportEvent
NewProgramStatusSupportEvent creates a new ProgramStatusSupportEvent.
type ResizeEvent ¶
type ResizeEvent struct {
BaseEvent
// Width is the new viewport width in columns.
Width int
// Height is the new viewport height in rows.
Height int
}
ResizeEvent is dispatched when the terminal viewport dimensions change. ResizeEvent does not bubble.
func NewResizeEvent ¶
func NewResizeEvent(width, height int) *ResizeEvent
NewResizeEvent creates a ResizeEvent.
type ScrollEvent ¶
type ScrollEvent struct {
BaseEvent
X, Y int // New absolute offset
DeltaX, DeltaY int // Change from previous offset
}
ScrollEvent is dispatched when an element's scroll offset changes. ScrollEvent bubbles.
func NewScrollEvent ¶
func NewScrollEvent(x, y, dx, dy int) *ScrollEvent
NewScrollEvent creates a ScrollEvent with the given offset and delta.
type Scrollable ¶
type Scrollable interface {
OnWheel(e *WheelEvent)
}
Scrollable is implemented by render objects that handle wheel event. The Dispatcher stops wheel-event bubbling at the first ancestor that implements Scrollable and calls OnWheel.
type SelectionChangeEvent ¶
SelectionChangeEvent is dispatched when a text selection or caret position changes. SelectionChangeEvent does not bubble.
func NewSelectionChange ¶
func NewSelectionChange(start, end int) *SelectionChangeEvent
NewSelectionChange creates a SelectionChangeEvent with the given byte offsets.
type SelectionProvider ¶
type SelectionProvider interface {
// SelectedText returns the currently selected text, or "" if nothing is
// selected.
SelectedText() string
}
SelectionProvider is implemented by elements that can report an active text selection. The Synthesizer uses it to decide whether to emit Copy/Cut Clipboardevent.
type SubmitEvent ¶
SubmitEvent is dispatched when a form is submitted.
func NewSubmitEvent ¶
func NewSubmitEvent(formData map[string]any) *SubmitEvent
NewSubmitEvent creates a SubmitEvent.
type Subscription ¶
type Subscription interface {
// Cancel removes this listener registration. It is idempotent: calling
// Cancel more than once is safe and has no additional effect.
Cancel()
}
Subscription is a cancellable event listener registration. Call Cancel to remove the listener from its target. Subscription values are safe to cancel from any goroutine; the actual removal is deferred to the next listener invocation to avoid map mutation under iteration.
type WheelEvent ¶
type WheelEvent struct {
BaseEvent
// Screen holds the absolute screen-space coordinates.
Screen geom.Point
// Local holds the coordinates local to the Target's render bounds.
Local geom.Point
// DeltaX is the horizontal scroll delta (positive = right).
DeltaX int
// DeltaY is the vertical scroll delta (positive = down).
DeltaY int
// Mods holds the active modifier keys.
Mods Modifiers
}
WheelEvent is dispatched when the scroll wheel is turned. WheelEvent bubbles.
func NewWheelEvent ¶
func NewWheelEvent(screen geom.Point, dx, dy int, mods Modifiers) *WheelEvent
NewWheelEvent creates a WheelEvent.
type WindowFocusEvent ¶
type WindowFocusEvent struct {
BaseEvent
}
WindowFocusEvent is dispatched when the terminal window gains or loses focus.
func NewWindowFocusEvent ¶
func NewWindowFocusEvent(typ EventType) *WindowFocusEvent
NewWindowFocusEvent creates a new WindowFocusEvent.