-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
235 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# doc: Set | ||
|
||
(register/set register value) | ||
|
||
Store a string in the given register, which can be any string. The "+" register refers to the system clipboard. | ||
|
||
# doc: Get | ||
|
||
(register/get register) | ||
|
||
Get the value stored in the given register. The "+" register refers to the system clipboard. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package api | ||
|
||
type RegisterModule struct { | ||
Registers Registers | ||
} | ||
|
||
func (c *RegisterModule) Set( | ||
register string, | ||
text string, | ||
) error { | ||
return c.Registers.Set(register, text) | ||
} | ||
|
||
func (c *RegisterModule) Get( | ||
register string, | ||
) (string, error) { | ||
return c.Registers.Get(register) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
(test "registers" | ||
(register/set "a" "a") | ||
(register/set "b" "b") | ||
(register/set "+" "test") | ||
(assert (= "a" (register/get "a"))) | ||
(assert (= "b" (register/get "b"))) | ||
(assert (= "test" (register/get "+")))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
(defn | ||
clipboard/get | ||
"Get the contents of the system clipboard." | ||
[] | ||
(register/get "+")) | ||
|
||
(defn | ||
clipboard/set | ||
"Set the contents of the system clipboard." | ||
[text] | ||
(register/set "+" text)) | ||
|
||
(defn | ||
register/insert | ||
"Insert the contents of the given register in the current pane." | ||
[register] | ||
(pane/send-keys | ||
(pane/current) | ||
@[(register/get register)])) | ||
|
||
(key/action | ||
action/paste | ||
"Insert the contents of the default register." | ||
(register/insert "")) | ||
|
||
(key/action | ||
action/paste-clipboard | ||
"Insert the contents of the system clipboard." | ||
(register/insert "+")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
(defn | ||
replay/copy-default | ||
"Yank the selection into the default register." | ||
[] | ||
(replay/copy "")) | ||
|
||
(defn | ||
replay/copy-clipboard | ||
"Yank the selection into the system clipboard." | ||
[] | ||
(replay/copy "+")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package cy | ||
|
||
import ( | ||
"github.com/cfoust/cy/pkg/clipboard" | ||
"github.com/cfoust/cy/pkg/cy/api" | ||
|
||
"github.com/sasha-s/go-deadlock" | ||
) | ||
|
||
type memoryRegisters struct { | ||
deadlock.RWMutex | ||
clipboard clipboard.Clipboard | ||
registers map[string]string | ||
} | ||
|
||
var _ api.Registers = (*memoryRegisters)(nil) | ||
|
||
func (r *memoryRegisters) Set(register string, text string) error { | ||
if register == "+" { | ||
return r.clipboard.Write(text) | ||
} | ||
|
||
r.Lock() | ||
defer r.Unlock() | ||
r.registers[register] = text | ||
return nil | ||
} | ||
|
||
func (r *memoryRegisters) Get(register string) (string, error) { | ||
if register == "+" { | ||
return r.clipboard.Read() | ||
} | ||
|
||
r.RLock() | ||
defer r.RUnlock() | ||
return r.registers[register], nil | ||
} | ||
|
||
func (r *memoryRegisters) GetAll() (map[string]string, error) { | ||
r.RLock() | ||
defer r.RUnlock() | ||
cloned := make(map[string]string) | ||
|
||
for k, v := range r.registers { | ||
cloned[k] = v | ||
} | ||
|
||
// Attempt to get system clipboard, but don't worry if we can't | ||
clipboard, err := r.clipboard.Read() | ||
if err == nil { | ||
cloned["+"] = clipboard | ||
} | ||
|
||
return cloned, nil | ||
} | ||
|
||
func newMemoryRegisters(clipboard clipboard.Clipboard) *memoryRegisters { | ||
return &memoryRegisters{ | ||
registers: make(map[string]string), | ||
clipboard: clipboard, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.