clipboard

package
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package clipboard reads image and file data out of the host system clipboard and spools it to disk, so it can be attached to a message.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoImage is returned when the clipboard holds nothing attachable.
	ErrNoImage = errors.New("clipboard holds no image or file")
	// ErrUnsupported is returned when the platform has no clipboard reader.
	ErrUnsupported = errors.New("clipboard paste is not supported on this platform")
	// ErrNoTool is returned when the required helper binary is missing.
	ErrNoTool = errors.New("no clipboard helper found (install wl-clipboard or xclip)")
)
View Source
var ErrNoWriter = errors.New("no clipboard tool found for copying text")

ErrNoWriter is returned when the platform has no clipboard writer this build knows how to drive.

Functions

func Cleanup

func Cleanup()

Cleanup removes the spool directory and everything in it. It exists for tests; production code does not call it at exit. Bubble Tea v2 never waits for in-flight tea.Cmd goroutines on quit, so deleting the spool dir at exit races any upload still reading from it. Instead, the spool directory is named deterministically per process and the next process to start sweeps up any directory left behind by a process that is no longer running (see spool and sweepStaleSpools).

func Copy

func Copy(text string) error

Copy puts text on the system clipboard.

Text only. There is no OSC 52 fallback: writing a base64 payload to the terminal to have it set the clipboard would work over ssh, where none of these helpers exist, but it is also the one clipboard path a user cannot see, cannot bound, and cannot decline — several terminals accept it silently and some multiplexers forward it onward. The design record (docs/tui-2.0.md, phase 8) gates it on explicit approval, which it has not been given, so an ssh session gets an honest "no clipboard tool found" rather than a surprise.

An empty string is a no-op rather than an error: "copy nothing" is what yanking an empty message means, and clearing the user's clipboard is not a service they asked for.

func IsImagePath

func IsImagePath(path string) bool

IsImagePath reports whether path looks like an image Telegram can render inline as a photo.

func Remove

func Remove(path string)

Remove deletes path if — and only if — it is a file we spooled ourselves.

Types

type Result

type Result struct {
	Path    string // local file path holding the pasted data
	IsImage bool   // true when the file is an image and can be sent as a photo
	Spooled bool   // true when the file was written by us and may be deleted
}

Result describes what came out of the clipboard.

func Paste

func Paste() (Result, error)

Paste resolves the current clipboard contents to a local file path. A file reference (an image copied in Finder or a file manager) is used in place; raw image data is spooled to a temporary file.

Jump to

Keyboard shortcuts

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