Skip to content

Commit

Permalink
Update API
Browse files Browse the repository at this point in the history
  • Loading branch information
atotto committed Jul 6, 2013
1 parent 65fa7c3 commit 8b48e18
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
27 changes: 16 additions & 11 deletions clipboard_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,34 @@
package clipboard

import (
"log"
"os/exec"
)

func Get() string {
cmd := exec.Command("pbpaste")
out, err := cmd.Output()
type Watcher struct {
Copied chan string
}

var (
pbpasteCmd = exec.Command("pbpaste")
pbcopyCmd = exec.Command("pbcopy")
)

func ReadAll() string {
out, err := pbpasteCmd.Output()
if err != nil {
panic(err)
}
return string(out)
}

func Set(str string) {
cmd := exec.Command("pbcopy")
in, err := cmd.StdinPipe()
func WriteAll(str string) {
in, err := pbcopyCmd.StdinPipe()
if err != nil {
log.Println(err)
return
panic(err)
}

cmd.Start()
pbcopyCmd.Start()
in.Write([]byte(str))
in.Close()
cmd.Wait()
pbcopyCmd.Wait()
}
4 changes: 2 additions & 2 deletions clipboard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (

func TestCopyAndPaste(t *testing.T) {
expected := "testtest"
Set(expected)
actual := Get()
WriteAll(expected)
actual := ReadAll()

if actual != expected {
t.Errorf("want %s, got %s", expected, actual)
Expand Down

0 comments on commit 8b48e18

Please sign in to comment.