Artificery.Console (artificery v0.4.3)
A minimal logger.
Link to this section Summary
Functions
Ask the user to provide data in response to a question.
Updates the logger configuration with the given options.
Prints a debug message, only visible when verbose mode is on.
Prints an error message, and then halts the process.
Terminates the process with the given status code.
Prints an info message.
Prints a notice
Provides a spinner while some long-running work is being done.
Prints a success message
Updates a running spinner with the provided status text.
Prints a warning message
Write text or iodata to standard output.
Ask the user a question which requires a yes/no answer, returns a boolean.
Link to this section Functions
ask(question, opts \\ [])
Ask the user to provide data in response to a question.
The value returned is dependent on whether a transformation is applied,
and whether blank answers are accepted. By default, empty strings will
return nil if no alternate default is supplied and either no validator
was supplied, or it returned :ok
for blank answers.
If you supply a default, instead of nil, the default will be returned. Again this only applies if a blank answer is considered valid.
You may validate answers by supplying a function (bound or captured) via
the validator: fun
option. This function will receive the raw input string
supplied by the user, and should return :ok
if the answer is valid, or
{:error, validation_error}
, where validation_error
is a string which will
be displayed to the user before asking them to answer the question again.
You may apply a transformation to answers, so that rather than getting a
string back, you get the value in a state useful for your application. You may
provide a transform via the transform: fun
option, and this will receive the
raw input string the user provided after the validator has validated the input,
if one was supplied, and if the user input was non-nil.
Supply default values with the default: term
option.
configure(opts)
Specs
Updates the logger configuration with the given options.
debug(device \\ :stdio, msg)
Specs
debug(:standard_error | :stdio, String.t()) :: :ok
Prints a debug message, only visible when verbose mode is on.
error(device \\ :stdio, msg)
Specs
Prints an error message, and then halts the process.
halt(code)
Specs
halt(non_neg_integer()) :: :ok | no_return()
Terminates the process with the given status code.
info(device \\ :stdio, msg)
Specs
info(:standard_error | :stdio, String.t()) :: :ok
Prints an info message.
notice(device \\ :stdio, msg)
Specs
notice(:standard_error | :stdio, String.t()) :: :ok
Prints a notice
Provides a spinner while some long-running work is being done.
Options
:spinner
- one of the spinners defined in Artificery.Console.Spinner
Examples
Console.spinner "Loading...", [spinner: :simple_dots] do
:timer.sleep(5_000)
end
success(device \\ :stdio, msg)
Specs
success(:standard_error | :stdio, String.t()) :: :ok
Prints a success message
update_spinner(status)
Specs
update_spinner(String.t()) :: :ok
Updates a running spinner with the provided status text.
warn(device \\ :stdio, msg)
Specs
warn(:standard_error | :stdio, String.t()) :: :ok
Prints a warning message
write(msg)
Specs
write(iodata()) :: :ok
Write text or iodata to standard output.
You may optionally pass a list of styles to apply to the output, as well as the device to write to (:standard_error, or :stdio).
write(msg, styles)
Specs
write(device, msg, styles)
Specs
yes?(question)
Ask the user a question which requires a yes/no answer, returns a boolean.