package spin

  1. Overview
  2. Docs

Inquire is a high-level library to create interactive command line interfaces.

exception Interrupted_by_user
module Style : sig ... end

Module to customize Inquire prompts.

val confirm : ?default:bool -> ?auto_enter:bool -> ?style:Style.t -> string -> bool

Prompt the user to answer the given message with "y" or "n".

Examples

Inquire.confirm "Are you sure?" ~default:true |> fun choice ->
if choice then print_endline "Yes!" else print_endline "No!"
val password : ?validate:(string -> (string, string) Stdlib.result) -> ?default:string -> ?style:Style.t -> string -> string

Prompt the user to enter a password that will be hidden.

The password can take any value, except the empty string.

On Unix, this works by setting the echo mode of the terminal to off.

On Windows, we print "\x1b8m" before prompting the password and "\x1b[0m" after. {4 Examples} {[ Inquire.password "Enter your password:" |> fun password -> print_endline "Your new password is: %S" password ]}

val input : ?validate:(string -> (string, string) Stdlib.result) -> ?default:string -> ?style:Style.t -> string -> string

Prompt the user to input a string.

The string can take any value, except the empty string.

Examples

Inquire.input "Enter a value:" |> fun value ->
print_endline "You entered: %S" value
val raw_select : ?default:int -> ?style:Style.t -> options:string list -> string -> string

Prompt the user to chose a value from the given options. The options will be listed with an index prefixed and the users will have to enter the index of their choice.

Note that raw_select does not support more than 9 options. If you need more options, please use select instead.

Examples

let movies =
  [ "Star Wars: The Rise of Skywalker"
  ; "Solo: A Star Wars Story"
  ; "Star Wars: The Last Jedi"
  ; "Rogue One: A Star Wars Story"
  ; "Star Wars: The Force Awakens"
  ]
in
Inquire.raw_select "What's your favorite movie?" ~options:movies
|> fun movie -> print_endline "Indeed, %S is a great movie!" movie
val select : ?default:int -> ?style:Style.t -> options:string list -> string -> string

Prompt the user to chose a value from the given options. The prompt is interactive and users can select their choice with directional keys.

Examples

let movies =
  [ "Star Wars: The Rise of Skywalker"
  ; "Solo: A Star Wars Story"
  ; "Star Wars: The Last Jedi"
  ; "Rogue One: A Star Wars Story"
  ; "Star Wars: The Force Awakens"
  ]
in
Inquire.select "What's your favorite movie?" ~options:movies
|> fun movie -> print_endline "Indeed, %S is a great movie!" movie
val set_exit_on_user_interrupt : bool -> unit

Configure the behavior on user interruptions during a prompt.

If exit_on_user_interrupt is true, the program will exit with status code 130. If it is false, an Interrupted_by_user exception is raised.

The default behavior is to exit on user interruptions.

OCaml

Innovation. Community. Security.