package spin
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=eeef9d3b89cca796d8d47ba425cee131bf14b5b0f1349927c4d8b22297b1f6b6
sha512=1850cad87f180b37e658e716986f6aa0ba76e57d6638d40b8f6e8ae2c6f60deee82218464e02356632022b394f49cc5a341e7255112aef455ffec9ca2db4cc32
doc/spin.inquire/Inquire/index.html
Module Inquire
Source
Inquire is a high-level library to create interactive command line interfaces.
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) 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) 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
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
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
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.