clipboard

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 10 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package clipboard reads, writes and watches the system clipboard for sharing it between host and client. It carries UTF-8 text and PNG images, skips content that password managers mark as concealed or transient, and never logs what it carries.

Index

Constants

View Source
const MaxSize = 16 << 20

MaxSize bounds one item's bytes.

Variables

View Source
var (
	ErrUnsupported = errors.New("clipboard: not supported on this platform")
	ErrTooLarge    = errors.New("clipboard: item larger than 16 MiB")
	ErrFormat      = errors.New("clipboard: unknown format")
)

Functions

This section is empty.

Types

type Board

type Board interface {
	// Watch calls onChange for each change another app makes, in canonical
	// form (text before an image when both are offered), until ctx ends.
	// Content marked concealed or transient is skipped. One watcher at a
	// time.
	Watch(ctx context.Context, onChange func(Item)) error
	// Read returns the current content; ok is false when there is none
	// Planck carries, or it is concealed.
	Read() (it Item, ok bool, err error)
	Write(it Item) error
	Close() error
}

Board is the system clipboard.

func Open

func Open() (Board, error)

Open opens the system clipboard.

type Format

type Format uint8
const (
	// Text is UTF-8 text.
	Text Format = iota + 1
	// PNG is a PNG image.
	PNG
)

type Guard

type Guard struct {
	// contains filtered or unexported fields
}

Guard stops clipboard loops between two devices. Each device stamps the items it sends with its own origin; a device drops items from its own origin, does not send back what it just applied, and does not apply what it just sent. It remembers only the last transfer, either way, so content copied again after the other side changed the clipboard still goes out.

func NewGuard

func NewGuard() *Guard

func (*Guard) Incoming

func (g *Guard) Incoming(origin [16]byte, hash [32]byte) bool

Incoming says whether to apply a remote item, and records it as applied when so.

func (*Guard) Origin

func (g *Guard) Origin() [16]byte

func (*Guard) Outgoing

func (g *Guard) Outgoing(data []byte) (hash [32]byte, send bool)

Outgoing hashes a local change and says whether to send it: not when it is the remote item this device just applied (its own write coming back) or the item it sent last.

type Item

type Item struct {
	Format Format
	Data   []byte
	Size   int
}

Item is one clipboard content in its canonical form. Size is the content's size; an item larger than MaxSize has Size set and no Data.

func (Item) TooLarge

func (it Item) TooLarge() bool

TooLarge says the item was left out for its size.

Jump to

Keyboard shortcuts

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