package lambda-term

  1. Overview
  2. Docs

Interactive line input

For a complete example of usage of this module, look at the shell example (examples/shell.ml) distributed with Lambda-Term.

exception Interrupt

Exception raised when the user presses Ctrl^D with an empty input.

type prompt = LTerm_text.t

Type of prompts.

type history = Zed_utf8.t list

Type of histories. It is a list of entries from the most recent to the oldest.

Completion
val common_prefix : string list -> string

Returns the common prefix of a list of words.

val lookup : Zed_utf8.t -> Zed_utf8.t list -> Zed_utf8.t list

lookup word words lookup for completion of word into words. It returns all words starting with word.

val lookup_assoc : Zed_utf8.t -> (Zed_utf8.t * 'a) list -> (Zed_utf8.t * 'a) list

lookup_assoc word words does the same as lookup but works on associative list.

Actions
type action =
  1. | Edit of LTerm_edit.action
    (*

    An edition action.

    *)
  2. | Interrupt_or_delete_next_char
    (*

    Interrupt if at the beginning of an empty line, or delete the next character.

    *)
  3. | Complete
    (*

    Complete current input.

    *)
  4. | Complete_bar_next
    (*

    Go to the next possible completion in the completion bar.

    *)
  5. | Complete_bar_prev
    (*

    Go to the previous possible completion in the completion bar.

    *)
  6. | Complete_bar_first
    (*

    Goto the beginning of the completion bar.

    *)
  7. | Complete_bar_last
    (*

    Goto the end of the completion bar.

    *)
  8. | Complete_bar
    (*

    Complete current input using the completion bar.

    *)
  9. | History_prev
    (*

    Go to the previous entry of the history.

    *)
  10. | History_next
    (*

    Go to the next entry of the history.

    *)
  11. | History_search_prev
    (*

    Search the previous entry of the history.

    *)
  12. | History_search_next
    (*

    Search the next entry of the history.

    *)
  13. | Accept
    (*

    Accept the current input.

    *)
  14. | Clear_screen
    (*

    Clear the screen.

    *)
  15. | Break
    (*

    Raise Sys.Break.

    *)
  16. | Suspend
    (*

    Suspend the program.

    *)
  17. | Edit_with_external_editor
    (*

    Launch external editor.

    *)

Type of actions.

val bind : LTerm_key.t list -> action list -> unit

bind seq actions associates actions to the given sequence.

val unbind : LTerm_key.t list -> unit

unbind seq unbinds seq.

val actions : (action * string) list

List of actions with their names, except Edit.

val doc_of_action : action -> string

doc_of_action action returns a short description of the action.

val action_of_name : string -> action

action_of_name str converts the given action name into an action. Action name are the same as variants name but lowercased and with '_' replaced by '-'. It raises Not_found if the name does not correspond to an action. It also recognizes edition actions.

val name_of_action : action -> string

name_of_action act returns the name of the given action.

The read-line engine
val macro : action Zed_macro.t

The global macro recorder.

type mode =
  1. | Edition
    (*

    Editing.

    *)
  2. | Search
    (*

    Backward search.

    *)
  3. | Set_counter
    (*

    Setting the macro counter value.

    *)
  4. | Add_counter
    (*

    Adding a value to the macro counter.

    *)

The current read-line mode.

class virtual 'a engine : ?history:history -> ?clipboard:Zed_edit.clipboard -> ?macro:action Zed_macro.t -> unit -> object ... end

The read-line engine. If no clipboard is provided, LTerm_edit.clipboard is used. If no macro recorder is provided, macro is used.

class virtual 'a abstract : object ... end

Abstract version of engine.

Predefined classes
class read_line : ?history:history -> unit -> object ... end

Simple read-line engine which returns the result as a string.

class read_password : unit -> object ... end

Read-line engine for reading a password. The stylise method default to replacing all characters by '*'. You can also for example completely disable displaying the password by doing:

type 'a read_keyword_result =
  1. | Rk_value of 'a
    (*

    The user typed a correct keyword and this is its associated value.

    *)
  2. | Rk_error of Zed_utf8.t
    (*

    The user did not enter a correct keyword and this is what he typed instead.

    *)

The result of reading a keyword.

class 'a read_keyword : ?history:history -> unit -> object ... end

Read a keyword.

Running in a terminal
class virtual 'a term : LTerm.t -> object ... end

Class for read-line instances running in a terminal.

OCaml

Innovation. Community. Security.