Raxol Plugin

Hex.pmDocumentation

Plugin framework for Raxol terminal applications. Build extensible terminal UIs with a simple behavior-based API.

Installation

def deps do
  [
    {:raxol_core, "~> 2.0"},
    {:raxol_plugin, "~> 2.0"}
  ]
end

Quick Start

defmodule MyPlugin do
  @behaviour Raxol.Plugin

  alias Raxol.Core.Buffer

  @impl true
  def init(_opts), do: {:ok, %{counter: 0}}

  @impl true
  def handle_input(key, _modifiers, state) do
    case key do
      " " -> {:ok, %{state | counter: state.counter + 1}}
      "r" -> {:ok, %{counter: 0}}
      "q" -> {:exit, state}
      _ -> {:ok, state}
    end
  end

  @impl true
  def render(buffer, state) do
    buffer
    |> Buffer.write_at(0, 0, "Counter: #{state.counter}")
    |> Buffer.write_at(0, 1, "Press SPACE to increment, R to reset, Q to quit")
  end

  @impl true
  def cleanup(_state), do: :ok
end

# Run it
Raxol.Plugin.run(MyPlugin, buffer_width: 80, buffer_height: 24)

Plugin Behavior

Four required callbacks:

One optional callback:

Input Handling

Special keys as atoms: :enter, :escape, :tab, :backspace, :delete, :up, :down, :left, :right, :home, :end, :page_up, :page_down, :f1-:f12

Modifiers: %{ctrl: bool, alt: bool, shift: bool, meta: bool}

Examples

Full examples in the main repository:

Documentation

See main repository:

License

MIT License - See LICENSE file

Contributing

Visit main repository

Credits

Built by axol.io for raxol.io