pax_global_header00006660000000000000000000000064137002116400014504gustar00rootroot0000000000000052 comment=c0ed90acabff7c68d2dbcbc4d87d4c8efb360829 clipboard-1.0.3/000077500000000000000000000000001370021164000134445ustar00rootroot00000000000000clipboard-1.0.3/.travis.yml000066400000000000000000000004131370021164000155530ustar00rootroot00000000000000language: go go: - go1.4.3 - go1.5.4 - go1.6.4 - go1.7.6 - go1.8.7 - go1.9.4 - go1.10 before_install: - export DISPLAY=:99.0 - sh -e /etc/init.d/xvfb start script: - sudo apt-get install xsel - go test -v . - sudo apt-get install xclip - go test -v . clipboard-1.0.3/LICENSE000066400000000000000000000030321370021164000144470ustar00rootroot00000000000000Copyright (c) 2018 Zachary Yedidia. Modifications to atotto/clipboard. Original license: Copyright (c) 2013 Ato Araki. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of @atotto. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. clipboard-1.0.3/README.md000066400000000000000000000021751370021164000147300ustar00rootroot00000000000000# This is a fork of atotto/clipboard This fork is used for `zyedidia/micro` and has some modifications, namely: support for the primary clipboard on linux and support for an internal clipboard if the system clipboard is not available. [![Build Status](https://travis-ci.org/atotto/clipboard.svg?branch=master)](https://travis-ci.org/atotto/clipboard) [![GoDoc](https://godoc.org/github.com/atotto/clipboard?status.svg)](http://godoc.org/github.com/atotto/clipboard) # Clipboard for Go Provide copying and pasting to the Clipboard for Go. Build: $ go get github.com/atotto/clipboard Platforms: * OSX * Windows 7 (probably work on other Windows) * Linux, Unix (requires 'xclip' or 'xsel' command to be installed) Document: * http://godoc.org/github.com/atotto/clipboard Notes: * Text string only * UTF-8 text encoding only (no conversion) TODO: * Clipboard watcher(?) ## Commands: paste shell command: $ go get github.com/atotto/clipboard/cmd/gopaste $ # example: $ gopaste > document.txt copy shell command: $ go get github.com/atotto/clipboard/cmd/gocopy $ # example: $ cat document.txt | gocopy clipboard-1.0.3/clipboard.go000066400000000000000000000013551370021164000157360ustar00rootroot00000000000000// Copyright 2013 @atotto. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Package clipboard read/write on clipboard package clipboard // Initialize attempts to initialize the clipboard // This function can only return an error on Linux func Initialize() error { return initialize() } // ReadAll read string from clipboard func ReadAll(register string) (string, error) { return readAll(register) } // WriteAll write string to clipboard func WriteAll(text, register string) error { return writeAll(text, register) } // Unsupported might be set true during clipboard init, to help callers decide // whether or not to offer clipboard options. var Unsupported bool clipboard-1.0.3/clipboard_darwin.go000066400000000000000000000020651370021164000173010ustar00rootroot00000000000000// Copyright 2013 @atotto. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // +build darwin package clipboard import ( "os/exec" ) var ( pasteCmdArgs = "pbpaste" copyCmdArgs = "pbcopy" ) func initialize() error { return nil } func getPasteCommand() *exec.Cmd { return exec.Command(pasteCmdArgs) } func getCopyCommand() *exec.Cmd { return exec.Command(copyCmdArgs) } func readAll(register string) (string, error) { if register != "clipboard" { return "", nil } pasteCmd := getPasteCommand() out, err := pasteCmd.Output() if err != nil { return "", err } return string(out), nil } func writeAll(text string, register string) error { if register != "clipboard" { return nil } copyCmd := getCopyCommand() in, err := copyCmd.StdinPipe() if err != nil { return err } if err := copyCmd.Start(); err != nil { return err } if _, err := in.Write([]byte(text)); err != nil { return err } if err := in.Close(); err != nil { return err } return copyCmd.Wait() } clipboard-1.0.3/clipboard_test.go000066400000000000000000000027341370021164000167770ustar00rootroot00000000000000// Copyright 2013 @atotto. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package clipboard_test import ( "log" "os" "testing" . "github.com/zyedidia/clipboard" ) func TestMain(m *testing.M) { err := Initialize() if err != nil { log.Fatalln(err) os.Exit(1) } retval := m.Run() os.Exit(retval) } func TestCopyAndPaste(t *testing.T) { expected := "日本語" err := WriteAll(expected, "clipboard") if err != nil { t.Fatal(err) } actual, err := ReadAll("clipboard") if err != nil { t.Fatal(err) } if actual != expected { t.Errorf("want %s, got %s", expected, actual) } } func TestMultiCopyAndPaste(t *testing.T) { expected1 := "French: éèêëàùœç" expected2 := "Weird UTF-8: 💩☃" err := WriteAll(expected1, "clipboard") if err != nil { t.Fatal(err) } actual1, err := ReadAll("clipboard") if err != nil { t.Fatal(err) } if actual1 != expected1 { t.Errorf("want %s, got %s", expected1, actual1) } err = WriteAll(expected2, "clipboard") if err != nil { t.Fatal(err) } actual2, err := ReadAll("clipboard") if err != nil { t.Fatal(err) } if actual2 != expected2 { t.Errorf("want %s, got %s", expected2, actual2) } } func BenchmarkReadAll(b *testing.B) { for i := 0; i < b.N; i++ { ReadAll("clipboard") } } func BenchmarkWriteAll(b *testing.B) { text := "いろはにほへと" for i := 0; i < b.N; i++ { WriteAll(text, "clipboard") } } clipboard-1.0.3/clipboard_unix.go000066400000000000000000000112461370021164000170010ustar00rootroot00000000000000// Copyright 2013 @atotto. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // +build freebsd linux netbsd openbsd solaris dragonfly package clipboard import ( "errors" "os" "os/exec" ) const ( xsel = "xsel" xclip = "xclip" wlcopy = "wl-copy" wlpaste = "wl-paste" termuxClipboardGet = "termux-clipboard-get" termuxClipboardSet = "termux-clipboard-set" ) var ( pasteCmdArgs map[string][]string copyCmdArgs map[string][]string xselPasteArgs = map[string][]string{ "primary": []string{xsel, "--output"}, "clipboard": []string{xsel, "--output", "--clipboard"}, } xselCopyArgs = map[string][]string{ "primary": []string{xsel, "--input"}, "clipboard": []string{xsel, "--input", "--clipboard"}, } xclipPasteArgs = map[string][]string{ "primary": []string{xclip, "-out"}, "clipboard": []string{xclip, "-out", "-selection", "clipboard"}, } xclipCopyArgs = map[string][]string{ "primary": []string{xclip, "-in"}, "clipboard": []string{xclip, "-in", "-selection", "clipboard"}, } wlpasteArgs = map[string][]string{ "primary": []string{wlpaste, "--no-newline", "--primary"}, "clipboard": []string{wlpaste, "--no-newline"}, } wlcopyArgs = map[string][]string{ "primary": []string{wlcopy, "--primary"}, "clipboard": []string{wlcopy}, } termuxPasteArgs = map[string][]string{ "primary": []string{termuxClipboardGet}, "clipboard": []string{termuxClipboardGet}, } termuxCopyArgs = map[string][]string{ "primary": []string{termuxClipboardSet}, "clipboard": []string{termuxClipboardSet}, } missingCommands = errors.New("No clipboard utilities available. Please install xsel, xclip, wl-clipboard or Termux:API add-on for termux-clipboard-get/set.") internalClipboards map[string]string ) // verify install makes sure that the given exec is installed // and operating correctly. In some cases, xclip/xsel can be installed // but not working because an X server is not running. func verifyInstall(cmd string) bool { if _, err := exec.LookPath(cmd); err == nil { // first check if to read from the clipboard // if this is possible, then xclip/xsel is working properly pasteCmd := getPasteCommand("primary") _, err := pasteCmd.Output() if err == nil { return true } // If the previous command didn't work, this could be because the clipboard // has no contents. Now we will try to copy an empty string into the clipboard. copyCmd := getCopyCommand("primary") in, err := copyCmd.StdinPipe() if err != nil { return false } if err := copyCmd.Start(); err != nil { return false } if _, err := in.Write([]byte{}); err != nil { return false } if err := in.Close(); err != nil { return false } return copyCmd.Wait() == nil } // if exec was not found in path we know it is not installed return false } func initialize() error { if os.Getenv("WAYLAND_DISPLAY") != "" { pasteCmdArgs = wlpasteArgs copyCmdArgs = wlcopyArgs if _, err := exec.LookPath(wlcopy); err == nil { if _, err := exec.LookPath(wlpaste); err == nil { return nil } } } pasteCmdArgs = xclipPasteArgs copyCmdArgs = xclipCopyArgs if verifyInstall(xclip) { return nil } pasteCmdArgs = xselPasteArgs copyCmdArgs = xselCopyArgs if verifyInstall(xsel) { return nil } pasteCmdArgs = termuxPasteArgs copyCmdArgs = termuxCopyArgs if _, err := exec.LookPath(termuxClipboardSet); err == nil { if _, err := exec.LookPath(termuxClipboardGet); err == nil { return nil } } if internalClipboards == nil { internalClipboards = make(map[string]string) } Unsupported = true return errors.New("System clipboard not found, install xclip/xsel") } func getPasteCommand(register string) *exec.Cmd { return exec.Command(pasteCmdArgs[register][0], pasteCmdArgs[register][1:]...) } func getCopyCommand(register string) *exec.Cmd { return exec.Command(copyCmdArgs[register][0], copyCmdArgs[register][1:]...) } func readAll(register string) (string, error) { if Unsupported { if text, ok := internalClipboards[register]; ok { return text, nil } return "", nil } pasteCmd := getPasteCommand(register) out, err := pasteCmd.Output() if err != nil { return "", err } return string(out), nil } func writeAll(text, register string) error { if Unsupported { internalClipboards[register] = text return nil } copyCmd := getCopyCommand(register) in, err := copyCmd.StdinPipe() if err != nil { return err } if err := copyCmd.Start(); err != nil { return err } if _, err := in.Write([]byte(text)); err != nil { return err } if err := in.Close(); err != nil { return err } return copyCmd.Wait() } clipboard-1.0.3/clipboard_windows.go000066400000000000000000000054131370021164000175070ustar00rootroot00000000000000// Copyright 2013 @atotto. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // +build windows package clipboard import ( "syscall" "time" "unsafe" ) const ( cfUnicodetext = 13 gmemMoveable = 0x0002 ) var ( user32 = syscall.MustLoadDLL("user32") openClipboard = user32.MustFindProc("OpenClipboard") closeClipboard = user32.MustFindProc("CloseClipboard") emptyClipboard = user32.MustFindProc("EmptyClipboard") getClipboardData = user32.MustFindProc("GetClipboardData") setClipboardData = user32.MustFindProc("SetClipboardData") kernel32 = syscall.NewLazyDLL("kernel32") globalAlloc = kernel32.NewProc("GlobalAlloc") globalFree = kernel32.NewProc("GlobalFree") globalLock = kernel32.NewProc("GlobalLock") globalUnlock = kernel32.NewProc("GlobalUnlock") lstrcpy = kernel32.NewProc("lstrcpyW") ) func initialize() error { return nil } // waitOpenClipboard opens the clipboard, waiting for up to a second to do so. func waitOpenClipboard() error { started := time.Now() limit := started.Add(time.Second) var r uintptr var err error for time.Now().Before(limit) { r, _, err = openClipboard.Call(0) if r != 0 { return nil } time.Sleep(time.Millisecond) } return err } func readAll(register string) (string, error) { if register != "clipboard" { return "", nil } err := waitOpenClipboard() if err != nil { return "", err } defer closeClipboard.Call() h, _, err := getClipboardData.Call(cfUnicodetext) if h == 0 { return "", err } l, _, err := globalLock.Call(h) if l == 0 { return "", err } text := syscall.UTF16ToString((*[1 << 20]uint16)(unsafe.Pointer(l))[:]) r, _, err := globalUnlock.Call(h) if r == 0 { return "", err } return text, nil } func writeAll(text, register string) error { if register != "clipboard" { return nil } err := waitOpenClipboard() if err != nil { return err } defer closeClipboard.Call() r, _, err := emptyClipboard.Call(0) if r == 0 { return err } data := syscall.StringToUTF16(text) // "If the hMem parameter identifies a memory object, the object must have // been allocated using the function with the GMEM_MOVEABLE flag." h, _, err := globalAlloc.Call(gmemMoveable, uintptr(len(data)*int(unsafe.Sizeof(data[0])))) if h == 0 { return err } defer func() { if h != 0 { globalFree.Call(h) } }() l, _, err := globalLock.Call(h) if l == 0 { return err } r, _, err = lstrcpy.Call(l, uintptr(unsafe.Pointer(&data[0]))) if r == 0 { return err } r, _, err = globalUnlock.Call(h) if r == 0 { if err.(syscall.Errno) != 0 { return err } } r, _, err = setClipboardData.Call(cfUnicodetext, h) if r == 0 { return err } h = 0 // suppress deferred cleanup return nil } clipboard-1.0.3/example_test.go000066400000000000000000000003471370021164000164710ustar00rootroot00000000000000package clipboard_test import ( "fmt" "github.com/zyedidia/clipboard" ) func Example() { clipboard.WriteAll("日本語", "clipboard") text, _ := clipboard.ReadAll("clipboard") fmt.Println(text) // Output: // 日本語 } clipboard-1.0.3/go.mod000066400000000000000000000000561370021164000145530ustar00rootroot00000000000000module github.com/zyedidia/clipboard go 1.13