Ratatouille v0.5.1 Ratatouille.Window View Source

A GenServer to manage the terminal window, along with a client API to perform updates and retrieve window information.

Link to this section Summary

Functions

Returns a specification to start this module under a supervisor.

Closes the window by stopping the GenServer. Prior to this, termbox is de-initialized so that the terminal is restored to its previous state.

Fetches an attribute for the window. This is currently limited to the window dimensions, which can be useful when laying out content.

Starts the gen_server representing the window.

Updates the window by rendering the given view to the termbox buffer and presenting it.

Link to this section Types

Link to this type

fetch_attr()

View Source
fetch_attr() :: :width | :height | :box

Link to this section Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

close(pid \\ __MODULE__)

View Source
close(GenServer.server()) :: :ok

Closes the window by stopping the GenServer. Prior to this, termbox is de-initialized so that the terminal is restored to its previous state.

Link to this function

fetch(pid \\ __MODULE__, attr)

View Source
fetch(GenServer.server(), fetch_attr()) :: term()

Fetches an attribute for the window. This is currently limited to the window dimensions, which can be useful when laying out content.

Examples

iex> Window.fetch(:height)
{:ok, 124}
iex> Window.fetch(:width)
{:ok, 50}
iex> Window.fetch(:foo)
{:error, :unknown_attribute}
Link to this function

start_link(opts \\ [])

View Source
start_link(Keyword.t()) :: GenServer.on_start()

Starts the gen_server representing the window.

The window is intended to be run as a singleton gen_server process, as initializing the underlying termbox library multiple times on the same TTY can lead to undefined behavior.

Options

Link to this function

update(pid \\ __MODULE__, view)

View Source
update(GenServer.server(), Ratatouille.Renderer.Element.t()) :: :ok

Updates the window by rendering the given view to the termbox buffer and presenting it.