View Source Garnish
Garnish is a terminal-UI (TUI) framework built around via Erlang's
ssh application.
Installation
The package can be installed by adding garnish to your list of dependencies
in mix.exs:
def deps do
[
{:garnish, "~> 0.2.0"}
]
endArchitecture
The architecure is heavily based on the approach taken by Ratatouille - indeed the entire view and rendering code has been copied from that project. The main differences are:
- The
Garnish.Appbehaviour is a little more idiomatic in its callback style. - The result of the rendering process is translated into escape sequences without the ExTermbox NIF requirement.
SSH Support
To expose your app via ssh, add ssh to the list of extra applications in mix.exs
def application do
[
extra_applications: [:logger, :ssh, ...],
mod: ...
]
endand start the ssh daemon e.g. in your application's start/2 callback:
@impl true
def start(_type, _args) do
opts = [
# ... other ssh opts
ssh_cli: {Garnish, app: My.App}
]
{:ok, ref} = :ssh.daemon({127,0,0,1}, 2222, opts)
children = [
]
opts = [strategy: :one_for_one, name: My.Supervisor]
with {:ok, pid} <- Supervisor.start_link(children, opts) do
{:ok, pid, ref}
end
end
@impl true
def stop(ref) do
:ssh.stop_daemon(ref)
endSee the Garnish.App behaviour for details of the application model.
Examples
To run the examples, first start the example, e.g.
> mix run --no-halt examples/counter.exsand then connect over ssh
> ssh -o NoHostAuthenticationForLocalhost=yes -p 2222 localhostCredits
The entire view and logical rendering framework is lifted from Ratatouille, with some renaming.