-
Notifications
You must be signed in to change notification settings - Fork 4
/
types.ts
224 lines (195 loc) · 5.11 KB
/
types.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/**
* @author Henry Hale <https://github.com/henryhale>
* @license MIT
*
* This contains the type declarations for the `xterminal` library. Note that
* some interfaces differ between this file and the actual implementation in
* source/, that's because this file declares the *Public* API which is intended
* to be stable and consumed by external programs.
*/
/// <reference lib="dom"/>
/**
* An object that can be disposed via a dispose function.
*/
export declare class IDisposable {
/**
* Clean up
*/
dispose(): void;
}
/**
* Type of event name.
*/
export type IEventName = string | symbol;
/**
* Callback function invoked when the event is dispatched.
*/
export type IEventListener = (...args: unknown[]) => void;
/**
* Event map
*/
interface IEventMap {
clear: () => void;
data: (input: string) => void;
keypress: (ev: IKeyPress) => void;
pause: () => void;
resume: () => void;
}
/**
* Object passed to callback functions invoked on `keypress` event
*/
export type IKeyPress = {
key: string;
value: string;
altKey: boolean;
metaKey: boolean;
shiftKey: boolean;
ctrlKey: boolean;
cancel(): void;
};
/**
* Event emitter
*
* It extends the Disposable class.
*/
export declare class XEventEmitter extends IDisposable {
/**
* Appends a event listener to the specified event.
*
* The listener is invoked everytime the event is dispatched.
*
* - return disposable object to remove the event listener
*/
on<K extends keyof IEventMap>(event: K, listener: IEventMap[K]): void;
on(event: IEventName, listener: IEventListener): void;
/**
* Appends a event listener to the specified event.
*
* The listener is invoked _only once_ when the event is dispatched.
*
* _It is deleted thereafter._
*/
once<K extends keyof IEventMap>(event: K, listener: IEventMap[K]): void;
once(event: IEventName, listener: IEventListener): void;
/**
* Removes an event listener from the specified event.
*
* The listener won't be invoked on event dispatch thereafter.
*/
off<K extends keyof IEventMap>(event: K, listener: IEventMap[K]): void;
off(event: IEventName, listener: IEventListener): void;
/**
* Triggers an event
* @param event The event name to dispatch.
* @param args data to be passed to the event listener.
*/
emit<K extends keyof IEventMap>(event: K, ...args: unknown[]): void;
emit(event: IEventName, ...args: unknown[]): void;
}
/**
* Terminal Options
*/
export type ITerminalOptions = {
/**
* An HTMLElement in which the terminal will be mounted
*/
target?: HTMLElement;
};
/**
* Plugin
*/
// export interface IPlugin {
// install(context: IPluginContext): void;
// }
/**
* XTerminal
*
* Create a new terminal instance
*/
declare class XTerminal extends XEventEmitter {
constructor(options?: ITerminalOptions);
/**
* Mounts the terminal instance in the `target` HTMLElement.
*
* If the selector is given, the first element is used.
*
* @param target An HTMLElement in which the terminal will be mounted.
*/
mount(target: HTMLElement | string): void;
/**
* Focus the terminal - ready for input.
*/
focus(): void;
/**
* Blurs the terminal.
*/
blur(): void;
/**
* Write data to the terminal.
*
* @param data The data to write to the terminal
* @param callback Optional function invoked on successful write
* @returns void
*/
write(data: string | number, callback?: () => void): void;
/**
* Write data to the terminal, followed by a break line character (\n).
*
* @param data The data to write to the terminal
* @param callback Optional function invoked on successful write
* @returns void
*/
writeln(data: string | number, callback?: () => void): void;
/**
* Clear the entire terminal.
*
* This method triggers the `clear` event.
*/
clear(): void;
/**
* Remove the element containing the previous output
*/
clearLast(): void;
/**
* Access the history stack
*/
history: string[];
/**
* Clears the entire history stack.
*/
clearHistory(): void;
/**
* Sets the autocomplete function that is invoked on Tab key.
*
* @param fn completer function that takes a string input and return a better
* completion.
*/
setCompleter(fn: (data: string) => string): void;
/**
* Deactivate the terminal input
*/
pause(): void;
/**
* Activate the terminal input
*/
resume(): void;
/**
* Gracefully close the terminal instance.
*
* This detaches all event listeners, unmounts the terminal from the DOM,
* and clears the backing functionality of the terminal.
*
* _The terminal should not be used again once disposed._
*
*/
dispose(): void;
/**
* Install an addon/plugin
*/
// use(plugin: IPlugin): void;
/**
* Version number
*/
static readonly version: string;
}
export default XTerminal;