Skip to content

Commit 4dbf0df

Browse files
committed
all: update docs regarding watcher
1 parent c534f34 commit 4dbf0df

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

README.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,13 @@ import "golang.design/x/clipboard"
1717
Quick start:
1818

1919
```go
20-
// write texts to the clipboard
20+
// write/read text format data of the clipboard
2121
clipboard.Write(clipboard.FmtText, []byte("text data"))
22-
23-
// read texts from the clipboard
2422
clipboard.Read(clipboard.FmtText)
2523

26-
// write image to the clipboard, assume image bytes are png encoded.
24+
// write/read image format data of the clipboard, assume
25+
// image bytes are png encoded.
2726
clipboard.Write(clipboard.FmtImage, []byte("image data"))
28-
29-
// read image from the clipboard
3027
clipboard.Read(clipboard.FmtImage)
3128
```
3229

@@ -45,7 +42,17 @@ case <-changed:
4542
}
4643
```
4744

48-
You can ignore the reutrning channel if you don't need this type of notification.
45+
You can ignore the reutrning channel if you don't need this type of
46+
notification. Furthermore, when you need more than just knowing whether
47+
clipboard data is changed, use the watcher API:
48+
49+
```go
50+
ch := clipboard.Watch(context.TODO(), clipboard.FmtText)
51+
for data := range ch {
52+
// print out clipboard data whenever it is changed
53+
println(string(data))
54+
}
55+
```
4956

5057
## Command Usage
5158

clipboard.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ func Write(t Format, buf []byte) <-chan struct{} {
5454

5555
// Watch returns a receive-only channel that received the clipboard data
5656
// if any changes of clipboard data in the desired format happends.
57+
//
58+
// The returned channel will be closed if the given context is canceled.
5759
func Watch(ctx context.Context, t Format) <-chan []byte {
5860
return watch(ctx, t)
5961
}

0 commit comments

Comments
 (0)