Add support to ANSI OSC52
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>
This commit is contained in:
Vendored
+44
@@ -24,6 +24,12 @@ declare module 'xterm' {
|
||||
* An object containing options for the terminal.
|
||||
*/
|
||||
export interface ITerminalOptions {
|
||||
/**
|
||||
* Whether to allow clipboard access. When false, any access to the
|
||||
* clipboard is ignored. The default is false.
|
||||
*/
|
||||
allowClipboardAccess?: boolean;
|
||||
|
||||
/**
|
||||
* Whether to allow the use of proposed API. When false, any usage of APIs
|
||||
* marked as experimental/proposed will throw an error. The default is
|
||||
@@ -1061,6 +1067,19 @@ declare module 'xterm' {
|
||||
*/
|
||||
registerDecoration(decorationOptions: IDecorationOptions): IDecoration | undefined;
|
||||
|
||||
/**
|
||||
* Registers a clipboard provider, allowing custom handling of clipboard
|
||||
* selection events. This is used primarily to enable accessing the
|
||||
* clipboard to read/write clipboard data.
|
||||
* @param provider The provider to register.
|
||||
*/
|
||||
registerClipboardProvider(provider: IClipboardProvider): void;
|
||||
|
||||
/**
|
||||
* Deregisters the active clipboard provider.
|
||||
*/
|
||||
deregisterClipboardProvider(): void;
|
||||
|
||||
/**
|
||||
* Gets whether the terminal has an active selection.
|
||||
*/
|
||||
@@ -1842,4 +1861,29 @@ declare module 'xterm' {
|
||||
*/
|
||||
readonly wraparoundMode: boolean;
|
||||
}
|
||||
|
||||
export interface IClipboardProvider {
|
||||
/**
|
||||
* Gets the clipboard content.
|
||||
* @param selection The clipboard selection to read.
|
||||
* @returns A promise that resolves with the base64 encoded data.
|
||||
*/
|
||||
readText(selection: ClipboardSelection): Promise<string>;
|
||||
|
||||
/**
|
||||
* Sets the clipboard content.
|
||||
* @param selection The clipboard selection to set.
|
||||
* @param data The base64 encoded data to set. If the data is invalid base64, the clipboard is
|
||||
* cleared.
|
||||
*/
|
||||
writeText(selection: ClipboardSelection, data: string): Promise<void>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clipboard selection type.
|
||||
*/
|
||||
export const enum ClipboardSelection {
|
||||
SYSTEM = 'c',
|
||||
PRIMARY = 'p',
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user