]> git.lizzy.rs Git - micro.git/commitdiff
Use zyedidia/clipper for external clipboard
authorZachary Yedidia <zyedidia@gmail.com>
Tue, 14 Jun 2022 12:40:57 +0000 (08:40 -0400)
committerZachary Yedidia <zyedidia@gmail.com>
Tue, 14 Jun 2022 12:40:57 +0000 (08:40 -0400)
Micro will now also search for a program called micro-clip for handling
the clipboard. This allows the user to make a program called micro-clip
that micro will call out to for performing copy/paste. For copy it will
be called with `micro-clip -i <reg>` and the text will be provided on
stdin. For paste it will be called with `micro-clip -o <reg>` and micro
expects the text to be provided on stdout.

go.mod
go.sum
internal/clipboard/clipboard.go

diff --git a/go.mod b/go.mod
index a6ecc3242297fc04134bb93b08befe8ad92f5cc5..91548575359f5f31f6b8061cd1c1a91745c0120b 100644 (file)
--- a/go.mod
+++ b/go.mod
@@ -11,7 +11,7 @@ require (
        github.com/sergi/go-diff v1.1.0
        github.com/stretchr/testify v1.4.0
        github.com/yuin/gopher-lua v0.0.0-20191220021717-ab39c6098bdb
-       github.com/zyedidia/clipboard v1.0.4 // indirect
+       github.com/zyedidia/clipper v0.1.0
        github.com/zyedidia/glob v0.0.0-20170209203856-dd4023a66dc3
        github.com/zyedidia/json5 v0.0.0-20200102012142-2da050b1a98d
        github.com/zyedidia/pty v1.1.15 // indirect
diff --git a/go.sum b/go.sum
index 277cbd37082072e5109eb1aff989d5a7c09d1a62..2553e7e9974a0911ea3c458da9a47521f8b9b99c 100644 (file)
--- a/go.sum
+++ b/go.sum
@@ -39,10 +39,10 @@ github.com/xo/terminfo v0.0.0-20200218205459-454e5b68f9e8/go.mod h1:6Yhx5ZJl5942
 github.com/yuin/gopher-lua v0.0.0-20190206043414-8bfc7677f583/go.mod h1:gqRgreBUhTSL0GeU64rtZ3Uq3wtjOa/TB2YfrtkCbVQ=
 github.com/yuin/gopher-lua v0.0.0-20191220021717-ab39c6098bdb h1:ZkM6LRnq40pR1Ox0hTHlnpkcOTuFIDQpZ1IN8rKKhX0=
 github.com/yuin/gopher-lua v0.0.0-20191220021717-ab39c6098bdb/go.mod h1:gqRgreBUhTSL0GeU64rtZ3Uq3wtjOa/TB2YfrtkCbVQ=
-github.com/zyedidia/clipboard v1.0.3 h1:F/nCDVYMdbDWTmY8s8cJl0tnwX32q96IF09JHM14bUI=
-github.com/zyedidia/clipboard v1.0.3/go.mod h1:zykFnZUXX0ErxqvYLUFEq7QDJKId8rmh2FgD0/Y8cjA=
-github.com/zyedidia/clipboard v1.0.4 h1:r6GUQOyPtIaApRLeD56/U+2uJbXis6ANGbKWCljULEo=
-github.com/zyedidia/clipboard v1.0.4/go.mod h1:zykFnZUXX0ErxqvYLUFEq7QDJKId8rmh2FgD0/Y8cjA=
+github.com/zyedidia/clipper v0.0.0-20220613212750-517cd4a6c524 h1:sWYUMHs1EAlsPERKLkaLCxLM0misLylZMEc9Ip5Csjw=
+github.com/zyedidia/clipper v0.0.0-20220613212750-517cd4a6c524/go.mod h1:7YApPNiiTZTXdKKZG92G50qj6mnWEX975Sdu65J7YpQ=
+github.com/zyedidia/clipper v0.1.0 h1:e16nhM1RgL3HYcugcHRUpMya1K830TS5uo6LlPJHySg=
+github.com/zyedidia/clipper v0.1.0/go.mod h1:7YApPNiiTZTXdKKZG92G50qj6mnWEX975Sdu65J7YpQ=
 github.com/zyedidia/glob v0.0.0-20170209203856-dd4023a66dc3 h1:oMHjjTLfGXVuyOQBYj5/td9WC0mw4g1xDBPovIqmHew=
 github.com/zyedidia/glob v0.0.0-20170209203856-dd4023a66dc3/go.mod h1:YKbIYP//Eln8eDgAJGI3IDvR3s4Tv9Z9TGIOumiyQ5c=
 github.com/zyedidia/go-runewidth v0.0.12 h1:aHWj8qL3aH7caRzoPBJXe1pEaZBXHpKtfTuiBo5p74Q=
@@ -55,8 +55,6 @@ github.com/zyedidia/poller v1.0.1 h1:Tt9S3AxAjXwWGNiC2TUdRJkQDZSzCBNVQ4xXiQ7440s
 github.com/zyedidia/poller v1.0.1/go.mod h1:vZXJOHGDcuK08GXhF6IAY0ZFd2WcgOR5DOTp84Uk5eE=
 github.com/zyedidia/pty v1.1.15 h1:XlxMFph7HDvTn4sDG8Klgmb/g4ATGiSj4655vAETp1U=
 github.com/zyedidia/pty v1.1.15/go.mod h1:HWbpfrLoVM9FmU+/9NV+PzVQV8jSxgnQLk8fvx0q/i8=
-github.com/zyedidia/tcell/v2 v2.0.8 h1:/WYLXyVJwSc6xQG1ZDXGpzTenzhWtRtsz4G5XsFKQQ4=
-github.com/zyedidia/tcell/v2 v2.0.8/go.mod h1:i4NNlquIQXFeNecrOgxDQQJdu+7LmTi3g62asvmwUws=
 github.com/zyedidia/tcell/v2 v2.0.9 h1:FxXRkE62N0GPHES7EMLtp2rteYqC9r1kVid8vJN1kOE=
 github.com/zyedidia/tcell/v2 v2.0.9/go.mod h1:i4NNlquIQXFeNecrOgxDQQJdu+7LmTi3g62asvmwUws=
 github.com/zyedidia/terminal v0.0.0-20180726154117-533c623e2415 h1:752dTQ5OatJ9M5ULK2+9lor+nzyZz+LYDo3WGngg3Rc=
index ffc74e74b47097bc721d0f1ae82706a67040aa37..3a57caf431b0f6b82f02a21bd194c2f27d21eb12 100644 (file)
@@ -3,7 +3,7 @@ package clipboard
 import (
        "errors"
 
-       "github.com/zyedidia/clipboard"
+       "github.com/zyedidia/clipper"
 )
 
 type Method int
@@ -35,12 +35,19 @@ const (
        PrimaryReg = -2
 )
 
+var clipboard clipper.Clipboard
+
 // Initialize attempts to initialize the clipboard using the given method
 func Initialize(m Method) error {
        var err error
        switch m {
        case External:
-               err = clipboard.Initialize()
+               clips := make([]clipper.Clipboard, 0, len(clipper.Clipboards)+1)
+               clips = append(clips, &clipper.Custom{
+                       Name: "micro-clip",
+               })
+               clips = append(clips, clipper.Clipboards...)
+               clipboard, err = clipper.GetClipboard(clips...)
        }
        if err != nil {
                CurrentMethod = Internal
@@ -104,9 +111,11 @@ func read(r Register, m Method) (string, error) {
        case External:
                switch r {
                case ClipboardReg:
-                       return clipboard.ReadAll("clipboard")
+                       b, e := clipboard.ReadAll(clipper.RegClipboard)
+                       return string(b), e
                case PrimaryReg:
-                       return clipboard.ReadAll("primary")
+                       b, e := clipboard.ReadAll(clipper.RegPrimary)
+                       return string(b), e
                default:
                        return internal.read(r), nil
                }
@@ -132,9 +141,9 @@ func write(text string, r Register, m Method) error {
        case External:
                switch r {
                case ClipboardReg:
-                       return clipboard.WriteAll(text, "clipboard")
+                       return clipboard.WriteAll(clipper.RegClipboard, []byte(text))
                case PrimaryReg:
-                       return clipboard.WriteAll(text, "primary")
+                       return clipboard.WriteAll(clipper.RegPrimary, []byte(text))
                default:
                        internal.write(text, r)
                }