Skip to content

Commit 79cfef9

Browse files
committed
all: doc updates
1 parent 8f90954 commit 79cfef9

File tree

1 file changed

+38
-7
lines changed

1 file changed

+38
-7
lines changed

README.md

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import "golang.design/x/clipboard"
1414

1515
## API Usage
1616

17+
Quick start:
18+
1719
```go
1820
// write texts to the clipboard
1921
clipboard.Write(clipboard.MIMEText, []byte("text data"))
@@ -28,13 +30,34 @@ clipboard.Write(clipboard.MIMEImage, []byte("image data"))
2830
clipboard.Read(clipboard.MIMEImage)
2931
```
3032

31-
## Command Usage
33+
In addition, the `clipboard.Write` API returns a channel that
34+
can receive an empty struct as a signal that indicates the
35+
corresponding write call to the clipboard is outdated, meaning
36+
the clipboard has been overwritten by others and the previously
37+
written data is lost. For instance:
38+
39+
```go
40+
changed := clipboard.Write(clipboard.MIMEText, []byte("text data"))
3241

33-
```sh
34-
go install golang.design/x/clipboard/cmd/gclip@latest
42+
select {
43+
case <-changed:
44+
println(`"text data" is no longer available from clipboard.`)
45+
}
3546
```
3647

48+
You can ignore the reutrning channel if you don't need this type of notification.
49+
50+
## Command Usage
51+
52+
`gclip` command offers the ability to interact with the system clipboard
53+
from the shell. To install:
54+
55+
```bash
56+
$ go install golang.design/x/clipboard/cmd/gclip@latest
3757
```
58+
59+
```bash
60+
$ gclip
3861
gclip is a command that provides clipboard interaction.
3962

4063
usage: gclip [-copy|-paste] [-f <file>]
@@ -57,12 +80,20 @@ gclip -copy -f x.txt copy content from x.txt to clipboard
5780
gclip -copy -f x.png copy x.png as image data to clipboard
5881
```
5982

60-
## Notes
83+
If `-copy` is used, the command will exit when the data is no longer
84+
available from the clipboard. You can always send the command to the
85+
background using a shell `&` operator, for example:
86+
87+
```bash
88+
$ cat x.txt | gclip -copy &
89+
```
90+
91+
## Additional Notes
6192

62-
To put image data to system clipboard, you could:
93+
In general, to put image data to system clipboard, there are system level shortcuts:
6394

64-
- On macOS, using shortcut Ctrl+Shift+Cmd+4
65-
- On Linux/Ubuntu, using Ctrl+Shift+PrintScreen
95+
- On macOS, using shortcut `Ctrl+Shift+Cmd+4`
96+
- On Linux/Ubuntu, using `Ctrl+Shift+PrintScreen`
6697

6798
The package supports read/write plain text or PNG encoded image data.
6899
The other types of data are not supported yet, i.e. undefined behavior.

0 commit comments

Comments
 (0)