clipimage

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 26 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

The image on the clipboard of the computer the app runs on, read with the program each system has for it, as a PNG a message attaches

Index

Constants

View Source
const (
	// Largest image a message takes, and the most pixels it may be, as the labels of the prompt take them
	MaxBytes  = 20 << 20
	MaxPixels = 100_000_000
	// Longest the reading of the clipboard image may take in all
	Limit = 15 * time.Second

	// Age past which a kept image, or a page rendered from a PDF, is removed as the next one is kept
	KeptFor = 7 * 24 * time.Hour
)

Variables

View Source
var ErrNone = errors.New("The clipboard holds no image.")

The clipboard holds no image

Functions

func Blocker

func Blocker(sys System, has func(program string) bool) error

What keeps this computer from reading a clipboard image: a *Missing program, an *Unreachable desktop, nil when nothing does; has says whether a program is installed. Under WSL the clipboard of Windows is read through powershell.exe, else through the display WSL shows, as Sources tries them

func DataURL

func DataURL(text string) bool

Whether the text is an image as a data URL, as a terminal or a browser pastes one: data:image/<type>;base64,<data>

func Installed

func Installed(program string) bool

Whether a program is on the search path of this process

func Keep

func Keep(dir string, img Image) (string, error)

Writes the image into the folder as a file of its own, named for when it was pasted, the files kept there longer than a week removed first; the path of the file

func Preferred

func Preferred(listed string) string

The type of image to take among the lines a clipboard program listed, empty for none

func Sources

func Sources(sys System) []string

Programs that read the clipboard image of the system, tried in this order

func Usable

func Usable(text string) bool

Whether text read from the clipboard is text a person meant: not empty or space alone, no NUL, and at most a few control or replacement characters among them, unlike what an image read as text leaves

Types

type Image

type Image struct {
	PNG           []byte
	Width, Height int
	// Program that read it, as a person knows it
	From string
}

The image on the clipboard, as a PNG

func FromDataURL

func FromDataURL(text string) (Image, error)

The image of a data URL as a PNG within the bounds

func Made

func Made(ctx context.Context, run Runner, data []byte) (Image, error)

The image as a PNG within the bounds: a PNG as it is, any other format the decoders read made PNG, else made PNG by ImageMagick where a runner is given; refused in words when nothing reads it or it is too large, one of too many pixels before it is decoded

func Read

func Read(ctx context.Context, sys System, run Runner) (Image, error)

The image on the clipboard as a PNG within the bounds, read with the programs of the system in turn: ErrNone when none of them found one; one found that can't be a PNG within the bounds is refused in words. A context that ends says how long the reading took

type Missing

type Missing struct {
	Program, Package string
	Packages         map[string]string
}

A program reading clipboard images that this computer lacks, with the package of each package manager that installs it

func (*Missing) Error

func (m *Missing) Error() string

func (*Missing) Remedy

func (m *Missing) Remedy() string

What installs it here: the command of the package manager of this system, else the package to install

type Output

type Output struct {
	Stdout []byte
	Code   int
}

What a program printed on its output and how it ended

func Run

func Run(ctx context.Context, argv []string, limit time.Duration) (Output, error)

Runs a program of this computer as a helper acting for no profile, with the variables of the desktop, never through a shell

type Runner

type Runner func(ctx context.Context, argv []string, limit time.Duration) (Output, error)

Runs a program to its end within its limit, with nothing on its input, and gives what it printed; an error for one that could not start, ran past its limit or printed too much, exec.ErrNotFound under it for one that is not installed

type System

type System struct {
	OS string
	// Linux under WSL, whose clipboard is the one of Windows
	WSL bool
	// A Wayland display, an X11 display is named
	Wayland, X11 bool
	// The terminal reaches this computer over SSH, so its clipboard is no clipboard of the person's own computer
	Remote bool
	// This process runs in a container, or in Termux, neither of which holds a desktop clipboard
	Contained, Termux bool
}

What the clipboard is read on

func Here

func Here() System

The system this process runs on, as its environment tells it

type Unreachable

type Unreachable struct {
	Why string
}

No desktop clipboard is reachable from this terminal: why, as the end of a sentence

func (*Unreachable) Error

func (u *Unreachable) Error() string

Jump to

Keyboard shortcuts

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