event

package
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 8, 2026 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package event defines the typed events that flow through the vigo view tree: keyboard, mouse, commands, broadcasts, idle ticks, and resize.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Class

type Class uint16

Class is the kind of an event. The zero value, ClassNothing, marks an event as consumed; views call (*Event).Clear when they handle one.

const (
	ClassKey Class = 1 << iota
	ClassMouseDown
	ClassMouseUp
	ClassMouseMove
	ClassMouseAuto
	ClassMouseWheel
	ClassCommand
	ClassBroadcast
	ClassIdle
	ClassResize
)

Event class flags.

const ClassNothing Class = 0

ClassNothing is the consumed marker. All other classes are bit flags so callers can build masks (e.g. an event filter for mouse events only).

type CommandID

type CommandID uint16

CommandID is a numeric identifier for a UI action: file open, save, quit, menu activate, and so on. Commands let views send actions without knowing who handles them.

const (
	CmdNone CommandID = iota
	CmdQuit
	CmdError
	CmdMenu
	CmdClose
	CmdZoom
	CmdResize
	CmdNext
	CmdPrev
	CmdHelp
	CmdOk
	CmdCancel
	CmdYes
	CmdNo
	CmdScrollBarChanged
	CmdScrollBarClicked
	CmdSelectWindowNum

	CmdUser CommandID = 100
)

System commands. User-defined commands start at CmdUser.

type Event

type Event struct {
	What  Class
	Key   KeyEvent
	Mouse MouseEvent
	Msg   MessageEvent
}

Event is the union type carried through the event loop. Only the field indicated by What is meaningful; the others are zero. Events are passed by pointer so handlers can mark them consumed via Clear.

func (*Event) Clear

func (e *Event) Clear()

Clear marks the event as consumed. The convention matches Turbo Vision: a view that handles an event sets What back to ClassNothing, and dispatch loops stop at that point.

func (*Event) Consumed

func (e *Event) Consumed() bool

Consumed reports whether the event has already been handled.

type Key

type Key uint16

Key identifies a non-printable key, or KeyRune for printable input where the rune lives in KeyEvent.Rune.

const (
	KeyNone Key = iota
	KeyRune
	KeyEnter
	KeyEsc
	KeyTab
	KeyShiftTab
	KeyBackspace
	KeyDelete
	KeyInsert
	KeyHome
	KeyEnd
	KeyPgUp
	KeyPgDn
	KeyArrowUp
	KeyArrowDown
	KeyArrowLeft
	KeyArrowRight
	KeyF1
	KeyF2
	KeyF3
	KeyF4
	KeyF5
	KeyF6
	KeyF7
	KeyF8
	KeyF9
	KeyF10
	KeyF11
	KeyF12
)

Key constants. Function keys, navigation, and KeyRune for printable text.

type KeyEvent

type KeyEvent struct {
	Key  Key
	Mod  Modifier
	Rune rune
}

KeyEvent is the payload of a KeyDown event.

type MessageEvent

type MessageEvent struct {
	Command CommandID
	Info    any
}

MessageEvent is the payload of ClassCommand and ClassBroadcast events. Info is an optional typed payload; consumers type-assert as needed.

type Modifier

type Modifier uint8

Modifier is a bitmask of keyboard modifier keys.

const (
	ModNone  Modifier = 0
	ModShift Modifier = 1 << iota
	ModCtrl
	ModAlt
	ModMeta
)

Modifier bits.

type MouseButton

type MouseButton uint8

MouseButton is a bitmask of mouse buttons currently pressed.

const (
	MouseLeft MouseButton = 1 << iota
	MouseMiddle
	MouseRight
	MouseWheelUp
	MouseWheelDown
)

Mouse button bits.

type MouseEvent

type MouseEvent struct {
	X, Y    int
	Buttons MouseButton
	Mod     Modifier
}

MouseEvent is the payload of any Mouse* event. For Resize events, X and Y carry the new screen width and height (no other field is meaningful).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL