go-osc52
A Go library to work with the ANSI OSC52 terminal sequence.
Example
str := "Hello World!"
osc52.Copy(str)
osc52.CopyPrimary(str)
SSH Example
You can use this over SSH using gliderlabs/ssh for instance:
envs := sshSession.Environ()
pty, _, _ := s.Pty()
envs = append(envs, "TERM="+pty.Term)
output := NewOutput(sshSession, envs)
output.Copy("Hello awesome!")
If you're using tmux, you could pass the TMUX
environment variable to help detect tmux:
ssh -o SendEnv=TMUX <host>
Tmux users
If you're using tmux, make sure you set set -g default-terminal
in your tmux
config, to a value that starts with tmux-
. tmux-256color
for instance. See
this
for more details.
go-osc52
will wrap the OSC52 sequence in a tmux
escape sequence if tmux is
detected. If you're running tmux >= 3.3, OSC52 won't work and you'll need to set
the set -g allow-passthrough on
in your tmux config.
set -g allow-passthrough on
or set set -g set-clipboard on
in your tmux config and use your outer terminal in your code instead:
seq := osc52.Sequence("Hello awesome!", "xterm-kitty", osc52.ClipboardC)
os.Stderr.WriteString(seq)
Credits