-
-
Notifications
You must be signed in to change notification settings - Fork 73
/
copy.go
37 lines (31 loc) · 820 Bytes
/
copy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package termenv
import (
"strings"
"github.com/aymanbagabas/go-osc52/v2"
)
// Copy copies text to clipboard using OSC 52 escape sequence.
func (o Output) Copy(str string) {
s := osc52.New(str)
if strings.HasPrefix(o.environ.Getenv("TERM"), "screen") {
s = s.Screen()
}
_, _ = s.WriteTo(o)
}
// CopyPrimary copies text to primary clipboard (X11) using OSC 52 escape
// sequence.
func (o Output) CopyPrimary(str string) {
s := osc52.New(str).Primary()
if strings.HasPrefix(o.environ.Getenv("TERM"), "screen") {
s = s.Screen()
}
_, _ = s.WriteTo(o)
}
// Copy copies text to clipboard using OSC 52 escape sequence.
func Copy(str string) {
output.Copy(str)
}
// CopyPrimary copies text to primary clipboard (X11) using OSC 52 escape
// sequence.
func CopyPrimary(str string) {
output.CopyPrimary(str)
}