clipboard

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2021 License: MIT Imports: 7 Imported by: 0

README

clipboard

Actions Status Doc Go Report Card

This is a multi-platform clipboard library in Go.

Abstract

  • This is clipboard library in Go, which runs on multiple platforms.
  • External clipboard package is not required.

Supported Platforms

  • Windows (Pure Go)
  • macOS (required cgo)
⚠WIP⚠
  • Linux, Unix (X11)

Unfortunately, I don't think it's feasible for Linux to build clipboard library, because xclient needs to be referenced as a daemon in order to keep the clipboard data. This approach is the same for xclip and xsel.

Go has an approach to running its own programs as external processes, such as VividCortex/godaemon and sevlyar/go-daemon. But these cannot be incorporated as a library, of course. xclip and xsel can also be achieved because they are completed as binaries, not libraries.

So it turns out that it is not possible to achieve clipboard in Linux as a library.

Installation

go get github.com/d-tsuji/clipboard

API

package clipboard

// Get returns the current text data of the clipboard.
func Get() (string, error)

// Set sets the current text data of the clipboard.
func Set(text string) error

Documentation

Overview

Example

The purpose of this example is to demonstrate the implementation of get and set.

package main

import (
	"fmt"
	"log"

	"github.com/d-tsuji/clipboard"
)

func main() {
	if err := clipboard.Set("gopher"); err != nil {
		log.Fatal(err)
	}

	text, err := clipboard.Get()
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(text)

}
Output:

gopher

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get() (string, error)

Get returns the current text data of the clipboard.

func Set

func Set(text string) error

Set sets the current text data of the clipboard.

Types

This section is empty.

Jump to

Keyboard shortcuts

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