Harpoon.Io
Centralizes high-level Harpoon input-output capabilities.
Type of IO capabilities. Includes:
When a function needs user interactivity, pass this object to it. If it only needs an output capability, see Format.formatter
.
val make : InputPrompt.t -> Stdlib.Format.formatter -> t
Constructs an IO capability.
val formatter : t -> Stdlib.Format.formatter
Extracts the formatter from an IO capability.
val prompt_number : t -> int
Gets the number of the last prompt that was shown.
val printf : t -> ('a, Stdlib.Format.formatter, unit) Stdlib.format -> 'a
Displays a formatted message.
val read_line :
?source:string ->
t ->
msg:string ->
history_file:string option ->
Beluga_syntax.Location.t * string
read_line ?source io ~msg ~history_file
prompts the user for input by displaying the given message. The input line is output. The returned location is an empty location having source
as filename and the number of lines input so far as the line number.
The default value of ?source
is default_source_prompt
.
An exception is raised if there are no more lines in the input.
val prompt_input :
?source:string ->
t ->
msg:string ->
history_file:string option ->
(Beluga_syntax.Location.t -> string -> 'a) ->
'a
prompt_input ?source io ~msg ~history_file f
repeatedly prompts the user for an input to pass to f
until a call to f
does not throw. That is, it calls read_line ?source io ~msg ~history_file
, then passes the result to f
. If f
raises an exception, then it is caught, printed, and prompt_input
is called once more.
Make sure that f
can fail gracefully (by cleaning up in case of a raised exception) because any exception from f
will be suppressed.