package terml

  1. Overview
  2. Docs
type key_code =
  1. | Escape
  2. | Char of string
  3. | Up
  4. | Down
  5. | Left
  6. | Right
type key_modifiers =
  1. | Shift
  2. | Ctrl
  3. | Alt
  4. | Super
  5. | Hyper
  6. | Meta
type key_event = {
  1. code : key_code;
  2. modifier : key_modifiers option;
}
type t =
  1. | Key of key_event
val handle_csi_key : 'a -> t
val handle_csi : (module Input_source.t) -> t

handle_csi () handles the case where we have a control sequence introducer.

This function decides what to do next based on the next key read from the input source.

  • if the next key is a [, we may have an arrow, function key or other special key;
  • if not, we just return the escape key event.
val next_event : (module Input_source.t) -> t option

next_event () reads the next key event from the input source.

This function reads from the input source and returns a key event if it finds one. If it doesn't find a key event, it returns None.

events read from the input source (e.g. stdin) are then converted into key events that can be used by the application.

val poll : unit -> t Event.channel

poll () returns a channel that will be populated with key events as they are read from the input source. (e.g. stdin)

This function spawns a new thead that will read from the input source to avoid blocking the main thread.

val read : unit -> [ `End | `Malformed of string | `Read of string | `Retry ]
OCaml

Innovation. Community. Security.