Packages

Multi-surface application runtime for Elixir. One TEA module renders to terminal, browser (LiveView), SSH, and MCP (agents). 30+ widgets, flexbox + CSS grid, AI agent runtime, distributed swarm with CRDTs, time-travel debugging, session recording, sandboxed REPL, and agentic commerce.

Current section

Files

Jump to
raxol lib raxol terminal clipboard sync.ex
Raw

lib/raxol/terminal/clipboard/sync.ex

defmodule Raxol.Terminal.Clipboard.Sync do
@moduledoc """
Handles clipboard synchronization between different terminal instances.
"""
defstruct [:subscribers]
@type t :: %__MODULE__{
subscribers: list(pid())
}
@doc """
Creates a new clipboard sync instance.
"""
@spec new() :: t()
def new() do
%__MODULE__{
subscribers: []
}
end
@doc """
Broadcasts clipboard content to all subscribers.
"""
@spec broadcast(t(), String.t(), String.t()) :: {:ok, t()}
def broadcast(sync, content, format) do
for subscriber <- sync.subscribers do
send(subscriber, {:clipboard_update, content, format})
end
{:ok, sync}
end
@doc """
Adds a subscriber to receive clipboard updates.
"""
@spec add_subscriber(t(), pid()) :: {:ok, t()}
def add_subscriber(sync, pid) do
{:ok, %{sync | subscribers: [pid | sync.subscribers]}}
end
@doc """
Removes a subscriber from receiving clipboard updates.
"""
@spec remove_subscriber(t(), pid()) :: {:ok, t()}
def remove_subscriber(sync, pid) do
{:ok, %{sync | subscribers: List.delete(sync.subscribers, pid)}}
end
end