šŸš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more →
Socket
Sign inDemoInstall
Socket

github.com/aymanbagabas/go-osc52

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/aymanbagabas/go-osc52

v1.2.2
Source
Go
Version published
Created
Source

go-osc52

Latest Release GoDoc

A Go library to work with the ANSI OSC52 terminal sequence.

Example

str := "Hello World!"
osc52.Copy(str) // Copies str to system clipboard
osc52.CopyPrimary(str) // Copies str to primary clipboard (X11 only)

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)
// Copy text in your application
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:

// Assuming this code is running in tmux >= 3.3 in kitty
seq := osc52.Sequence("Hello awesome!", "xterm-kitty", osc52.ClipboardC)
os.Stderr.WriteString(seq)

Credits

  • vim-oscyank this is heavily inspired by vim-oscyank.

FAQs

Package last updated on 26 Feb 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts