...

Source file src/github.com/muesli/termenv/copy.go

Documentation: github.com/muesli/termenv

     1  package termenv
     2  
     3  import (
     4  	"strings"
     5  
     6  	"github.com/aymanbagabas/go-osc52/v2"
     7  )
     8  
     9  // Copy copies text to clipboard using OSC 52 escape sequence.
    10  func (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.
    20  func (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.
    29  func Copy(str string) {
    30  	output.Copy(str)
    31  }
    32  
    33  // CopyPrimary copies text to primary clipboard (X11) using OSC 52 escape
    34  // sequence.
    35  func CopyPrimary(str string) {
    36  	output.CopyPrimary(str)
    37  }
    38  

View as plain text