Raxol.Protocols.Renderable protocol (Raxol v2.0.1)

View Source

Protocol for rendering data structures to terminal output.

This protocol provides a unified interface for rendering different types of data to the terminal. Any data structure that needs to be displayed in the terminal can implement this protocol.

Examples

defimpl Raxol.Protocols.Renderable, for: MyStruct do
  def render(data, opts) do
    # Return rendered string
  end

  def render_metadata(data) do
    %{width: 80, height: 24, colors: true}
  end
end

Summary

Types

t()

All the types that implement this protocol.

Functions

Renders the data structure to terminal output.

Gets rendering metadata for the data structure.

Types

t()

@type t() :: term()

All the types that implement this protocol.

Functions

render(data, opts \\ [])

@spec render(
  t(),
  keyword()
) :: binary()

Renders the data structure to terminal output.

Options

  • :width - Maximum width for rendering (default: 80)
  • :height - Maximum height for rendering (default: 24)
  • :colors - Whether to include color codes (default: true)
  • :style - Style map to apply during rendering
  • :theme - Theme to use for rendering

Returns

A binary string containing the rendered output with ANSI codes.

render_metadata(data)

@spec render_metadata(t()) :: map()

Gets rendering metadata for the data structure.

This helps the renderer understand the requirements and capabilities of the data being rendered.

Returns

A map containing:

  • :width - Preferred or required width
  • :height - Preferred or required height
  • :colors - Whether colors are used
  • :scrollable - Whether content is scrollable
  • :interactive - Whether content is interactive