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

ANSI OSC 52 support? #3260

Closed
olegkrutov opened this issue Mar 22, 2021 · 13 comments · Fixed by #4220
Closed

ANSI OSC 52 support? #3260

olegkrutov opened this issue Mar 22, 2021 · 13 comments · Fixed by #4220
Assignees
Labels
help wanted type/enhancement Features or improvements to existing features
Milestone

Comments

@olegkrutov
Copy link

ANSI OSC 52 is a sequence to transport some data from remote console app to client's clipboard. For example, tmux can use it on remote side, and xterm (terminal app), Windows terminal and a number of others -- on client side. It would be very convenient to have such a feature in xterm.js.
Here is a simple test which sends a string from remote to local clipboard (taken here):
printf "\033]52;c;$(printf "%s" "blabla" | base64)\a"

@Tyriar Tyriar added the type/enhancement Features or improvements to existing features label Mar 22, 2021
@Tyriar
Copy link
Member

Tyriar commented Mar 22, 2021

This would need some thinking around how embedders can conditionally enable it, like how browsers ask if they can access the clipboard.

@olegkrutov
Copy link
Author

Maybe it can be done as plugin so it can be totally disabled, otherwise raising a pop-up window when such a sequence arrives first time in session?

@jerch
Copy link
Member

jerch commented Mar 22, 2021

Just tested this with Firefox and Chrome:

setTimeout(() => navigator.clipboard.writeText('Hello there!'), 1000);

which seems to work in both as long as something on the page has the focus. Not quite sure about the focus state, it also works if the browser window is in the background, but does not work, if the focus is in the console.
No clue about Safari.

What would be possible:

  • make it optional via terminal settings or as addon
  • use async handler for OSC 52, with this we can stop terminal progression and show an "Allow clipboard access?" popup, if the attempt fails in the first place due to missing focus (clipboard.writeText returns a promise, easy to get that up with an async handler now 😸)

@Tyriar
Copy link
Member

Tyriar commented Mar 22, 2021

which seems to work in both as long as something on the page has the focus.

I think browsers treat this differently and it may get blocked if it wasn't caused by a "user event" (ie. KeyboardEvent, MouseEvent).

make it optional via terminal settings or as addon

The way VS Code copies depends on the environment it's in, so this might need an event. If it was an event the embedder could just not listen to it if it doesn't want to support it then.

with this we can stop terminal progression and show an "Allow clipboard access?" popup,

We probably wouldn't want to pause the terminal, just request it and not await.

@olegkrutov
Copy link
Author

Isn't it worth to assume that since we are selecting text here in xterm session, we have a focus right now? Focus will be lost in situations like some "mirroring" of terminal output but I don't think this is 1) majority of cases and 2) we should manipulate with clipboard in these situations...

@jaraco
Copy link

jaraco commented Dec 7, 2021

Isn't it worth to assume that since we are selecting text here in xterm session, we have a focus right now? Focus will be lost in situations like some "mirroring" of terminal output but I don't think this is 1) majority of cases and 2) we should manipulate with clipboard in these situations...

OSC 52 doesn't mean text is selected. It means the remote process has emitted this sequence. That could happen from a process that's running, such as sleep 30; printf "\033]52;c;$(printf "%s" "blabla" | base64)\a". No selection necessary, and the terminal could easily be out of focus by the time the sequence is reached.

@jerch
Copy link
Member

jerch commented Dec 8, 2021

@jaraco Yes, part of the OSC 52 deal is that it works the way around for remote --> local clipboard mapping. For this it cannot be assumed, that the terminal still has focus. A partial workaround could be to implement a deferred clipboard write, which replays the write onFocus.

@Tyriar
Copy link
Member

Tyriar commented Dec 8, 2021

We may want to expose a handler on the API similar to the to attachCustomKeyEventHandler to handle copying, that way the embedder can hook it up to its clipboard mechanism (eg. electron/native copy API, clipboard web API, fallback to execCommand).

@YingboMa
Copy link

Is there any update on this? It would be really nice to have this feature in vscode's terminal.

@Tyriar
Copy link
Member

Tyriar commented Aug 12, 2022

@YingboMa as with anything where the clipboard is touched we want to make sure there aren't any security concerns (if you log into a malicious server, it could read your clipboard which may have a password in it?), we would need some API to plug the clipboard detection code in anyway I think so that would probably be solved by a warning on the API. Other than that potential issue, it just needs someone to come and help implement it.

aymanbagabas added a commit to aymanbagabas/xterm.js that referenced this issue Oct 19, 2022
Add support to ANSI OSC52 sequence to manipulate selection and clipboard
data. The sequence specs supports multiple selections but due to the
browser limitations (Clipboard API), this PR only supports manipulating
the clipboard selection.

Reference: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands
Fixes: xtermjs#3260
aymanbagabas added a commit to aymanbagabas/xterm.js that referenced this issue Oct 19, 2022
Add support to ANSI OSC52 sequence to manipulate selection and clipboard
data. The sequence specs supports multiple selections but due to the
browser limitations (Clipboard API), this PR only supports manipulating
the clipboard selection.

Reference: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands
Fixes: xtermjs#3260
aymanbagabas added a commit to aymanbagabas/xterm.js that referenced this issue Oct 19, 2022
Add support to ANSI OSC52 sequence to manipulate selection and clipboard
data. The sequence specs supports multiple selections but due to the
browser limitations (Clipboard API), this PR only supports manipulating
the clipboard selection.

Reference: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands
Fixes: xtermjs#3260
aymanbagabas added a commit to aymanbagabas/xterm.js that referenced this issue Oct 26, 2022
Add support to ANSI OSC52 sequence to manipulate selection and clipboard
data. The sequence specs supports multiple selections but due to the
browser limitations (Clipboard API), this PR only supports manipulating
the clipboard selection.

This adds a new `registerClipboardService` method to allow headless
xtermjs to register their own clipboard service.

The browser uses a clipboard service that use the Clipboard API to
read/write from and to the clipboard.

Reference: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands
Fixes: xtermjs#3260
aymanbagabas added a commit to aymanbagabas/xterm.js that referenced this issue Dec 18, 2022
Add support to ANSI OSC52 sequence to manipulate selection and clipboard
data. The sequence specs supports multiple selections but due to the
browser limitations (Clipboard API), this PR only supports manipulating
the clipboard selection.

This adds a new `registerClipboardService` method to allow headless
xtermjs to register their own clipboard service.

The browser uses a clipboard service that use the Clipboard API to
read/write from and to the clipboard.

Reference: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands
Fixes: xtermjs#3260
Signed-off-by: Ayman Bagabas <ayman.bagabas@gmail.com>
aymanbagabas added a commit to aymanbagabas/xterm.js that referenced this issue Dec 18, 2022
Add support to ANSI OSC52 sequence to manipulate selection and clipboard
data. The sequence specs supports multiple selections but due to the
browser limitations (Clipboard API), this PR only supports manipulating
the clipboard selection.

This adds a new `registerClipboardService` method to allow headless
xtermjs to register their own clipboard service.

The browser uses a clipboard service that use the Clipboard API to
read/write from and to the clipboard.

Reference: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands
Fixes: xtermjs#3260
Signed-off-by: Ayman Bagabas <ayman.bagabas@gmail.com>
aymanbagabas added a commit to aymanbagabas/xterm.js that referenced this issue Dec 18, 2022
Add support to ANSI OSC52 sequence to manipulate selection and clipboard
data. The sequence specs supports multiple selections but due to the
browser limitations (Clipboard API), this PR only supports manipulating
the clipboard selection.

This adds a new `registerClipboardService` method to allow headless
xtermjs to register their own clipboard service.

The browser uses a clipboard service that use the Clipboard API to
read/write from and to the clipboard.

Reference: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands
Fixes: xtermjs#3260
Signed-off-by: Ayman Bagabas <ayman.bagabas@gmail.com>
aymanbagabas added a commit to aymanbagabas/xterm.js that referenced this issue Dec 19, 2022
Add support to ANSI OSC52 sequence to manipulate selection and clipboard
data. The sequence specs supports multiple selections but due to the
browser limitations (Clipboard API), this PR only supports manipulating
the clipboard selection.

This adds a new `registerClipboardService` method to allow headless
xtermjs to register their own clipboard service.

The browser uses a clipboard service that use the Clipboard API to
read/write from and to the clipboard.

Reference: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands
Fixes: xtermjs#3260
Signed-off-by: Ayman Bagabas <ayman.bagabas@gmail.com>
aymanbagabas added a commit to aymanbagabas/xterm.js that referenced this issue Dec 26, 2022
Add support to ANSI OSC52 sequence to manipulate selection and clipboard
data. The sequence specs supports multiple selections but due to the
browser limitations (Clipboard API), this PR only supports manipulating
the clipboard selection.

This adds a new event listener to the terminal `onClipboard` to allow
other external implementations to hook into it.

The browser uses a clipboard service that use the Clipboard API to
read/write from and to the clipboard.

