Files
xterm.js/addons/xterm-addon-clipboard
Ayman Bagabas db5bfc7525 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>
2023-09-20 17:46:52 -04:00
..
2023-09-20 17:46:52 -04:00
2023-09-20 17:46:52 -04:00
2023-09-20 17:46:52 -04:00
2023-09-20 17:46:52 -04:00
2023-09-20 17:46:52 -04:00
2023-09-20 17:46:52 -04:00
2023-09-20 17:46:52 -04:00
2023-09-20 17:46:52 -04:00
2023-09-20 17:46:52 -04:00
2023-09-20 17:46:52 -04:00
2023-09-20 17:46:52 -04:00

xterm-addon-clipboard

An addon for xterm.js that enables accessing the system clipboard. This addon requires xterm.js v4+.

Install

npm install --save xterm-addon-clipboard

Usage

import { Terminal } from 'xterm';
import { ClipboardAddon } from 'xterm-addon-clipboard';

const terminal = new Terminal();
const clipboardAddon = new ClipboardAddon();
terminal.loadAddon(clipboardAddon);

To use a custom clipboard provider

import { Terminal, IClipboardProvider, ClipboardSelection } from 'xterm';
import { ClipboardAddon } from 'xterm-addon-clipboard';

function b64Encode(data: string): string {
  // Base64 encode impl
}

function b64Decode(data: string): string {
  // Base64 decode impl
}

class MyCustomClipboardProvider implements IClipboardProvider {
  private _data: string
  public readText(selection: ClipboardSelection): Promise<string> {
    return Promise.resolve(b64Encode(this._data));
  }
  public writeText(selection: ClipboardSelection, data: string): Promise<void> {
    this._data = b64Decode(data);
    return Promise.resolve();
  }
}

const terminal = new Terminal();
const clipboardAddon = new ClipboardAddon(new MyCustomClipboardProvider());
terminal.loadAddon(clipboardAddon);

See the full API for more advanced usage.