-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
addon-clipboard.d.ts
113 lines (100 loc) · 3.35 KB
/
addon-clipboard.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/**
* Copyright (c) 2023 The xterm.js authors. All rights reserved.
* @license MIT
*/
import { Terminal, ITerminalAddon } from '@xterm/xterm';
declare module '@xterm/addon-clipboard' {
/**
* An xterm.js addon that enables accessing the system clipboard from
* xterm.js.
*/
export class ClipboardAddon implements ITerminalAddon {
/**
* Creates a new clipboard addon.
* @param base64 An optional base64 encoder/decoder.
* @param provider An optional clipboard provider.
*/
constructor(base64?: IBase64, provider?: IClipboardProvider);
/**
* Activates the addon
* @param terminal The terminal the addon is being loaded in.
*/
public activate(terminal: Terminal): void;
/**
* Disposes the addon.
*/
public dispose(): void
}
/**
* Clipboard selection type. This is used to specify which selection buffer to
* read or write to.
* - SYSTEM `c`: The system clipboard.
* - PRIMARY `p`: The primary clipboard. This is provided for compatibility
* with Linux X11.
*/
export const enum ClipboardSelectionType {
SYSTEM = 'c',
PRIMARY = 'p',
}
export interface IBase64 {
/**
* Converts a utf-8 string to a base64 string.
* @param data The utf-8 string to convert to base64 string.
*/
encodeText(data: string): string;
/**
* Converts a base64 string to a utf-8 string.
* @param data The base64 string to convert to utf-8 string.
* @throws An error if the input is not valid base64.
*/
decodeText(data: string): string;
}
/**
* A default Base64 encoding and decoding type.
**/
export class Base64 implements IBase64 {
/**
* Converts a utf-8 string to a base64 string.
* @param data The utf-8 string to convert to base64 string.
*/
public encodeText(data: string): string;
/**
* Converts a base64 string to a utf-8 string.
* @param data The base64 string to convert to utf-8 string.
* @throws An error if the input is not valid base64.
*/
public decodeText(data: string): string;
}
export interface IClipboardProvider {
/**
* Gets the clipboard content.
* @param selection The clipboard selection to read.
* @returns A promise that resolves with clipboard selection data.
*/
readText(selection: ClipboardSelectionType): string | Promise<string>;
/**
* Sets the clipboard content.
* @param selection The clipboard selection to set.
* @param data The clipboard text to write.
*/
writeText(selection: ClipboardSelectionType, text: string): void | Promise<void>;
}
/**
* The clipboard provider interface that enables xterm.js to access the system clipboard.
*/
export class BrowserClipboardProvider implements IClipboardProvider{
/**
* Reads text from the clipboard.
* @param selection The selection type to read from.
* @returns A promise that resolves with the text from the clipboard.
*/
public readText(selection: ClipboardSelectionType): Promise<string>;
/**
* Writes text to the clipboard.
* @param selection The selection type to write to.
* @param data The text to write to the clipboard.
* @returns A promise that resolves when the text has been written to the clipboard.
*/
public writeText(selection: ClipboardSelectionType, data: string): Promise<void>;
}
}