GitXplorerGitXplorer
a

go-osc52

public
38 stars
1 forks
0 issues

Commits

List of commits on branch master.
Verified
5c9b696c9b6c78c88f0bed2178029f2de2458b0e

fix: remove redundant sequence end

aaymanbagabas committed 2 years ago
Verified
ce73587a0f72cf077e55f163e71ea1b5496a133c

fix: use struct value receivers

aaymanbagabas committed 2 years ago
Verified
028c0dad51637d3f4969969f439af621847b4ab5

docs: update godoc link

aaymanbagabas committed 2 years ago
Verified
e279bc9f0784fe556566c775e1627ae882bd4345

docs: correct import path

aaymanbagabas committed 2 years ago
Verified
c2743c04b5204bdb7bde01accad8ac74d2b4c5b0

docs: correct tmux version

aaymanbagabas committed 2 years ago
Verified
779a37c6a21887a6bb3bb332734e446739c7f4a7

fix(gomod): update module path

aaymanbagabas committed 2 years ago

README

The README file for this repository.

go-osc52

Latest Release GoDoc

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"
)

func main() {
  s := "Hello World!"

  // Copy `s` to system clipboard
  osc52.New(s).WriteTo(os.Stderr)

  // Copy `s` to primary clipboard (X11)
  osc52.New(s).Primary().WriteTo(os.Stderr)

  // Query the clipboard
  osc52.Query().WriteTo(os.Stderr)

  // Clear system clipboard
  osc52.Clear().WriteTo(os.Stderr)

  // Use the fmt.Stringer interface to copy `s` to system clipboard
  fmt.Fprint(os.Stderr, osc52.New(s))

  // Or to primary clipboard
  fmt.Fprint(os.Stderr, osc52.New(s).Primary())
}

SSH Example

You can use this over SSH using gliderlabs/ssh for instance:

var sshSession ssh.Session
seq := osc52.New("Hello awesome!")
// Check if term is screen or tmux
pty, _, _ := s.Pty()
if pty.Term == "screen" {
  seq = seq.Screen()
} else if isTmux {
  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.3a 2.

Credits

  1. See tmux clipboard

  2. What is allow-passthrough