copy.go

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