Raxol.Plugins.EventHandler (Raxol v0.5.0)

View Source

Handles dispatching various events (input, resize, mouse, etc.) to plugins.

Provides a generic mechanism to iterate through enabled plugins and invoke specific callback functions defined by the Raxol.Plugins.Plugin behaviour. Updates the plugin manager state based on the results returned by the plugins.

Summary

Functions

Dispatches an "input" event to all enabled plugins implementing handle_input/2.

Dispatches a key event to enabled plugins implementing handle_input/2. Returns {:ok, updated_manager, :propagate | :halt} or {:error, reason}.

Dispatches a mouse event to all enabled plugins implementing handle_mouse/3. Returns {:ok, updated_manager, :propagate | :halt} or {:error, reason}.

Dispatches an "output" event to all enabled plugins implementing handle_output/2. Accumulates transformed output.

Dispatches a "resize" event to all enabled plugins implementing handle_resize/3.

Types

accumulator()

@type accumulator() :: any()

callback_name()

@type callback_name() :: atom()

event()

@type event() :: map()

event_args()

@type event_args() :: [any()]

handler_payload()

@type handler_payload() :: accumulator() | {:error, term()}

handler_result()

@type handler_result() :: {:cont | :halt, handler_payload()}

manager()

@type manager() :: Raxol.Plugins.Manager.Core.t()

plugin()

@type plugin() :: map()

propagation()

@type propagation() :: :propagate | :halt

result()

@type result() :: {:ok, manager()} | {:error, term()}

Functions

handle_input(manager, input)

@spec handle_input(Raxol.Plugins.Manager.Core.t(), binary()) :: result()

Dispatches an "input" event to all enabled plugins implementing handle_input/2.

handle_key_event(manager, key_event)

@spec handle_key_event(Raxol.Plugins.Manager.Core.t(), map()) ::
  {:ok, Raxol.Plugins.Manager.Core.t(), propagation()} | {:error, term()}

Dispatches a key event to enabled plugins implementing handle_input/2. Returns {:ok, updated_manager, :propagate | :halt} or {:error, reason}.

handle_mouse_event(manager, event, rendered_cells)

@spec handle_mouse_event(Raxol.Plugins.Manager.Core.t(), map(), map()) ::
  {:ok, Raxol.Plugins.Manager.Core.t(), propagation()} | {:error, term()}

Dispatches a mouse event to all enabled plugins implementing handle_mouse/3. Returns {:ok, updated_manager, :propagate | :halt} or {:error, reason}.

handle_output(manager, output)

@spec handle_output(Raxol.Plugins.Manager.Core.t(), binary()) ::
  {:ok, Raxol.Plugins.Manager.Core.t(), binary()} | {:error, term()}

Dispatches an "output" event to all enabled plugins implementing handle_output/2. Accumulates transformed output.

handle_resize(manager, width, height)

@spec handle_resize(Raxol.Plugins.Manager.Core.t(), integer(), integer()) :: result()

Dispatches a "resize" event to all enabled plugins implementing handle_resize/3.