celina/core/events

Search:
Group by:

Event handling

This module provides comprehensive event handling for keyboard input, including escape sequences and arrow keys for POSIX systems.

Types

Event = object
  case kind*: EventKind
  of Key:
    key*: KeyEvent
  of Mouse:
    mouse*: MouseEvent
  of Resize, Quit, Unknown:
    nil
EventKind = enum
  Key, Mouse, Resize, Quit, Unknown
KeyCode = enum
  Char, Enter, Escape, Backspace, Tab, BackTab, Space, ArrowUp, ArrowDown,
  ArrowLeft, ArrowRight, Home, End, PageUp, PageDown, Insert, Delete, F1, F2,
  F3, F4, F5, F6, F7, F8, F9, F10, F11, F12
KeyEvent = object
  code*: KeyCode
  char*: char
  modifiers*: set[KeyModifier]
KeyModifier = enum
  Ctrl, Alt, Shift
MouseButton = enum
  Left, Right, Middle, WheelUp, WheelDown
MouseEvent = object
  kind*: MouseEventKind
  button*: MouseButton
  x*: int
  y*: int
  modifiers*: set[KeyModifier]
MouseEventKind = enum
  Press, Release, Move, Drag

Procs

proc checkResize(): Option[Event] {....raises: [], tags: [], forbids: [].}
Check if a resize event occurred
proc hasInput(): bool {....raises: [], tags: [], forbids: [].}
Check if input is available without blocking
proc initSignalHandling() {....raises: [], tags: [], forbids: [].}
Initialize signal handling for terminal resize
proc pollEvents(timeoutMs: int): bool {....raises: [], tags: [], forbids: [].}
Poll for available events with a timeout Returns true if events are available, false if timeout occurred Similar to crossterm::event::poll()
proc pollKey(): Event {....raises: [Exception, ValueError],
                        tags: [RootEffect, ReadIOEffect], forbids: [].}
Poll for a key event (non-blocking)
proc readKey(): Event {....raises: [Exception, ValueError],
                        tags: [RootEffect, ReadIOEffect], forbids: [].}
Read a key event (blocking mode) Raises IOError if unable to read from stdin
proc readKeyInput(): Option[Event] {....raises: [IOError, ValueError],
                                     tags: [ReadIOEffect], forbids: [].}
Read a single key input event (non-blocking) Returns none(Event) if no input is available or on error
proc waitForAnyKey(): bool {....raises: [Exception, ValueError],
                             tags: [RootEffect, ReadIOEffect, TimeEffect],
                             forbids: [].}
Wait for any key press, return true if not quit
proc waitForKey(): Event {....raises: [Exception, ValueError],
                           tags: [RootEffect, ReadIOEffect, TimeEffect],
                           forbids: [].}
Wait for a key press (blocking)