Skip to content

Commit ffaf9a0

Browse files
committed
all: rename mime to format
1 parent 79cfef9 commit ffaf9a0

File tree

7 files changed

+44
-44
lines changed

7 files changed

+44
-44
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ Quick start:
1818

1919
```go
2020
// write texts to the clipboard
21-
clipboard.Write(clipboard.MIMEText, []byte("text data"))
21+
clipboard.Write(clipboard.FmtText, []byte("text data"))
2222

2323
// read texts from the clipboard
24-
clipboard.Read(clipboard.MIMEText)
24+
clipboard.Read(clipboard.FmtText)
2525

2626
// write image to the clipboard, assume image bytes are png encoded.
27-
clipboard.Write(clipboard.MIMEImage, []byte("image data"))
27+
clipboard.Write(clipboard.FmtImage, []byte("image data"))
2828

2929
// read image from the clipboard
30-
clipboard.Read(clipboard.MIMEImage)
30+
clipboard.Read(clipboard.FmtImage)
3131
```
3232

3333
In addition, the `clipboard.Write` API returns a channel that
@@ -37,7 +37,7 @@ the clipboard has been overwritten by others and the previously
3737
written data is lost. For instance:
3838

3939
```go
40-
changed := clipboard.Write(clipboard.MIMEText, []byte("text data"))
40+
changed := clipboard.Write(clipboard.FmtText, []byte("text data"))
4141

4242
select {
4343
case <-changed:

clipboard.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ import (
1010
"sync"
1111
)
1212

13-
// MIMEType represents the MIME type of clipboard data.
14-
type MIMEType int
13+
// Format represents the MIME type of clipboard data.
14+
type Format int
1515

1616
// All sorts of supported clipboard data
1717
const (
18-
// MIMEText indicates plain text MIME format
19-
MIMEText MIMEType = iota
20-
// MIMEImage indicates image/png MIME format
21-
MIMEImage
18+
// FmtText indicates plain text MIME format
19+
FmtText Format = iota
20+
// FmtImage indicates image/png MIME format
21+
FmtImage
2222
)
2323

2424
// Due to the limitation on operating systems (such as darwin),
@@ -27,7 +27,7 @@ const (
2727
var lock = sync.Mutex{}
2828

2929
// Read reads and returns the clipboard data.
30-
func Read(t MIMEType) []byte {
30+
func Read(t Format) []byte {
3131
lock.Lock()
3232
defer lock.Unlock()
3333

@@ -40,7 +40,7 @@ func Read(t MIMEType) []byte {
4040
//
4141
// If the MIME type indicates an image, then the given buf assumes
4242
// the image data is PNG encoded.
43-
func Write(t MIMEType, buf []byte) <-chan struct{} {
43+
func Write(t Format, buf []byte) <-chan struct{} {
4444
lock.Lock()
4545
defer lock.Unlock()
4646

clipboard_darwin.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ import (
2727
"unsafe"
2828
)
2929

30-
func read(t MIMEType) (buf []byte) {
30+
func read(t Format) (buf []byte) {
3131
var (
3232
data unsafe.Pointer
3333
n C.uint
3434
)
3535
switch t {
36-
case MIMEText:
36+
case FmtText:
3737
n = C.clipboard_read_string(&data)
38-
case MIMEImage:
38+
case FmtImage:
3939
n = C.clipboard_read_image(&data)
4040
}
4141
if data == nil {
@@ -50,13 +50,13 @@ func read(t MIMEType) (buf []byte) {
5050

5151
// write writes the given data to clipboard and
5252
// returns true if success or false if failed.
53-
func write(t MIMEType, buf []byte) (bool, <-chan struct{}) {
53+
func write(t Format, buf []byte) (bool, <-chan struct{}) {
5454
var ok C.int
5555
switch t {
56-
case MIMEText:
56+
case FmtText:
5757
ok = C.clipboard_write_string(unsafe.Pointer(&buf[0]),
5858
C.NSInteger(len(buf)))
59-
case MIMEImage:
59+
case FmtImage:
6060
ok = C.clipboard_write_image(unsafe.Pointer(&buf[0]),
6161
C.NSInteger(len(buf)))
6262
}

clipboard_linux.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ func init() {
4545
}
4646
}
4747

48-
func read(t MIMEType) (buf []byte) {
48+
func read(t Format) (buf []byte) {
4949
switch t {
50-
case MIMEText:
50+
case FmtText:
5151
return readc("UTF8_STRING")
52-
case MIMEImage:
52+
case FmtImage:
5353
return readc("image/png")
5454
}
5555
return nil
@@ -74,12 +74,12 @@ func readc(t string) []byte {
7474

7575
// write writes the given data to clipboard and
7676
// returns true if success or false if failed.
77-
func write(t MIMEType, buf []byte) (bool, <-chan struct{}) {
77+
func write(t Format, buf []byte) (bool, <-chan struct{}) {
7878
var s string
7979
switch t {
80-
case MIMEText:
80+
case FmtText:
8181
s = "UTF8_STRING"
82-
case MIMEImage:
82+
case FmtImage:
8383
s = "image/png"
8484
}
8585

clipboard_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ func TestClipboard(t *testing.T) {
2222
if err != nil {
2323
t.Fatalf("failed to read gold file: %v", err)
2424
}
25-
clipboard.Write(clipboard.MIMEImage, data)
25+
clipboard.Write(clipboard.FmtImage, data)
2626

27-
b := clipboard.Read(clipboard.MIMEText)
27+
b := clipboard.Read(clipboard.FmtText)
2828
if b != nil {
2929
t.Fatalf("read clipboard that stores image data as text should fail, but got len: %d", len(b))
3030
}
3131

32-
b = clipboard.Read(clipboard.MIMEImage)
32+
b = clipboard.Read(clipboard.FmtImage)
3333
if b == nil {
3434
t.Fatalf("read clipboard that stores image data as image should success, but got: nil")
3535
}
@@ -41,13 +41,13 @@ func TestClipboard(t *testing.T) {
4141

4242
t.Run("text", func(t *testing.T) {
4343
data := []byte("golang.design/x/clipboard")
44-
clipboard.Write(clipboard.MIMEText, data)
44+
clipboard.Write(clipboard.FmtText, data)
4545

46-
b := clipboard.Read(clipboard.MIMEImage)
46+
b := clipboard.Read(clipboard.FmtImage)
4747
if b != nil {
4848
t.Fatalf("read clipboard that stores text data as image should fail, but got len: %d", len(b))
4949
}
50-
b = clipboard.Read(clipboard.MIMEText)
50+
b = clipboard.Read(clipboard.FmtText)
5151
if b == nil {
5252
t.Fatal("read clipboard taht stores text data as text should success, but got: nil")
5353
}
@@ -63,10 +63,10 @@ func TestClipboardMultipleWrites(t *testing.T) {
6363
if err != nil {
6464
t.Fatalf("failed to read gold file: %v", err)
6565
}
66-
chg := clipboard.Write(clipboard.MIMEImage, data)
66+
chg := clipboard.Write(clipboard.FmtImage, data)
6767

6868
data = []byte("golang.design/x/clipboard")
69-
clipboard.Write(clipboard.MIMEText, data)
69+
clipboard.Write(clipboard.FmtText, data)
7070

7171
ctx, cancel := context.WithTimeout(context.Background(), time.Second*2)
7272
defer cancel()
@@ -84,12 +84,12 @@ func TestClipboardMultipleWrites(t *testing.T) {
8484
t.Fatalf("changed channel should be closed after receiving the notification")
8585
}
8686

87-
b := clipboard.Read(clipboard.MIMEImage)
87+
b := clipboard.Read(clipboard.FmtImage)
8888
if b != nil {
8989
t.Fatalf("read clipboard that should store text data as image should fail, but got: %d", len(b))
9090
}
9191

92-
b = clipboard.Read(clipboard.MIMEText)
92+
b = clipboard.Read(clipboard.FmtText)
9393
if b == nil {
9494
t.Fatalf("read clipboard that should store text data as text should success, got: nil")
9595
}
@@ -107,8 +107,8 @@ func BenchmarkClipboard(b *testing.B) {
107107
b.ReportAllocs()
108108
b.ResetTimer()
109109
for i := 0; i < b.N; i++ {
110-
clipboard.Write(clipboard.MIMEText, data)
111-
_ = clipboard.Read(clipboard.MIMEText)
110+
clipboard.Write(clipboard.FmtText, data)
111+
_ = clipboard.Read(clipboard.FmtText)
112112
}
113113
})
114114
}

clipboard_windows.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99

1010
package clipboard
1111

12-
func read(t MIMEType) (buf []byte) {
12+
func read(t Format) (buf []byte) {
1313
panic("unsupported")
1414
}
1515

1616
// write writes the given data to clipboard and
1717
// returns true if success or false if failed.
18-
func write(t MIMEType, buf []byte) bool {
18+
func write(t Format, buf []byte) (bool, <-chan struct{}) {
1919
panic("unsupported")
2020
}

cmd/gclip/main.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,16 @@ func main() {
6767
}
6868

6969
func cpy() error {
70-
t := clipboard.MIMEText
70+
t := clipboard.FmtText
7171
ext := filepath.Ext(*file)
7272

7373
switch ext {
7474
case ".png":
75-
t = clipboard.MIMEImage
75+
t = clipboard.FmtImage
7676
case ".txt":
7777
fallthrough
7878
default:
79-
t = clipboard.MIMEText
79+
t = clipboard.FmtText
8080
}
8181

8282
var (
@@ -105,9 +105,9 @@ func cpy() error {
105105
func pst() (err error) {
106106
var b []byte
107107

108-
b = clipboard.Read(clipboard.MIMEText)
108+
b = clipboard.Read(clipboard.FmtText)
109109
if b == nil {
110-
b = clipboard.Read(clipboard.MIMEImage)
110+
b = clipboard.Read(clipboard.FmtImage)
111111
}
112112

113113
if *file != "" && b != nil {

0 commit comments

Comments
 (0)