package mopsa

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

Module Utils_core.LineEditSource

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

Entering raw mode

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

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

Whether terminal control is available

Sourceval enter_raw_mode : unit -> unit

Enter raw mode before starting line edition.

Sourceval 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

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

Sourcemodule FIFO : sig ... end

Character input

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

Sourceval read_char_unbuf_opt : unit -> char option

Non blocking read_char.

Sourceval read_char_unbuf : unit -> char

Block until a char is available and return it.

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

Sourceval unread_char : char -> unit

Put (back) in FIFO.

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

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

Sourceval read_char : unit -> char

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

Sourceval read_flush : unit -> unit

Put all chars possible in the read-ahead buffer.

Cursor manipulation

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

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

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

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

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

Sourceval perv_line : int -> unit
Sourceval set_column : int -> unit

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

Sourceval set_position : int -> int -> unit
Sourceval clear_screen : unit -> unit

Clear the whole screen / line.

Sourceval clear_line : unit -> unit
Sourceval clear_end_screen : unit -> unit

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

Sourceval clear_end_line : unit -> unit
Sourceval clear_start_screen : unit -> unit

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

Sourceval clear_start_line : unit -> unit
Sourceval scroll_up : int -> unit

Scroll some number of lines up / down.

Sourceval scroll_down : int -> unit
Sourceval save_position : unit -> unit

Save / restore the cursor position.

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

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

Sourceval get_window_size : unit -> int * int

Return the height and width of the window.

UTF-8 buffers

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

Sourceval sizeof_uchar : char -> int

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

Sourcemodule 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

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

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

Line edition context, maintained between calls to read_line.

Sourceval create_ctx : unit -> ctx
Sourceval backslash_eol : Str.regexp
Sourceval 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.

Sourceval read_line : ctx -> string

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

OCaml

Innovation. Community. Security.