package bestline

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

Module BestlineSource

Sourceexception BestlineError of string * int
Sourceval 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

Sourceval 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

Sourceval 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

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

Clear the screen. Used to handle ctrl+l

Sourceval 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()

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

Innovation. Community. Security.