-
Notifications
You must be signed in to change notification settings - Fork 783
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support setting and querying the terminal clipboard using OSC52
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
- Loading branch information
1 parent
eb2eee4
commit b97ffd7
Showing
4 changed files
with
96 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,68 @@ | ||
package tea | ||
|
||
// ClipboardMsg is a clipboard read message event. | ||
// This message is emitted when a terminal receives an OSC52 clipboard read | ||
// message event. | ||
// ClipboardMsg is a clipboard read message event. This message is emitted when | ||
// a terminal receives an OSC52 clipboard read message event. | ||
type ClipboardMsg string | ||
|
||
// String returns the string representation of the clipboard message. | ||
func (e ClipboardMsg) String() string { | ||
return string(e) | ||
} | ||
|
||
// PrimaryClipboardMsg is a primary clipboard read message event. This message | ||
// is emitted when a terminal receives an OSC52 primary clipboard read message | ||
// event. | ||
// Note that the primary clipboard selection is a feature present in X11 and | ||
// Wayland only. | ||
type PrimaryClipboardMsg string | ||
|
||
// String returns the string representation of the primary clipboard message. | ||
func (e PrimaryClipboardMsg) String() string { | ||
return string(e) | ||
} | ||
|
||
// setClipboardMsg is an internal message used to set the system clipboard | ||
// using OSC52. | ||
type setClipboardMsg string | ||
|
||
// SetClipboard produces a command that sets the system clipboard using OSC52. | ||
func SetClipboard(s string) Cmd { | ||
return func() Msg { | ||
return setClipboardMsg(s) | ||
} | ||
} | ||
|
||
// readClipboardMsg is an internal message used to read the system clipboard | ||
// using OSC52. | ||
type readClipboardMsg struct{} | ||
|
||
// ReadClipboard produces a command that reads the system clipboard using OSC52. | ||
func ReadClipboard() Msg { | ||
return readClipboardMsg{} | ||
} | ||
|
||
// setPrimaryClipboardMsg is an internal message used to set the primary | ||
// clipboard using OSC52. | ||
type setPrimaryClipboardMsg string | ||
|
||
// SetPrimaryClipboard produces a command that sets the primary clipboard using | ||
// OSC52. | ||
// Note that the primary clipboard selection is a feature present in X11 and | ||
// Wayland only. | ||
func SetPrimaryClipboard(s string) Cmd { | ||
return func() Msg { | ||
return setPrimaryClipboardMsg(s) | ||
} | ||
} | ||
|
||
// readPrimaryClipboardMsg is an internal message used to read the primary | ||
// clipboard using OSC52. | ||
type readPrimaryClipboardMsg struct{} | ||
|
||
// ReadPrimaryClipboard produces a command that reads the primary clipboard | ||
// using OSC52. | ||
// Note that the primary clipboard selection is a feature present in X11 and | ||
// Wayland only. | ||
func ReadPrimaryClipboard() Msg { | ||
return readPrimaryClipboardMsg{} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters