These libraries are experimental. APIs may change without notice. Generated from source with koruc 0.1.7 on 11/4/2026.

Kbd

@korulang/kbd@0.0.1

Raw nonblocking keyboard reads for terminal Koru programs (termios cbreak + poll + CSI arrow decode)

kbd/index.kz · 5 tors

@korulang/kbd — raw nonblocking keyboard reads for terminal Koru programs. · 29 more lines
@korulang/kbd — raw nonblocking keyboard reads for terminal Koru programs. The lightest path to live keys: termios cbreak+noecho on stdin (VMIN=0, VTIME=0), then poll()+read() drained through a byte-level decoder for the two sequences a game client actually wants — WASD single bytes and CSI arrow escapes (ESC [ A..D, plus the SS3 alternate ESC O A..D). No event loop, no alternate screen, no library dependency — three host procs and a 64-deep decoded-key queue. import libs/kbd import std/io libs/kbd:raw() |> for(0..4000) ! each _ |> libs/kbd:keys(max: 8) ! key k |> libs/kbd:key.name(code: k.code): n |> std/io:print.ln("{{ n:s }}") | done |> std/time:sleep-ms(ms: 16) | done |> libs/kbd:restore() Codes: 1 up, 2 down, 3 left, 4 right, 5 w, 6 a, 7 s, 8 d, 9 q, 10 space, 11 enter, 12 tab, 13 escape — anything else arrives as 1000+byte (a raw passthrough so unmapped keys stay distinguishable). 0 is the empty queue: `keys` reports it as | done, `read` returns it. Named gaps, honestly: terminals send no key-up — held-key state is repeat-arrival only. ISIG stays on so ^C still kills (and leaves the tty raw — restore is the caller's job). A lone Escape is reported only after two consecutive empty polls: it shares a prefix with every CSI sequence.

restore

index.kz:156

key.name

index.kz:197