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
Current section
Files
lib/raxol/terminal/clipboard/clipboard_manager.ex
defmodule Raxol.Terminal.Clipboard.Manager do
@moduledoc """
Manages clipboard operations for the terminal, including copying and pasting text.
"""
defstruct [:content, :mode]
@type t :: %__MODULE__{
content: String.t(),
mode: :normal | :bracketed
}
@doc """
Creates a new clipboard manager instance.
"""
def new do
%__MODULE__{
content: "",
mode: :normal
}
end
@doc """
Gets the current clipboard content.
"""
def get_content(%__MODULE__{} = manager) do
manager.content
end
@doc """
Sets the clipboard content.
"""
def set_content(%__MODULE__{} = manager, content) when is_binary(content) do
%{manager | content: content}
end
@doc """
Gets the current clipboard mode.
"""
def get_mode(%__MODULE__{} = manager) do
manager.mode
end
@doc """
Sets the clipboard mode.
"""
def set_mode(%__MODULE__{} = manager, mode)
when mode in [:normal, :bracketed] do
%{manager | mode: mode}
end
@doc """
Clears the clipboard content.
"""
def clear(%__MODULE__{} = manager) do
%{manager | content: ""}
end
@doc """
Appends text to the current clipboard content.
"""
def append(%__MODULE__{} = manager, text) when is_binary(text) do
%{manager | content: manager.content <> text}
end
@doc """
Prepends text to the current clipboard content.
"""
def prepend(%__MODULE__{} = manager, text) when is_binary(text) do
%{manager | content: text <> manager.content}
end
@doc """
Checks if the clipboard is empty.
"""
def empty?(%__MODULE__{} = manager) do
manager.content == ""
end
@doc """
Gets the length of the clipboard content.
"""
def length(%__MODULE__{} = manager) do
String.length(manager.content)
end
@doc """
Resets the clipboard manager to its initial state.
"""
def reset(%__MODULE__{} = manager) do
%{manager | content: "", mode: :normal}
end
@doc """
Clears the clipboard content (global function).
"""
def clear do
# This would typically interact with the system clipboard
# For now, we'll just return :ok
:ok
end
@doc """
Copies content to the clipboard with the specified format.
"""
def copy(content, _format \\ :text) when is_binary(content) do
# This would typically interact with the system clipboard
# For now, we'll just return :ok
:ok
end
@doc """
Pastes content from the clipboard with the specified format.
"""
def paste(_format \\ :text) do
# This would typically interact with the system clipboard
# For now, we'll return an empty string
""
end
end