package miaou-core

  1. Overview
  2. Docs
Miaou core/widgets (no drivers, no SDL)

Install

dune-project
 Dependency

Authors

Maintainers

Sources

v0.5.2.tar.gz
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 *)
Sourcetype key =
  1. | Char of string
    (*

    Regular character or UTF-8 grapheme

    *)
  2. | Enter
  3. | AltEnter
    (*

    Alt+Enter (ESC followed by newline)

    *)
  4. | Tab
  5. | ShiftTab
    (*

    Shift+Tab / backtab (ESC Z)

    *)
  6. | Backspace
  7. | Escape
  8. | Up
  9. | Down
  10. | Left
  11. | Right
  12. | PageUp
    (*

    ESC 5 ~

    *)
  13. | PageDown
    (*

    ESC 6 ~

    *)
  14. | Home
    (*

    ESC H, ESC O H, ESC [ 1 ~, ESC [ 7 ~

    *)
  15. | End
    (*

    ESC F, ESC O F, ESC [ 4 ~, ESC [ 8 ~

    *)
  16. | Delete
  17. | Ctrl of char
    (*

    Control + letter, e.g., Ctrl 'a' for C-a

    *)
  18. | Mouse of {
    1. row : int;
    2. col : int;
    3. button : int;
    4. release : bool;
    }
    (*

    Mouse click. button is 0=left, 1=middle, 2=right. release is true for button release (actual click).

    *)
  19. | MouseDrag of {
    1. row : int;
    2. col : int;
    }
    (*

    Mouse motion while button held. Emitted during drag operations.

    *)
  20. | WheelUp of {
    1. row : int;
    2. col : int;
    }
    (*

    Mouse wheel scroll up

    *)
  21. | WheelDown of {
    1. row : int;
    2. col : int;
    }
    (*

    Mouse wheel scroll down

    *)
  22. | Refresh
    (*

    Synthetic refresh marker (null byte)

    *)
  23. | Unknown of string
    (*

    Unrecognized escape sequence

    *)

Parsed key event.

Sourcetype t

Parser state.

Sourceval create : Unix.file_descr -> t

Create a new parser for the given file descriptor.

Sourceval refill : t -> timeout_s:float -> int

Read bytes into buffer with timeout.

  • parameter timeout_s

    Timeout in seconds (0.0 for non-blocking)

  • returns

    Number of bytes read

Sourceval refill_nonblocking : t -> int

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).

  • returns

    Number of bytes read, or 0 on EINTR / nothing available.

Return the underlying file descriptor.

Sourceval parse_key : t -> key option

Parse next key from buffer, consuming the bytes. Returns None if buffer is empty.

Sourceval peek_key : t -> key option

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.

Sourceval drain_matching : t -> key -> int

Drain consecutive matching keys using peek-then-consume. Call after receiving a navigation key to prevent scroll lag.

  • returns

    Count of drained keys

Sourceval drain_esc : t -> int

Drain all Escape keys from buffer. Call after modal close to prevent double-Esc navigation.

  • returns

    Count of drained keys

Sourceval key_to_string : key -> string

Convert key to string for PAGE.handle_key. Examples: Up -> "Up", Ctrl 'a' -> "C-a", Mouse {row=5; col=10; _} -> "Mouse:5:10"

Sourceval is_nav_key : key -> bool

Check if key is a navigation key (Up/Down/Left/Right/Tab/Delete/PageUp/PageDown/Home/End). These are candidates for draining.

Sourceval pending_length : t -> int

Get pending buffer length (for debugging).

Sourceval clear : t -> unit

Clear pending buffer.