| 1 |
//go:build (darwin || linux || windows) && cgo |
| 2 |
// +build darwin linux windows |
| 3 |
// +build cgo |
| 4 |
|
| 5 |
package clipboard |
| 6 |
|
| 7 |
import ( |
| •8 |
"context" |
| 9 |
"os" |
| 10 |
|
| 11 |
"github.com/juju/errors" |
| 12 |
"golang.design/x/clipboard" |
| 13 |
) |
| 14 |
|
| 15 |
var InitErr error = nil |
| 16 |
|
| 17 |
// init is a wrapper around clipboard.Init, it only exists because |
| 18 |
// clipboard.Init panics if it was built with CGO_ENABLED=0, but we want just |
| 19 |
// an error, not a panic; therefore we have this wrapper guarded with build |
| 20 |
// flags above. |
| 21 |
func init() { |
| 22 |
if os.Getenv("NERDLOG_NO_CLIPBOARD") != "" { |
| 23 |
InitErr = errors.Errorf("clipboard is disabled via NERDLOG_NO_CLIPBOARD env var") |
| 24 |
return |
| 25 |
} |
| 26 |
|
| 27 |
InitErr = errors.Trace(clipboard.Init()) |
| 28 |
} |
| 29 |
|
| 30 |
// WriteText is a wrapper around clipboard.Write with FmtText; it exists so |
| 31 |
// that we can avoid compiling it on unsupported platforms (e.g. FreeBSD) and |
| 32 |
// still have nerdlog working (without clipboard support). |
| 33 |
func WriteText(value []byte) { |
| •34 |
clipboard.Write(context.Background(), clipboard.FmtText, value) |
| 35 |
} |