File tree Expand file tree Collapse file tree 2 files changed +16
-7
lines changed Expand file tree Collapse file tree 2 files changed +16
-7
lines changed Original file line number Diff line number Diff line change @@ -17,16 +17,13 @@ import "golang.design/x/clipboard"
1717Quick start:
1818
1919``` go
20- // write texts to the clipboard
20+ // write/read text format data of the clipboard
2121clipboard.Write (clipboard.FmtText , []byte (" text data" ))
22-
23- // read texts from the clipboard
2422clipboard.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.
2726clipboard.Write (clipboard.FmtImage , []byte (" image data" ))
28-
29- // read image from the clipboard
3027clipboard.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
Original file line number Diff line number Diff 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.
5759func Watch (ctx context.Context , t Format ) <- chan []byte {
5860 return watch (ctx , t )
5961}
You can’t perform that action at this time.
0 commit comments