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 section Functions
Returns a specification to start this module under a supervisor.
See 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.
fetch(pid \\ __MODULE__, attr)
View Sourcefetch(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}
start_link(opts \\ [])
View Sourcestart_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
:name
- Override the name passed toGenServer.start_link/3
. Bydefault, `name: Ratatouille.Window` is passed in order to protect against accidental double initialization, but this can be overridden by passing `nil` or an alternate value.
:input_mode
- Configure the input mode. SeeRatatouille.Constants.input_mode/1
for possible values.
:output_mode
- Configure the output mode. SeeRatatouille.Constants.output_mode/1
for possible values.
update(pid \\ __MODULE__, view)
View Sourceupdate(GenServer.server(), Ratatouille.Renderer.Element.t()) :: :ok
Updates the window by rendering the given view to the termbox buffer and presenting it.