View Source Tux.Show behaviour (Tux v0.4.0)
This module is responsible for converting the Tux.Result returned by a command
module to a string representation, and then sending it to the device (by default
the :stdio) defined in the Tux.Env struct.
In the case a command returns non-successful results (e.g. errors, warnings)
this module will extract the appropriate information they carry via the
Tux.Alertable protocol.
Summary
Callbacks
Write the result returned by a command module to the device defined in that command's env.
Functions
This is used internally by the Tux.Dispatcher and Tux.Command
to inject the show routines.
Write a command result to the IO device.
Write a string-able item to a IO device with or without a newline.
Types
@type device() :: IO.device()
A device as supported by the IO module.
@type stringable() :: String.Chars.t()
A term convertible to a string
Callbacks
@callback show(env :: Tux.Env.t(), result :: Tux.Result.t()) :: :ok
Write the result returned by a command module to the device defined in that command's env.
Functions
This is used internally by the Tux.Dispatcher and Tux.Command
to inject the show routines.
@spec show(Tux.Env.t(), Tux.Result.t()) :: :ok
Write a command result to the IO device.
Caveats
When the given result is
:ok, it writes only an empty string and no newline, irrespective of whether the env's newline was set totrue, because such a result means the command was successful but no other information was returned.When the given result is
{:ok, term}, then it will append a newline to the term only if theuse Tux.Dispatcher, newline: truewas set. Note that this is the default behaviour so there's no need to setnewline: true, however you can optionally prevent newlines from being written by specifyingnewline: falsewhenuseing the Dispatcher.The result
{:error, term}will be shown asTux.AlertNote that you can also overwrite
show/2in your own command module this way you have full control over how any particalar command displays its results.
@spec write(stringable(), device(), boolean()) :: :ok
Write a string-able item to a IO device with or without a newline.
Examples
Tux.Show.write("something", :stdio, true)
something
:ok
Tux.Show.write("something", :stdio, false)
something:ok