diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b7ff007 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +compilar.howto diff --git a/main.go b/main.go index a8d173c..40307f7 100644 --- a/main.go +++ b/main.go @@ -300,8 +300,9 @@ func (c *Keychain) show(name string) { code := c.code(name) if *flagClip { clipboard.WriteAll(code) + } else { + fmt.Printf("%s\n", code) } - fmt.Printf("%s\n", code) } func (c *Keychain) showAll() { diff --git a/vendor/github.com/atotto/clipboard/.travis.yml b/vendor/github.com/atotto/clipboard/.travis.yml new file mode 100644 index 0000000..5bd5ae3 --- /dev/null +++ b/vendor/github.com/atotto/clipboard/.travis.yml @@ -0,0 +1,20 @@ +language: 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 . diff --git a/vendor/github.com/atotto/clipboard/README.md b/vendor/github.com/atotto/clipboard/README.md new file mode 100644 index 0000000..41fdd57 --- /dev/null +++ b/vendor/github.com/atotto/clipboard/README.md @@ -0,0 +1,48 @@ +[![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 + + + diff --git a/vendor/github.com/atotto/clipboard/clipboard_unix.go b/vendor/github.com/atotto/clipboard/clipboard_unix.go index 0acd5fa..8f5e23c 100644 --- a/vendor/github.com/atotto/clipboard/clipboard_unix.go +++ b/vendor/github.com/atotto/clipboard/clipboard_unix.go @@ -8,12 +8,17 @@ package clipboard import ( "errors" + "os" "os/exec" ) const ( - xsel = "xsel" - xclip = "xclip" + xsel = "xsel" + xclip = "xclip" + wlcopy = "wl-copy" + wlpaste = "wl-paste" + termuxClipboardGet = "termux-clipboard-get" + termuxClipboardSet = "termux-clipboard-set" ) var ( @@ -28,10 +33,27 @@ var ( xclipPasteArgs = []string{xclip, "-out", "-selection", "clipboard"} xclipCopyArgs = []string{xclip, "-in", "-selection", "clipboard"} - missingCommands = errors.New("No clipboard utilities available. Please install xsel or xclip.") + wlpasteArgs = []string{wlpaste, "--no-newline"} + wlcopyArgs = []string{wlcopy} + + termuxPasteArgs = []string{termuxClipboardGet} + termuxCopyArgs = []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.") ) func init() { + if os.Getenv("WAYLAND_DISPLAY") != "" { + pasteCmdArgs = wlpasteArgs; + copyCmdArgs = wlcopyArgs; + + if _, err := exec.LookPath(wlcopy); err == nil { + if _, err := exec.LookPath(wlpaste); err == nil { + return + } + } + } + pasteCmdArgs = xclipPasteArgs copyCmdArgs = xclipCopyArgs @@ -46,6 +68,15 @@ func init() { return } + pasteCmdArgs = termuxPasteArgs + copyCmdArgs = termuxCopyArgs + + if _, err := exec.LookPath(termuxClipboardSet); err == nil { + if _, err := exec.LookPath(termuxClipboardGet); err == nil { + return + } + } + Unsupported = true } diff --git a/vendor/github.com/atotto/clipboard/clipboard_windows.go b/vendor/github.com/atotto/clipboard/clipboard_windows.go index 5dbb562..4b4aedb 100644 --- a/vendor/github.com/atotto/clipboard/clipboard_windows.go +++ b/vendor/github.com/atotto/clipboard/clipboard_windows.go @@ -8,12 +8,13 @@ package clipboard import ( "syscall" + "time" "unsafe" ) const ( cfUnicodetext = 13 - gmemFixed = 0x0000 + gmemMoveable = 0x0002 ) var ( @@ -32,15 +33,31 @@ var ( lstrcpy = kernel32.NewProc("lstrcpyW") ) +// 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() (string, error) { - r, _, err := openClipboard.Call(0) - if r == 0 { + err := waitOpenClipboard() + if err != nil { return "", err } defer closeClipboard.Call() h, _, err := getClipboardData.Call(cfUnicodetext) - if r == 0 { + if h == 0 { return "", err } @@ -51,7 +68,7 @@ func readAll() (string, error) { text := syscall.UTF16ToString((*[1 << 20]uint16)(unsafe.Pointer(l))[:]) - r, _, err = globalUnlock.Call(h) + r, _, err := globalUnlock.Call(h) if r == 0 { return "", err } @@ -60,23 +77,30 @@ func readAll() (string, error) { } func writeAll(text string) error { - r, _, err := openClipboard.Call(0) - if r == 0 { + err := waitOpenClipboard() + if err != nil { return err } defer closeClipboard.Call() - r, _, err = emptyClipboard.Call(0) + r, _, err := emptyClipboard.Call(0) if r == 0 { return err } data := syscall.StringToUTF16(text) - h, _, err := globalAlloc.Call(gmemFixed, uintptr(len(data)*int(unsafe.Sizeof(data[0])))) + // "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 { @@ -90,12 +114,15 @@ func writeAll(text string) error { r, _, err = globalUnlock.Call(h) if r == 0 { - return err + 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 } diff --git a/vendor/github.com/atotto/clipboard/go.mod b/vendor/github.com/atotto/clipboard/go.mod new file mode 100644 index 0000000..68ec980 --- /dev/null +++ b/vendor/github.com/atotto/clipboard/go.mod @@ -0,0 +1 @@ +module github.com/atotto/clipboard diff --git a/vendor/modules.txt b/vendor/modules.txt new file mode 100644 index 0000000..a6e90e6 --- /dev/null +++ b/vendor/modules.txt @@ -0,0 +1,3 @@ +# github.com/atotto/clipboard v0.1.2 +## explicit +github.com/atotto/clipboard