A Java library to work with the ANSI OSC52 terminal sequence.
Requires Java 17+
<dependency>
<groupId>dev.mccue</groupId>
<artifactId>osc52</artifactId>
<version>2023.06.20</version>
</dependency>
dependencies {
implementation("dev.mccue:osc52:2023.06.20")
}
You can use this small library to construct an ANSI OSC52 sequence suitable for your terminal.
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());
}
}
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.
- go-osc52 From which almost all code was cribbed. Thank you, @aymanbagabas!
- vim-oscyank which inspired go-osc52.