Raxol.Protocols.BehaviourAdapter (Raxol v2.0.1)

View Source

Adapter module to help migrate from behaviours to protocols.

This module provides adapter functions that bridge the gap between the old behaviour-based system and the new protocol-based system, allowing for gradual migration without breaking existing code.

Usage

For modules implementing behaviours, you can use this adapter to automatically implement the corresponding protocols:

defmodule MyRenderer do
  @behaviour Raxol.Terminal.RendererBehaviour
  use Raxol.Protocols.BehaviourAdapter, :renderer

  # Your existing behaviour callbacks...
end

This will automatically implement the Renderable protocol for your module.

Summary

Functions

Macro to inject protocol implementations based on behaviour type.

Wraps a behaviour-implementing module to work with protocol-expecting code.

Functions

__using__(adapter_type)

(macro)

Macro to inject protocol implementations based on behaviour type.

wrap_buffer(buffer)

wrap_event_handler(handler)

wrap_renderer(renderer)

Wraps a behaviour-implementing module to work with protocol-expecting code.

Examples

# Old behaviour-based renderer
renderer = MyRenderer.new(buffer)

# Wrap it to work with protocol-expecting code
wrapped = BehaviourAdapter.wrap_renderer(renderer)
Raxol.Protocols.Renderable.render(wrapped, [])