Skip to content

bowbahdoe/osc52

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

osc52

javadoc Tests

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

Requires Java 17+

Dependency Information

Maven

<dependency>
    <groupId>dev.mccue</groupId>
    <artifactId>osc52</artifactId>
    <version>2023.06.20</version>
</dependency>

Gradle

dependencies {
    implementation("dev.mccue:osc52:2023.06.20")
}

Usage

You can use this small library to construct an ANSI OSC52 sequence suitable for your terminal.

Example

import dev.mccue.osc52.OSC52;

public class Main {
    public static void main(String[] args) {
        var s = "Hello World!";
        
        // Copy `s` to system clipboard
        System.err.print(OSC52.of(s));
        
        // Copy `s` to primary clipboard (X11)
        System.err.print(OSC52.of(s).primary());
        
        // Query the clipboard
        System.err.print(OSC52.ofQuery());
        
        // Clear system clipboard
        System.err.print(OSC52.ofClear());
    }
}

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, Mode.TMUX or OSC52.of(...).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

  • go-osc52 From which almost all code was cribbed. Thank you, @aymanbagabas!
  • vim-oscyank which inspired go-osc52.

Footnotes

  1. See tmux clipboard

  2. What is allow-passthrough

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages