You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A Go library to work with the ANSI OSC52 terminal sequence.
Usage
You can use this small library to construct an ANSI OSC52 sequence suitable for
your terminal.
Example
import (
"os""fmt""github.com/aymanbagabas/go-osc52/v2"
)
funcmain() {
s:="Hello World!"// Copy `s` to system clipboardosc52.New(s).WriteTo(os.Stderr)
// Copy `s` to primary clipboard (X11)osc52.New(s).Primary().WriteTo(os.Stderr)
// Query the clipboardosc52.Query().WriteTo(os.Stderr)
// Clear system clipboardosc52.Clear().WriteTo(os.Stderr)
// Use the fmt.Stringer interface to copy `s` to system clipboardfmt.Fprint(os.Stderr, osc52.New(s))
// Or to primary clipboardfmt.Fprint(os.Stderr, osc52.New(s).Primary())
}
SSH Example
You can use this over SSH using gliderlabs/ssh for instance:
varsshSession ssh.Sessionseq:=osc52.New("Hello awesome!")
// Check if term is screen or tmuxpty, _, _:=s.Pty()
ifpty.Term=="screen" {
seq=seq.Screen()
} elseifisTmux {
seq=seq.Tmux()
}
seq.WriteTo(sshSession.Stderr())
Tmux
Make sure you have set-clipboard on in your config, otherwise, tmux won't
allow your application to access the clipboard 1.
Using the tmux option, osc52.TmuxMode or osc52.New(...).Tmux(), wraps the
OSC52 sequence in a special tmux DCS sequence and pass it to the outer
terminal. This requires allow-passthrough on in your config.
allow-passthrough is no longer enabled by default
since tmux 3.3a2.
Credits
vim-oscyank this is heavily inspired by vim-oscyank.