Reference: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands
Fixes: xtermjs#3260
Signed-off-by: Ayman Bagabas <ayman.bagabas@gmail.com>
aymanbagabas added a commit to aymanbagabas/xterm.js that referenced this issue Dec 26, 2022
Add support to ANSI OSC52 sequence to manipulate selection and clipboard
data. The sequence specs supports multiple selections but due to the
browser limitations (Clipboard API), this PR only supports manipulating
the clipboard selection.

This adds a new event listener to the terminal `onClipboard` to allow
other external implementations to hook into it.

The browser uses a clipboard service that use the Clipboard API to
read/write from and to the clipboard.

Reference: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands
Fixes: xtermjs#3260
Signed-off-by: Ayman Bagabas <ayman.bagabas@gmail.com>
@MrPeacockNLB
Copy link

really looking forward to copy text from tmux inside coder web terminal

aymanbagabas added a commit to aymanbagabas/xterm.js that referenced this issue Sep 20, 2023
Add support to ANSI OSC52 sequence to manipulate selection and clipboard
data. The sequence specs supports multiple clipboard selections but we
only support the common ones, system and primary clipboard selections.

This adds a new event listener to the common terminal module
`onClipboard` to allow external implementations to hook into it.

The addon uses the browser Clipboard API to read/write from and to the
clipboard. The default `ClipboardProvider` uses the browser Clipboard
API. This means it only supports read/write to and from the system
clipboard.

Reference: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands
Fixes: xtermjs#3260
Signed-off-by: Ayman Bagabas <ayman.bagabas@gmail.com>
aymanbagabas added a commit to aymanbagabas/xterm.js that referenced this issue Sep 20, 2023
Add support to ANSI OSC52 sequence to manipulate selection and clipboard
data. The sequence specs supports multiple clipboard selections but we
only support the common ones, system and primary clipboard selections.

This adds a new event listener to the common terminal module
`onClipboard` to allow external implementations to hook into it.

The addon uses the browser Clipboard API to read/write from and to the
clipboard. The default `ClipboardProvider` uses the browser Clipboard
API. This means it only supports read/write to and from the system
clipboard.

Reference: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands
Fixes: xtermjs#3260
Signed-off-by: Ayman Bagabas <ayman.bagabas@gmail.com>
aymanbagabas added a commit to aymanbagabas/xterm.js that referenced this issue Sep 20, 2023
Add support to ANSI OSC52 sequence to manipulate selection and clipboard
data. The sequence specs supports multiple clipboard selections but we
only support the common ones, system and primary clipboard selections.

This adds a new event listener to the common terminal module
`onClipboard` to allow external implementations to hook into it.

The addon uses the browser Clipboard API to read/write from and to the
clipboard. The default `ClipboardProvider` uses the browser Clipboard
API. This means it only supports read/write to and from the system
clipboard.

Reference: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands
Fixes: xtermjs#3260
Signed-off-by: Ayman Bagabas <ayman.bagabas@gmail.com>
aymanbagabas added a commit to aymanbagabas/xterm.js that referenced this issue Sep 20, 2023
Add support to ANSI OSC52 sequence to manipulate selection and clipboard
data. The sequence specs supports multiple clipboard selections but we
only support the common ones, system and primary clipboard selections.

This adds a new event listener to the common terminal module
`onClipboard` to allow external implementations to hook into it.

The addon uses the browser Clipboard API to read/write from and to the
clipboard. The default `ClipboardProvider` uses the browser Clipboard
API. This means it only supports read/write to and from the system
clipboard.

Reference: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands
Fixes: xtermjs#3260
Signed-off-by: Ayman Bagabas <ayman.bagabas@gmail.com>
aymanbagabas added a commit to aymanbagabas/xterm.js that referenced this issue Sep 20, 2023
Add support to ANSI OSC52 sequence to manipulate selection and clipboard
data. The sequence specs supports multiple clipboard selections but we
only support the common ones, system and primary clipboard selections.

This adds a new event listener to the common terminal module
`onClipboard` to allow external implementations to hook into it.

The addon uses the browser Clipboard API to read/write from and to the
clipboard. The default `ClipboardProvider` uses the browser Clipboard
API. This means it only supports read/write to and from the system
clipboard.

Reference: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands
Fixes: xtermjs#3260
Signed-off-by: Ayman Bagabas <ayman.bagabas@gmail.com>
haibchen added a commit to haibchen/configs that referenced this issue Jan 15, 2024
@Tyriar Tyriar added this to the 5.6.0 milestone Apr 22, 2024
@Tyriar Tyriar self-assigned this Apr 22, 2024
@luong-komorebi
Copy link

Thank you so much to all the contributors for delivering this feature

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted type/enhancement Features or improvements to existing features
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants