Skip to content

Commit

Permalink
feat: copy to primary clipboard (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas authored Feb 2, 2023
1 parent 3848164 commit a33f7dc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,9 @@ output.ShowCursor()
// Copy to clipboard
output.Copy(message)

// Copy to primary clipboard (X11)
output.CopyPrimary(message)

// Trigger notification
output.Notify(title, body)
```
Expand Down
19 changes: 17 additions & 2 deletions copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,28 @@ import (
"github.com/aymanbagabas/go-osc52"
)

func (o Output) osc52Output() *osc52.Output {
return osc52.NewOutput(o.tty, o.environ.Environ())
}

// Copy copies text to clipboard using OSC 52 escape sequence.
func (o Output) Copy(str string) {
out := osc52.NewOutput(o.tty, o.environ.Environ())
out.Copy(str)
o.osc52Output().Copy(str)
}

// CopyPrimary copies text to primary clipboard (X11) using OSC 52 escape
// sequence.
func (o Output) CopyPrimary(str string) {
o.osc52Output().CopyPrimary(str)
}

// 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)
}

0 comments on commit a33f7dc

Please sign in to comment.