Skip to content

ausimian/garnish

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Garnish

Hex.pm Version GitHub License

Garnish is a terminal-UI (TUI) framework built around via Erlang's ssh application.

asciicast

Installation

The package can be installed by adding garnish to your list of dependencies in mix.exs:

def deps do
  [
    {:garnish, "~> 0.2.0"}
  ]
end

Architecture

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:

  1. The Garnish.App behaviour is a little more idiomatic in its callback style.
  2. 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: ...
  ]
end

and 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)
  end

See 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.exs

and then connect over ssh

> ssh -o NoHostAuthenticationForLocalhost=yes -p 2222 localhost

Credits

The entire view and logical rendering framework is lifted from Ratatouille, with some renaming.

About

A Terminal UI Framework for Elixir Applications

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages