Raxol.Plugins.EventHandler (Raxol v0.3.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 (map) to enabled plugins implementing handle_input/2. NOTE: Uses handle_input/2 as per the original PluginManager logic. Consider adding

Dispatches a mouse event (new format with propagation control) to enabled plugins implementing handle_mouse/3.

Dispatches a 'mouse' event (older format) to all enabled plugins implementing handle_mouse/3. This corresponds to the PluginManager.process_mouse/3 function.

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_args()

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

handler_payload()

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

handler_result()

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

Functions

handle_input(manager, input)

@spec handle_input(Raxol.Plugins.PluginManager.t(), binary()) ::
  {:ok, Raxol.Plugins.PluginManager.t()} | {:error, any()}

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

handle_key_event(manager, event, rendered_cells)

@spec handle_key_event(Raxol.Plugins.PluginManager.t(), map(), map()) ::
  {:ok, Raxol.Plugins.PluginManager.t(), [any()], :propagate | :halt}
  | {:error, any()}

Dispatches a key event (map) to enabled plugins implementing handle_input/2. NOTE: Uses handle_input/2 as per the original PluginManager logic. Consider adding

  a dedicated `handle_key_event` callback to the Plugin behaviour later.

Accumulates commands and handles propagation control.

handle_mouse_event(manager, event, rendered_cells)

@spec handle_mouse_event(Raxol.Plugins.PluginManager.t(), map(), map()) ::
  {:ok, Raxol.Plugins.PluginManager.t(), :propagate | :halt} | {:error, any()}

Dispatches a mouse event (new format with propagation control) to enabled plugins implementing handle_mouse/3.

handle_mouse_legacy(manager, event, emulator_state)

@spec handle_mouse_legacy(Raxol.Plugins.PluginManager.t(), tuple(), map()) ::
  {:ok, Raxol.Plugins.PluginManager.t()} | {:error, any()}

Dispatches a 'mouse' event (older format) to all enabled plugins implementing handle_mouse/3. This corresponds to the PluginManager.process_mouse/3 function.

handle_output(manager, output)

@spec handle_output(Raxol.Plugins.PluginManager.t(), binary()) ::
  {:ok, Raxol.Plugins.PluginManager.t(), binary()} | {:error, any()}

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.PluginManager.t(), integer(), integer()) ::
  {:ok, Raxol.Plugins.PluginManager.t()} | {:error, any()}

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