package mopsa

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

Simple line-editing for interactive sessions in the terminal. Assumes an UTF-8 console with standard ANSI escape codes.

Entering raw mode

*********************

val org_stdin_attr : Unix.terminal_io option
val tc_available : unit -> bool

Whether terminal control is available

val enter_raw_mode : unit -> unit

Enter raw mode before starting line edition.

val exit_raw_mode : unit -> unit

Exit raw mode after finishing line edition. Do not call print to the console when in raw mode.

FIFO character buffer

*************************

module FIFO : sig ... end

Character input

*******************

val read_char_unbuf_opt : unit -> char option

Non blocking read_char.

val read_char_unbuf : unit -> char

Block until a char is available and return it.

val rabuf : FIFO.t

We may need to scan the input to get the answer for a get_position call. Hence, we keep a FIFO of inputs read while scanning.

val unread_char : char -> unit

Put (back) in FIFO.

val unread_char_list : char list -> unit
val read_char_opt : unit -> char option

Non blocking read_char. Fetch from the read-ahead buffer first.

val read_char : unit -> char

Block until a char is available and return it. Fetch from the read-ahead buffer first.

val read_flush : unit -> unit

Put all chars possible in the read-ahead buffer.

Cursor manipulation

***********************

val pf : ('a, out_channel, unit) format -> 'a
val ps : string -> unit
val cursor_up : int -> unit

Moves the cursor up, down, left, or right n positions.

val cursor_down : int -> unit
val cursor_right : int -> unit
val cursor_left : int -> unit
val next_line : int -> unit

Go to the begining of the n-th next / previous line.

val perv_line : int -> unit
val set_column : int -> unit

Move to line l, column c (starting at 1).

val set_position : int -> int -> unit
val clear_screen : unit -> unit

Clear the whole screen / line.

val clear_line : unit -> unit
val clear_end_screen : unit -> unit

Clear the screen / line from the cursor position until the end.

val clear_end_line : unit -> unit
val clear_start_screen : unit -> unit

Clear the screen / line up to the cursor position from the begining.

val clear_start_line : unit -> unit
val scroll_up : int -> unit

Scroll some number of lines up / down.

val scroll_down : int -> unit
val save_position : unit -> unit

Save / restore the cursor position.

val restore_position : unit -> unit
val get_position : unit -> int * int

Return the cursur line and column (starting at 1). Return (0,0) in case of an error.

val get_window_size : unit -> int * int

Return the height and width of the window.

UTF-8 buffers

*****************

val sizeof_uchar : char -> int

Byte-size of the utf-8 char starting with code c.

module UBuf : sig ... end

Buffers backed by byte sequences that grow automatically. Support insertion and deletion at any position within the buffer. Include some support for UTF-8 encoding.

Line editing

****************

type ctx = {
  1. mutable ctx_history : UBuf.t list;
}

Line edition context, maintained between calls to read_line.

val create_ctx : unit -> ctx
val backslash_eol : Str.regexp
val read_line_tc : ctx -> string

Main line editing function, with support for cursor movement and history. You can print a prompt before calling this function. Return the string that was read. Throw Exit when Ctrl+C or Ctrl+D is typed.

val read_line : ctx -> string

Line edition, with fall-back to Stdlib.read_line if there is no terminal control.

OCaml

Innovation. Community. Security.