clipboard

package
v0.6.15 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2024 License: MIT Imports: 10 Imported by: 1

README

Clipboard

Package clipboard provide a simple clipboard read and write operations.

Install
go get github.com/gookit/goutil/sysutil/clipboard
Usage

Examples:

src := "hello, this is clipboard"
err = clipboard.WriteString(src)
assert.NoErr(t, err)

// str: "hello, this is clipboard"
str, err = clipboard.ReadString()
assert.NoErr(t, err)
assert.NotEmpty(t, str)
assert.Eq(t, src, str)

Documentation

Overview

Package clipboard provide a simple clipboard read and write operations.

Index

Constants

View Source
const (
	// WriterOnMac driver
	//
	// Example:
	//   echo hello | pbcopy
	//   pbcopy < tempfile.txt
	WriterOnMac = "pbcopy"

	// WriterOnWin driver on Windows
	//
	// TIP: clip only support write contents to clipboard.
	WriterOnWin = "clip"

	// WriterOnLin driver name
	//
	// linux:
	//   echo "hello-c" | xclip -selection c
	WriterOnLin = "xclip -selection clipboard"

	// ReaderOnMac driver
	//
	// Example:
	// 	Mac: pbpaste >> tasklist.txt
	ReaderOnMac = "pbpaste"

	// ReaderOnWin driver on Windows
	//
	// read clipboard should use: powershell get-clipboard
	ReaderOnWin = "powershell get-clipboard"

	// ReaderOnLin driver name
	//
	// Usage:
	// 	xclip -o -selection clipboard
	// 	xclip -o -selection c // can use shorts
	ReaderOnLin = "xclip -o -selection clipboard"
)

clipboard writer, reader program names

Variables

This section is empty.

Functions

func Available

func Available() bool

Available clipboard available check

func GetReaderBin

func GetReaderBin() string

GetReaderBin program name

func GetWriterBin

func GetWriterBin() string

GetWriterBin program name

func ReadString

func ReadString() (string, error)

ReadString contents from clipboard

func Reset

func Reset() error

Reset clipboard data

func WriteString

func WriteString(s string) error

WriteString contents to clipboard and flush

Types

type Clipboard

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

Clipboard struct

func New

func New() *Clipboard

New instance

func Std added in v0.6.7

func Std() *Clipboard

Std get

func (*Clipboard) Available

func (c *Clipboard) Available() bool

Available check

func (*Clipboard) Clean added in v0.6.7

func (c *Clipboard) Clean() error

Clean the clipboard

func (*Clipboard) Flush

func (c *Clipboard) Flush() error

Flush buffer contents to clipboard

func (*Clipboard) Read

func (c *Clipboard) Read() ([]byte, error)

Read bytes contents from clipboard

func (*Clipboard) ReadString

func (c *Clipboard) ReadString() (string, error)

ReadString contents as string from clipboard

func (*Clipboard) ReadTo added in v0.6.7

func (c *Clipboard) ReadTo(w io.Writer) error

ReadTo read clipboard contents to writer

func (*Clipboard) ReadToBuffer added in v0.6.7

func (c *Clipboard) ReadToBuffer() (*bytes.Buffer, error)

ReadToBuffer read clipboard contents to new buffer.

func (*Clipboard) ReadToFile

func (c *Clipboard) ReadToFile(filepath string) error

ReadToFile dump clipboard data to file

func (*Clipboard) Readable added in v0.6.7

func (c *Clipboard) Readable() bool

Readable check

func (*Clipboard) Reset

func (c *Clipboard) Reset() error

Reset and clean the clipboard

func (*Clipboard) SafeString added in v0.6.13

func (c *Clipboard) SafeString() string

SafeString read contents as string from clipboard, will return empty string on error

func (*Clipboard) WithVerbose added in v0.6.7

func (c *Clipboard) WithVerbose(yn bool) *Clipboard

WithVerbose setting

func (*Clipboard) Write

func (c *Clipboard) Write(p []byte) (int, error)

Write bytes data to buffer. should call Flush() to write to clipboard

func (*Clipboard) WriteFrom added in v0.6.7

func (c *Clipboard) WriteFrom(r io.Reader) error

WriteFrom reader data to clipboard

func (*Clipboard) WriteFromFile

func (c *Clipboard) WriteFromFile(filepath string) error

WriteFromFile contents to clipboard

func (*Clipboard) WriteString

func (c *Clipboard) WriteString(s string) (int, error)

WriteString data to buffer. should call Flush() to write to clipboard

func (*Clipboard) Writeable added in v0.6.7

func (c *Clipboard) Writeable() bool

Writeable check

Jump to

Keyboard shortcuts

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