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

Types

A device as supported by the IO module.

A term convertible to a string

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

device()

@type device() :: IO.device()

A device as supported by the IO module.

stringable()

@type stringable() :: String.Chars.t()

A term convertible to a string

Callbacks

show(env, result)

@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

__using__(opts \\ [])

(macro)

This is used internally by the Tux.Dispatcher and Tux.Command to inject the show routines.

show(env, arg2)

@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 to true, 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 the use Tux.Dispatcher, newline: true was set. Note that this is the default behaviour so there's no need to set newline: true, however you can optionally prevent newlines from being written by specifying newline: false when useing the Dispatcher.

  • The result {:error, term} will be shown as Tux.Alert

  • Note that you can also overwrite show/2 in your own command module this way you have full control over how any particalar command displays its results.

write(stringable, device, newline)

@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