clipboard

package
v0.3.35 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 4, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package clipboard provides cross-platform clipboard access behind build-tag guards so that unsupported platforms (e.g., Android, iOS) compile without requiring CGO or platform-specific dependencies.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnsupported is returned when clipboard access is not available on
	// the current platform.
	ErrUnsupported = errors.New("clipboard operations are not supported on this platform")
	// ErrEmpty is returned when the clipboard holds no data for the
	// requested format.
	ErrEmpty = errors.New("clipboard is empty or holds an unsupported format")
	// ErrWriteFailed is returned when the platform has a clipboard but the
	// written text is not there afterwards.
	ErrWriteFailed = errors.New("clipboard write did not land")
)

Functions

func CopyToClipboard

func CopyToClipboard(text, successMessage string) tea.Cmd

CopyToClipboard copies the given text to the clipboard using both OSC 52 (terminal escape sequence) and native clipboard for maximum compatibility. Returns a command that reports the outcome to the user, using the given message on success.

func CopyToClipboardWithCallback

func CopyToClipboardWithCallback(text, successMessage string, callback tea.Cmd) tea.Cmd

CopyToClipboardWithCallback copies text to clipboard and executes a callback before showing the success message. This is useful when you need to perform additional actions like clearing UI state.

The callback and the success message only run when the copy is believed to have worked, so callers can safely use the callback to discard the copied state (a selection, say) without losing it on a failed copy.

func Init

func Init() error

Init initializes the clipboard subsystem. On unsupported platforms it returns ErrUnsupported but is otherwise safe to call.

func Read

func Read(f Format) ([]byte, error)

Read returns the clipboard contents for the given format. It returns ErrEmpty when no matching data is present and ErrUnsupported on platforms without clipboard support.

func WriteText

func WriteText(text string) error

WriteText writes plain text to the system clipboard and reads it back to confirm the write landed. It returns ErrUnsupported on platforms without a clipboard or when Init did not succeed, and ErrWriteFailed when the clipboard does not hold the text afterwards.

Types

type Format

type Format int

Format identifies the kind of data to read from the clipboard.

const (
	// FormatText is plain UTF-8 text.
	FormatText Format = iota
	// FormatImage is binary image data (PNG).
	FormatImage
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL