Debian Codegraph @

clipboard.go

raw symbols SCIP
1 // Copyright 2013 @atotto. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 // Package clipboard read/write on clipboard
6 package clipboard
7
8 import "context"
9
10 // ForceUnsupported is set to true to force the package to be unsupported.
11 // This is useful for testing purposes.
12 var ForceUnsupported bool
13
14 // ReadAll reads from the clipboard.
15 func ReadAll(ctx context.Context) ([]byte, error) {
16 return readAll(ctx)
17 }
18
19 // ReadAllString reads a string from the clipboard.
20 func ReadAllString(ctx context.Context) (string, error) {
21 text, err := readAll(ctx)
22 if err != nil {
23 return "", err
24 }
25
26 return string(text), nil
27 }
28
29 // WriteAll writes a string to the clipboard.
30 func WriteAll(ctx context.Context, text []byte) error {
31 return writeAll(ctx, text, false)
32 }
33
34 // WriteAllString writes a string to the clipboard.
35 func WriteAllString(ctx context.Context, text string) error {
36 return writeAll(ctx, []byte(text), false)
37 }
38
39 // WritePassword writes a password to the clipboard.
40 func WritePassword(ctx context.Context, text []byte) error {
41 return writeAll(ctx, text, true)
42 }
43
44 // IsUnsupported returns true if the current platform is not supported.
45 func IsUnsupported() bool {
46 return unsupported() || ForceUnsupported
47 }