Module Interact.Make

Functor to construct an Interactive module from a given TTY module.

Typical usage is:

module I = Interact.Make (Interact.Tty (Null)) 

Parameters

module Tty : TTY

Signature

module Tty = Tty
val display : string -> unit

(display msg) prints msg to Tty.ttyout and flushes.

val norm : string -> string

(norm str) is str trimmed of whitespace on both ends and converted to lowercase.

This function works for ASCII only.

val read : ?norm:(string -> string) -> string -> string

(read ?norm prompt) prints the prompt on Tty.ttyout and then reads a one-line normalized string from Tty.ttyin.

The default value for ~norm is id (no normalization).

val query : ?norm:(string -> string) -> ?what:string -> (string -> bool) -> string -> string

(query ?norm ?what valid prompt) calls (read ?norm prompt) repeatedly until ((valid (read ?norm prompt)) = true).

~what is used as the prompt after receiving a bogus (not valid) answer; the default is "What? ".

The normalized response is returned.

The default value for ~norm is as for read.

val oneof : string list -> string -> bool

(oneof list) is a validator for query that accepts any of the strings in list.

val whatof : string list -> string

(whatof list) returns a string suitable for query's ~what parameter:

  • (query ~what:(whatof list) (oneof list)).
val yorn : ?norm:(string -> string) -> ?what:string -> string -> string

(yorn ?norm ?what prompt) calls (read ?norm prompt) repeatedly until a "y" or "n" answer is received.

Any string beginning (after normalization) with either "y" or "n" is acceptable as an answer.

~what is as for query.

The normalized answer is returned.

val yesorno : ?norm:(string -> string) -> ?what:string -> string -> string

yesorno is a stricter yorn that insists on a normalized answer of exactly either "yes" or "no".

val okay : ?what:string -> string -> bool

(okay ?what prompt) returns true iff (yorn ?what prompt) returns a "y" answer.