copy.go 820 B

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