Skip to content

Commit

Permalink
feat(copy): fix detecting tmux & upgrade go-osc52 to v2
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas authored and muesli committed Mar 8, 2023
1 parent 7eb5f84 commit a6f7ced
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
20 changes: 13 additions & 7 deletions copy.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
package termenv

import (
"github.com/aymanbagabas/go-osc52"
)
"strings"

func (o Output) osc52Output() *osc52.Output {
return osc52.NewOutput(o.tty, o.environ.Environ())
}
"github.com/aymanbagabas/go-osc52/v2"
)

// Copy copies text to clipboard using OSC 52 escape sequence.
func (o Output) Copy(str string) {
o.osc52Output().Copy(str)
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) {
o.osc52Output().CopyPrimary(str)
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.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/muesli/termenv
go 1.13

require (
github.com/aymanbagabas/go-osc52 v1.2.2
github.com/aymanbagabas/go-osc52/v2 v2.0.1
github.com/lucasb-eyer/go-colorful v1.2.0
github.com/mattn/go-isatty v0.0.17
github.com/mattn/go-runewidth v0.0.14
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/aymanbagabas/go-osc52 v1.2.2 h1:NT7wkhEhPTcKnBCdPi9djmyy9L3JOL4+3SsfJyqptCo=
github.com/aymanbagabas/go-osc52 v1.2.2/go.mod h1:zT8H+Rk4VSabYN90pWyugflM3ZhpTZNC7cASDfUCdT4=
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng=
Expand Down

0 comments on commit a6f7ced

Please sign in to comment.