Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support setting and querying the terminal clipboard using OSC52 #1086

Merged
merged 2 commits into from
Aug 19, 2024

Conversation

aymanbagabas
Copy link
Member

This adds support to setting the system and primary (X11 & Wayland) clipboards using OSC52. This makes the clipboard commands work even on remote session such as SSH.

While this doesn't work on all terminals, most modern terminals support OSC52 including Alacritty, Kitty, Xterm.JS, etc. For terminals, that don't support OSC52, application developers should consider using a Golang clipboard library like https://github.com/atotto/clipboard.

OSC52 support can be detected if the terminal responds to a ReadClipboard command.

Fixes: #982

This adds support to setting the system and primary (X11 & Wayland)
clipboards using OSC52. This makes the clipboard commands work even on
remote session such as SSH.

While this doesn't work on all terminals, most modern terminals support
OSC52 including Alacritty, Kitty, Xterm.JS, etc. For terminals, that
don't support OSC52, application developers should consider using a
Golang clipboard library like https://github.com/atotto/clipboard.

OSC52 support can be detected if the terminal responds to a
`ReadClipboard` command.

Fixes: #982
@@ -581,15 +581,28 @@ func parseOsc(b []byte) (int, Msg) {
if len(parts) == 0 {
return i, ClipboardMsg("")
}
b64 := parts[len(parts)-1]
if len(parts) != 2 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe use strings.Cut? not sure if it existed in 1.18 or only earlier version

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But we also want to ensure that we exactly have 2 parts, strings.Cut will only split on the first occurrence of ;.

Base automatically changed from input to master August 19, 2024 15:47
@aymanbagabas aymanbagabas merged commit 6062461 into master Aug 19, 2024
16 of 18 checks passed
@aymanbagabas aymanbagabas deleted the input-clipboard branch August 19, 2024 16:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Async Clipboard
2 participants