clipboard

package module
v0.1.2 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: 254

README

clipboard PkgGoDev clipboard

cross platform clipboard access in 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 put image data to system clipboard, you could:

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

The package supports read/write plain text or PNG encoded image data. The other types of data are not supported yet, i.e. 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