package miaou-core
Install
dune-project
Dependency
Authors
Maintainers
Sources
md5=60a3b9f181f24572a06a9492532bfdda
sha512=fcc35a275066be2900e6201782faf47503076fa4640f08cf78067835a6f447b74613009e55b2ac799adb7ca46f1bffa261fc5971753f2cc3c6bef327511c7ef6
doc/miaou-core.driver-common/Miaou_driver_common/Input_parser/index.html
Module Miaou_driver_common.Input_parserSource
Terminal input parser shared between drivers.
Parses escape sequences for keyboard and mouse input. Based on lambda-term driver's tested implementation.
Key feature: uses peek-then-consume pattern for draining to avoid losing input when a different key is in the buffer.
Usage:
let parser = Input_parser.create fd in
(* ... in poll loop ... *)
ignore (Input_parser.refill parser ~timeout_s:0.033);
match Input_parser.parse_key parser with
| Some key -> handle_key (Input_parser.key_to_string key)
| None -> (* no input *)type key = | Char of string(*Regular character or UTF-8 grapheme
*)| Enter| AltEnter(*Alt+Enter (ESC followed by newline)
*)| Tab| ShiftTab(*Shift+Tab / backtab (ESC
*)Z)| Backspace| Escape| Up| Down| Left| Right| PageUp(*ESC
*)5 ~| PageDown(*ESC
*)6 ~| Home(*ESC
*)H, ESC O H, ESC [ 1 ~, ESC [ 7 ~| End(*ESC
*)F, ESC O F, ESC [ 4 ~, ESC [ 8 ~| Delete| Ctrl of char(*Control + letter, e.g., Ctrl 'a' for C-a
*)| Mouse of {}(*Mouse click.
*)buttonis 0=left, 1=middle, 2=right.releaseis true for button release (actual click).| MouseDrag of {}(*Mouse motion while button held. Emitted during drag operations.
*)| WheelUp of {}(*Mouse wheel scroll up
*)| WheelDown of {}(*Mouse wheel scroll down
*)| Refresh(*Synthetic refresh marker (null byte)
*)| Unknown of string(*Unrecognized escape sequence
*)
Parsed key event.
Parser state.
Create a new parser for the given file descriptor.
Read bytes into buffer without waiting (no Unix.select). The caller is responsible for ensuring the fd is readable (e.g. via Eio_unix.await_readable).
Return the underlying file descriptor.
Parse next key from buffer, consuming the bytes. Returns None if buffer is empty.
Peek at next key without consuming bytes. Returns None if buffer is empty or contains incomplete sequence. Use this for drain operations to avoid losing input.
Drain consecutive matching keys using peek-then-consume. Call after receiving a navigation key to prevent scroll lag.
Drain all Escape keys from buffer. Call after modal close to prevent double-Esc navigation.
Convert key to string for PAGE.handle_key. Examples: Up -> "Up", Ctrl 'a' -> "C-a", Mouse {row=5; col=10; _} -> "Mouse:5:10"
Check if key is a navigation key (Up/Down/Left/Right/Tab/Delete/PageUp/PageDown/Home/End). These are candidates for draining.