Adding upstream version 0.7.0+dfsg.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
f170ee46ad
commit
79ead63b61
35 changed files with 2904 additions and 0 deletions
57
example_test.go
Normal file
57
example_test.go
Normal file
|
@ -0,0 +1,57 @@
|
|||
// Copyright 2021 The golang.design Initiative Authors.
|
||||
// All rights reserved. Use of this source code is governed
|
||||
// by a MIT license that can be found in the LICENSE file.
|
||||
//
|
||||
// Written by Changkun Ou <changkun.de>
|
||||
|
||||
//go:build cgo
|
||||
// +build cgo
|
||||
|
||||
package clipboard_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"golang.design/x/clipboard"
|
||||
)
|
||||
|
||||
func ExampleWrite() {
|
||||
err := clipboard.Init()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
clipboard.Write(clipboard.FmtText, []byte("Hello, 世界"))
|
||||
// Output:
|
||||
}
|
||||
|
||||
func ExampleRead() {
|
||||
err := clipboard.Init()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println(string(clipboard.Read(clipboard.FmtText)))
|
||||
// Output:
|
||||
// Hello, 世界
|
||||
}
|
||||
|
||||
func ExampleWatch() {
|
||||
err := clipboard.Init()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*2)
|
||||
defer cancel()
|
||||
|
||||
changed := clipboard.Watch(context.Background(), clipboard.FmtText)
|
||||
go func(ctx context.Context) {
|
||||
clipboard.Write(clipboard.FmtText, []byte("你好,world"))
|
||||
}(ctx)
|
||||
fmt.Println(string(<-changed))
|
||||
// Output:
|
||||
// 你好,world
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue