View Source ExTerm.Router (ex_term v0.2.1)

Plug that marshals ExTerm options to be put in the session store.

by placing options in the session, it's possible for the initial html render and the socket-connected liveview to share common parameters.

This module also provides the helper function live_term/3 which wraps calling the plug (with options) and calling the Phoenix.LiveView.Router.live/4 macro into one directive.

Link to this section Summary

Functions

creates an ExTerm live terminal route, inside of a Phoenix Router

Link to this section Functions

Link to this macro

live_term(route, module_or_opts, opts \\ [])

View Source (macro)

creates an ExTerm live terminal route, inside of a Phoenix Router

You must supply a path, and optionally a backend module.

basic-usage

Basic Usage

The following code creates a router with the default ExTerm.TerminalBackend backend:

defmodule MyAppWeb.Router do
  use MyAppWeb, :router
  import ExTerm.Router

  pipeline :browser do
    plug :accepts, ["html"]
    plug :fetch_session
    plug :fetch_live_flash
    plug :put_root_layout, {MyAppWeb.LayoutView, :root}
    plug :protect_from_forgery
    plug :put_secure_browser_headers
  end

  import ExTerm.Router

  scope "/live_term" do
    pipe_through :browser

    live_term "/terminal", pubsub_server: MyAppWeb.PubSub
  end
end

alternative-backends

Alternative backends

If you would like to specify an alternative backend, you may provide this as a second parameter, which must be a module.

Other backends

There are currently no other backends shipped with :ex_term but backends to interface with other CLIs may be forthcoming.

scope "/live_term", MyBackend, pubsub_server: MyAppWeb.PubSub

options

Options

Required options

  • :pubsub_server A Phoenix.Pubsub server that will be used for Terminal backends to communicate back to the LiveView.

Optional options

  • :layout A twople of postive integers which specify the dimensions of the viewable console space.
  • :css may be an atom or {:priv, app, file_path}.
    • if an atom, may be :default or :bw, which are the builtin css files.
    • if a :priv tuple, at compile-time it will search the priv directory of the supplied application at the specified file_path to obtain the css file.

For documentation for backend-specific options, see ExTerm.TerminalBackend