Raxol LiveView

Hex.pmDocumentation

Phoenix LiveView integration for Raxol terminal buffers. Render terminal UIs in the browser with real-time updates.

Features

Installation

Add raxol_liveview to your list of dependencies in mix.exs:

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

Quick Start

Basic Terminal Component

defmodule MyAppWeb.TerminalLive do
use MyAppWeb, :live_view
alias Raxol.Core.Buffer
alias Raxol.LiveView.TerminalComponent
def mount(_params, _session, socket) do
buffer = Buffer.create_blank_buffer(80, 24)
buffer = Buffer.write_at(buffer, 0, 0, "Hello from LiveView!")
{:ok, assign(socket, buffer: buffer)}
end
def render(assigns) do
~H"""
<.live_component
module={TerminalComponent}
id="terminal-1"
buffer={@buffer}
theme={:nord}
on_keypress={&handle_keypress/1}
/>
"""
end
def handle_keypress(key) do
# Handle keyboard input
IO.puts("Key pressed: #{key}")
end
end

With Event Handling

def render(assigns) do
~H"""
<.live_component
module={Raxol.LiveView.TerminalComponent}
id="terminal"
buffer={@buffer}
theme={:dracula}
on_keypress={fn key -> send(self(), {:key, key}) end}
on_click={fn {x, y} -> send(self(), {:click, x, y}) end}
/>
"""
end
def handle_info({:key, key}, socket) do
buffer = update_buffer_with_key(socket.assigns.buffer, key)
{:noreply, assign(socket, buffer: buffer)}
end

Available Themes

Core Modules

Raxol.LiveView.TerminalBridge

Convert Raxol buffers to HTML with efficient caching and diffing.

alias Raxol.LiveView.TerminalBridge
html = TerminalBridge.buffer_to_html(buffer, theme: :nord)

Raxol.LiveView.TerminalComponent

LiveComponent for embedding terminals in LiveView templates.

Props:

Performance

CSS Customization

Include the default styles in your app.css:

@import "../../deps/raxol_liveview/priv/static/css/raxol_terminal.css";

Or customize with CSS variables:

.raxol-terminal {
--terminal-bg: #1e1e1e;
--terminal-fg: #d4d4d4;
--terminal-font: 'Fira Code', 'Courier New', monospace;
}

Examples

Full examples available in the main repository:

Documentation

Additional documentation in the main repository:

Package Ecosystem

License

MIT License - See LICENSE file included in this package

Contributing

Contributions welcome! Please visit the main repository

Credits

Built by axol.io for raxol.io