View Source ExTerm (ex_term v0.2.1)

description

Description

ExTerm is a terminal Phoenix.LiveView. By default, ExTerm provides an IEx terminal usable as a web interface, however, this is customizable and you may use ExTerm for other CLIs.

Under the hood, ExTerm is a generic interface for converting erlang IO protocol messages into web output and translating web input into responses in the IO protocol.

installation

Installation

Add ExTerm to your mix.exs:


def deps do
[
  # ...
  {:ex_term, "~> 0.2"}
  # ...
]
end

how-to-create-a-live-terminal-in-your-phoenix-router

How to create a live terminal in your Phoenix router

ExTerm provides the convenience helper ExTerm.Router.live_term/3 that you can use to create a live view route.

You must supply a Phoenix.PubSub server that is the communication channel to send important updates to the liveview. It's recommended to use the PubSub server associated with your web server.

The default backend is ExTerm.TerminalBackend and the default terminal is IEx.Server. Both of these are customizable.

  • with the default backend and default terminal

    import ExTerm.Router
    
    scope "/live_term" do
      pipe_through :browser
    
      live_term "/", pubsub_server: MyAppWeb.PubSub
    end
  • with the default backend and a custom interaction layer

    import ExTerm.Router
    
    scope "/live_term" do
      pipe_through :browser
    
      live_term "/", pubsub_server: MyAppWeb.PubSub, terminal: {__MODULE__, :function, []}
    end
  • with a custom backend

    import ExTerm.Router
    
    scope "/live_term" do
      pipe_through :browser
    
      live_term "/", MyBackend, pubsub_server: MyAppWeb.PubSub
    end

customizing-layout-css

Customizing layout (CSS)

You can customize the css for the layout, by providing either a builtin layout option or providing your own. To use a builtin layout, pass the layout name :default or :bw (for black and white console text) as the css option, as follows:

  live_term "/", pubsub_server: MyAppWeb.PubSub, css: :bw

To use a custom layout, put the layout file in the priv directory of your applicatyon and pass the relative path as follows:

  live_term "/", MyBackend, pubsub_server: MyAppWeb.PubSub, css: {:priv, my_app, "path/to/my_layout.css"}

Note that this content must be available at compile time.