TermUI.Clipboard (TermUI v0.2.0)
View SourceClipboard integration for TermUI applications.
Provides clipboard writing via OSC 52 escape sequences and paste event handling. Clipboard operations work across terminals that support these features.
Usage
# Write to clipboard
Clipboard.write("text to copy")
# Check OSC 52 support
if Clipboard.osc52_supported?() do
Clipboard.write(content)
end
# Enable bracketed paste mode
IO.write(Clipboard.bracketed_paste_on())
Summary
Functions
Returns escape sequence to disable bracketed paste mode.
Returns escape sequence to enable bracketed paste mode.
Clears the system clipboard via OSC 52.
Generates OSC 52 sequence to clear the clipboard.
Checks if OSC 52 clipboard is likely supported.
Returns the paste end marker sequence.
Returns the paste start marker sequence.
Writes content to the system clipboard via OSC 52.
Generates OSC 52 escape sequence to write to clipboard.
Functions
@spec bracketed_paste_off() :: String.t()
Returns escape sequence to disable bracketed paste mode.
@spec bracketed_paste_on() :: String.t()
Returns escape sequence to enable bracketed paste mode.
@spec clear(keyword()) :: :ok
Clears the system clipboard via OSC 52.
Generates OSC 52 sequence to clear the clipboard.
@spec osc52_supported?() :: boolean()
Checks if OSC 52 clipboard is likely supported.
This is a heuristic check based on terminal type. Some terminals support OSC 52 but don't advertise it; others advertise but block it.
Known supporting terminals:
- xterm (with allowWindowOps)
- Alacritty
- Kitty
- WezTerm
- iTerm2
- foot
@spec paste_end_marker() :: String.t()
Returns the paste end marker sequence.
@spec paste_start_marker() :: String.t()
Returns the paste start marker sequence.
Writes content to the system clipboard via OSC 52.
This writes the escape sequence directly to the terminal.
Returns :ok on success.
Options
:target- Clipboard target::clipboard(default) or:primary
Generates OSC 52 escape sequence to write to clipboard.
Returns the escape sequence string that should be written to the terminal to set the clipboard content.
Options
:target- Clipboard target::clipboard(default) or:primary
Examples
iex> Clipboard.write_sequence("hello")
"\e]52;c;aGVsbG8=\e\\"
iex> Clipboard.write_sequence("test", target: :primary)
"\e]52;p;dGVzdA==\e\\"