clipboard

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2021 License: GPL-3.0 Imports: 6 Imported by: 252

README

clipboard PkgGoDev clipboard

clipboard access with Go

import "golang.design/x/clipboard"

Dependency

  • Linux users: apt install -y libx11-dev
  • macOS users: no dependency

Usage

// write texts to the clipboard
clipboard.Write(clipboard.MIMEText, []byte("text data"))

// read texts from the clipboard
clipboard.Read(clipboard.MIMEText)

// write image to the clipboard, assume image bytes are png encoded.
clipboard.Write(clipboard.MIMEImage, []byte("image data"))

// read image from the clipboard
clipboard.Read(clipboard.MIMEImage)

Notes

To obtain image data to the clipboard, you can:

  • On macOS, Ctrl+Shift+Cmd+4
  • On Linux/Ubuntu, Ctrl+Shift+PrintScreen

The package currently supports read/write plain text string or image data with PNG format. The other types of data are not supported, as undefined behavior.

License

GNU GPL-3 Copyright © 2021 The golang.design Initiative Authors, written by Changkun Ou.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Read

func Read(t MIMEType) []byte

Read reads and returns the clipboard data.

func Write

func Write(t MIMEType, buf []byte)

Write writes the given buffer to the clipboard.

If the MIME type indicates an image, then the given buf assumes the image data is PNG encoded.

Types

type MIMEType

type MIMEType int

MIMEType represents the MIME type of clipboard data.

const (
	// MIMEText indicates plain text MIME format
	MIMEText MIMEType = iota
	// MIMEImage indicates image/png MIME format
	MIMEImage
)

All sorts of supported clipboard data

Jump to

Keyboard shortcuts

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