Skip to content

nimterm/input

This page is generated from the module’s exported API and ## documentation comments.

Shared terminal input decoder.

Reads bytes from term (posix raw stdin) and turns them into keys / mouse events.

ByteReader = proc (timeoutMs: int): int {.closure.}

View source

InputDecoder = object

View source

MouseKind = enum
mouseNone, mousePress, ## left button down
mouseRelease, ## left button up
mouseDrag ## motion while left button held

View source

FocusKind = enum
focusNone, focusIn, focusOut

View source

InputEvent = object
key*: Key
ch*: char ## ASCII keyChar; prefer `text` for insert
text*: string ## UTF-8 rune or a whole paste
scrollDelta*: int ## +N scroll up (older), -N scroll down (newer)
resized*: bool
mouse*: MouseKind
button*: UiMouseButton
shift*: bool
alt*: bool
ctrl*: bool
mouseX*: int ## 0-based column
mouseY*: int ## 0-based row
focus*: FocusKind

View source

CR LF / CR → LF so a paste never submits.

proc normalizePasteText(s: string): string {.raises: [], tags: [], forbids: [].}

Returns: string.

Name Type Default
s string

View source

Ctrl/Cmd+V as xterm modifyOtherKeys (27;5;118~) or CSI-u (118;5u).

proc isModifiedPaste(seq: string): bool {.raises: [], tags: [], forbids: [].}

Returns: bool.

Name Type Default
seq string

View source

proc decodeInput(b: int; readNext: ByteReader): InputEvent {.
raises: [Exception], tags: [RootEffect], forbids: [].}

Returns: InputEvent.

Name Type Default
b int
readNext ByteReader

View source

proc feed(decoder: var InputDecoder; bytes: string) {.raises: [], tags: [],
forbids: [].}
Name Type Default
decoder var InputDecoder
bytes string

View source

proc pending(decoder: InputDecoder): bool {.raises: [], tags: [], forbids: [].}

Returns: bool.

Name Type Default
decoder InputDecoder

View source

proc escapeWaitMs(decoder: InputDecoder; nowMs: int64; timeoutMs = 15): int {.
raises: [], tags: [], forbids: [].}

Returns: int.

Name Type Default
decoder InputDecoder
nowMs int64
timeoutMs inferred 15

View source

proc nextEvent(decoder: var InputDecoder; nowMs: int64; escapeTimeoutMs = 15): InputEvent {.
raises: [Exception], tags: [RootEffect], forbids: [].}

Returns: InputEvent.

Name Type Default
decoder var InputDecoder
nowMs int64
escapeTimeoutMs inferred 15

View source

proc toUiEvent(input: InputEvent; width = 0; height = 0): UiEvent {.raises: [],
tags: [], forbids: [].}

Returns: UiEvent.

Name Type Default
input InputEvent
width inferred 0
height inferred 0

View source