View Source ExTerm.Backend behaviour (ex_term v0.2.0)

This behaviour defines the contract that an ExTerm backend must implement to respond to inbound user events.

Link to this section Summary

Callbacks

triggered when the terminal loses focus.

forwarded from the Phoenix.LiveView.mount/3 callback, but only on the second pass when the socket connects.

triggered when the terminal gets focus.

triggered when the user presses on a key when the terminal has focus.

triggered when the user lets go of a key when the terminal has focus.

triggered when the user pastes content into the terminal.

Link to this section Types

@type json() ::
  String.t()
  | nil
  | boolean()
  | number()
  | [json()]
  | %{optional(String.t()) => json()}
@type params() :: %{optional(String.t()) => term()}
@type session() :: %{optional(String.t()) => term()}

Link to this section Callbacks

@callback on_blur(Phoenix.LiveView.Socket.t()) :: {:noreply, Phoenix.LiveView.Socket.t()}

triggered when the terminal loses focus.

Link to this callback

on_connect(params, session, t)

View Source
@callback on_connect(params(), session(), Phoenix.LiveView.Socket.t()) ::
  {:ok, Console.t(), Phoenix.LiveView.Socket.t()}

forwarded from the Phoenix.LiveView.mount/3 callback, but only on the second pass when the socket connects.

An ExTerm terminal does not display any data until the websocket connection has been established.

Link to this callback

on_event(type, payload, t)

View Source (optional)
@callback on_event(type :: String.t(), payload :: json(), Phoenix.LiveView.Socket.t()) ::
  {:noreply, Phoenix.LiveView.Socket.t()}

forwarded from the Phoenix.LiveView.handle_event/3 callback.

This callback is only invoked for events that aren't handled by the other callbacks.

note

Note

This callback should not be implemented unless customizing the terminal in ways that are not currently supported; this is a future placeholder.

@callback on_focus(Phoenix.LiveView.Socket.t()) :: {:noreply, Phoenix.LiveView.Socket.t()}

triggered when the terminal gets focus.

@callback on_keydown(key :: String.t(), Phoenix.LiveView.Socket.t()) ::
  {:noreply, Phoenix.LiveView.Socket.t()}

triggered when the user presses on a key when the terminal has focus.

see also https://developer.mozilla.org/en-US/docs/Web/API/Element/keydown_event the key string is corresponds to the KeyboardEvent.key field.

for documentation on non-character key strings that can be passed to the callback, see: https://developer.mozilla.org/en-US/docs/Web/API/UI_Events/Keyboard_event_key_values

Aside from capitalization of standard characters, it's the backend's responsibility to track modifier keys, for example "Control"

@callback on_keyup(key :: String.t(), Phoenix.LiveView.Socket.t()) ::
  {:noreply, Phoenix.LiveView.Socket.t()}

triggered when the user lets go of a key when the terminal has focus.

see also https://developer.mozilla.org/en-US/docs/Web/API/Element/keyup_event the key string is corresponds to the KeyboardEvent.key field.

for documentation on non-character key strings that can be passed to the callback, see: https://developer.mozilla.org/en-US/docs/Web/API/UI_Events/Keyboard_event_key_values

Aside from capitalization of standard characters, it's the backend's responsibility to track modifier keys, for example "Control"

@callback on_paste(String.t(), Phoenix.LiveView.Socket.t()) ::
  {:noreply, Phoenix.LiveView.Socket.t()}

triggered when the user pastes content into the terminal.