package bestline

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type
exception BestlineError of string * int
val bestline : string -> string option

Reads line intelligently.

The high level function that is the main API of the bestline library. This function checks if the terminal has basic capabilities, just checking for a blacklist of inarticulate terminals, and later either calls the line editing function or uses dummy fgets() so that you will be able to type something even in the most desperate of the conditions.

  • parameter prompt

    is printed before asking for input if we have a term and this may be set to empty to disable and prompt may contain ansi escape sequences, color, utf8, etc.

  • returns

    chomped allocated string of read line or None on eof/error

val bestline_raw : string -> Unix.file_descr -> Unix.file_descr -> string option

Reads line interactively.

This function can be used instead of bestline() in cases where we know for certain we're dealing with a terminal, which means we can avoid linking any stdio code.

  • returns

    chomped allocated string of read line or None on eof/error

val bestline_with_history : string -> string -> string option

Reads line intelligently w/ history, e.g.

(* see ~/.foo_history *) let () = let go () = match bestline_with_history("In> ", "foo") with | None -> () | Some line -> Printf.printf "OUT> %s\n" line; go () go ()

  • parameter prompt

    is printed before asking for input if we have a term and this may be set to empty to disable and prompt may contain ansi escape sequences, color, utf8, etc.

  • parameter prog

    is name of your app, used to generate history filename however if it contains a slash / dot then we'll assume prog is the history filename which as determined by the caller

  • returns

    chomped allocated string of read line or None on eof/error

val history_add : string -> bool
val history_save_raw : string -> int option
val history_save : string -> unit
val history_load_raw : string -> int option
val history_load : string -> unit
val history_free : unit -> unit
val clear_screen : Unix.file_descr -> unit

Clear the screen. Used to handle ctrl+l

val mask_mode_enable : unit -> unit

Enables "mask mode".

When it is enabled, instead of the input that the user is typing, the terminal will just display a corresponding number of asterisks, like "****". This is useful for passwords and other secrets that should not be displayed.

@see bestlineMaskModeDisable()

val mask_mode_disable : unit -> unit
val disable_raw_mode : unit -> unit
val is_separator : char -> bool
val not_separator : char -> bool
val is_xeparator : char -> bool
val uppercase : char -> char
val lowercase : char -> char
OCaml

Innovation. Community. Security.