|
3 | 3 | * @license MIT |
4 | 4 | */ |
5 | 5 |
|
6 | | -import { Terminal as ITerminalApi, ITerminalOptions, IMarker, IDisposable, ILinkMatcherOptions, ITheme, ILocalizableStrings, ITerminalAddon, ISelectionPosition, IBuffer as IBufferApi, IBufferNamespace as IBufferNamespaceApi, IBufferLine as IBufferLineApi, IBufferCell as IBufferCellApi, IParser, IFunctionIdentifier, ILinkProvider, IUnicodeHandling, IUnicodeVersionProvider, FontWeight } from 'xterm'; |
| 6 | +import { Terminal as ITerminalApi, ITerminalOptions, IMarker, IDisposable, ILinkMatcherOptions, ITheme, ILocalizableStrings, ITerminalAddon, ISelectionPosition, IBufferNamespace as IBufferNamespaceApi, IParser, ILinkProvider, IUnicodeHandling, FontWeight } from 'xterm'; |
7 | 7 | import { ITerminal } from 'browser/Types'; |
8 | | -import { IBufferLine, ICellData } from 'common/Types'; |
9 | | -import { IBuffer, IBufferSet } from 'common/buffer/Types'; |
10 | | -import { CellData } from 'common/buffer/CellData'; |
11 | 8 | import { Terminal as TerminalCore } from '../Terminal'; |
12 | 9 | import * as Strings from '../LocalizableStrings'; |
13 | | -import { IEvent, EventEmitter } from 'common/EventEmitter'; |
| 10 | +import { IEvent } from 'common/EventEmitter'; |
| 11 | +import { ParserApi } from 'common/public/ParserApi'; |
| 12 | +import { UnicodeApi } from 'common/public/UnicodeApi'; |
14 | 13 | import { AddonManager } from './AddonManager'; |
15 | | -import { IParams } from 'common/parser/Types'; |
16 | | -import { BufferSet } from 'common/buffer/BufferSet'; |
| 14 | +import { BufferNamespaceApi } from 'common/public/BufferNamespaceApi'; |
17 | 15 |
|
18 | 16 | export class Terminal implements ITerminalApi { |
19 | 17 | private _core: ITerminal; |
@@ -218,123 +216,3 @@ export class Terminal implements ITerminalApi { |
218 | 216 | } |
219 | 217 | } |
220 | 218 | } |
221 | | - |
222 | | -class BufferApiView implements IBufferApi { |
223 | | - constructor( |
224 | | - private _buffer: IBuffer, |
225 | | - public readonly type: 'normal' | 'alternate' |
226 | | - ) { } |
227 | | - |
228 | | - public init(buffer: IBuffer): BufferApiView { |
229 | | - this._buffer = buffer; |
230 | | - return this; |
231 | | - } |
232 | | - |
233 | | - public get cursorY(): number { return this._buffer.y; } |
234 | | - public get cursorX(): number { return this._buffer.x; } |
235 | | - public get viewportY(): number { return this._buffer.ydisp; } |
236 | | - public get baseY(): number { return this._buffer.ybase; } |
237 | | - public get length(): number { return this._buffer.lines.length; } |
238 | | - public getLine(y: number): IBufferLineApi | undefined { |
239 | | - const line = this._buffer.lines.get(y); |
240 | | - if (!line) { |
241 | | - return undefined; |
242 | | - } |
243 | | - return new BufferLineApiView(line); |
244 | | - } |
245 | | - public getNullCell(): IBufferCellApi { return new CellData(); } |
246 | | -} |
247 | | - |
248 | | -class BufferNamespaceApi implements IBufferNamespaceApi { |
249 | | - private _normal: BufferApiView; |
250 | | - private _alternate: BufferApiView; |
251 | | - private _onBufferChange = new EventEmitter<IBufferApi>(); |
252 | | - public get onBufferChange(): IEvent<IBufferApi> { return this._onBufferChange.event; } |
253 | | - |
254 | | - constructor(private _core: ITerminal) { |
255 | | - this._normal = new BufferApiView(this._core.buffers.normal, 'normal'); |
256 | | - this._alternate = new BufferApiView(this._core.buffers.alt, 'alternate'); |
257 | | - this._core.buffers.onBufferActivate(() => this._onBufferChange.fire(this.active)); |
258 | | - } |
259 | | - public get active(): IBufferApi { |
260 | | - if (this._core.buffers.active === this._core.buffers.normal) { return this.normal; } |
261 | | - if (this._core.buffers.active === this._core.buffers.alt) { return this.alternate; } |
262 | | - throw new Error('Active buffer is neither normal nor alternate'); |
263 | | - } |
264 | | - public get normal(): IBufferApi { |
265 | | - return this._normal.init(this._core.buffers.normal); |
266 | | - } |
267 | | - public get alternate(): IBufferApi { |
268 | | - return this._alternate.init(this._core.buffers.alt); |
269 | | - } |
270 | | -} |
271 | | - |
272 | | -class BufferLineApiView implements IBufferLineApi { |
273 | | - constructor(private _line: IBufferLine) { } |
274 | | - |
275 | | - public get isWrapped(): boolean { return this._line.isWrapped; } |
276 | | - public get length(): number { return this._line.length; } |
277 | | - public getCell(x: number, cell?: IBufferCellApi): IBufferCellApi | undefined { |
278 | | - if (x < 0 || x >= this._line.length) { |
279 | | - return undefined; |
280 | | - } |
281 | | - |
282 | | - if (cell) { |
283 | | - this._line.loadCell(x, cell as ICellData); |
284 | | - return cell; |
285 | | - } |
286 | | - return this._line.loadCell(x, new CellData()); |
287 | | - } |
288 | | - public translateToString(trimRight?: boolean, startColumn?: number, endColumn?: number): string { |
289 | | - return this._line.translateToString(trimRight, startColumn, endColumn); |
290 | | - } |
291 | | -} |
292 | | - |
293 | | -class ParserApi implements IParser { |
294 | | - constructor(private _core: ITerminal) { } |
295 | | - |
296 | | - public registerCsiHandler(id: IFunctionIdentifier, callback: (params: (number | number[])[]) => boolean | Promise<boolean>): IDisposable { |
297 | | - return this._core.registerCsiHandler(id, (params: IParams) => callback(params.toArray())); |
298 | | - } |
299 | | - public addCsiHandler(id: IFunctionIdentifier, callback: (params: (number | number[])[]) => boolean | Promise<boolean>): IDisposable { |
300 | | - return this.registerCsiHandler(id, callback); |
301 | | - } |
302 | | - public registerDcsHandler(id: IFunctionIdentifier, callback: (data: string, param: (number | number[])[]) => boolean | Promise<boolean>): IDisposable { |
303 | | - return this._core.registerDcsHandler(id, (data: string, params: IParams) => callback(data, params.toArray())); |
304 | | - } |
305 | | - public addDcsHandler(id: IFunctionIdentifier, callback: (data: string, param: (number | number[])[]) => boolean | Promise<boolean>): IDisposable { |
306 | | - return this.registerDcsHandler(id, callback); |
307 | | - } |
308 | | - public registerEscHandler(id: IFunctionIdentifier, handler: () => boolean | Promise<boolean>): IDisposable { |
309 | | - return this._core.registerEscHandler(id, handler); |
310 | | - } |
311 | | - public addEscHandler(id: IFunctionIdentifier, handler: () => boolean | Promise<boolean>): IDisposable { |
312 | | - return this.registerEscHandler(id, handler); |
313 | | - } |
314 | | - public registerOscHandler(ident: number, callback: (data: string) => boolean | Promise<boolean>): IDisposable { |
315 | | - return this._core.registerOscHandler(ident, callback); |
316 | | - } |
317 | | - public addOscHandler(ident: number, callback: (data: string) => boolean | Promise<boolean>): IDisposable { |
318 | | - return this.registerOscHandler(ident, callback); |
319 | | - } |
320 | | -} |
321 | | - |
322 | | -class UnicodeApi implements IUnicodeHandling { |
323 | | - constructor(private _core: ITerminal) { } |
324 | | - |
325 | | - public register(provider: IUnicodeVersionProvider): void { |
326 | | - this._core.unicodeService.register(provider); |
327 | | - } |
328 | | - |
329 | | - public get versions(): string[] { |
330 | | - return this._core.unicodeService.versions; |
331 | | - } |
332 | | - |
333 | | - public get activeVersion(): string { |
334 | | - return this._core.unicodeService.activeVersion; |
335 | | - } |
336 | | - |
337 | | - public set activeVersion(version: string) { |
338 | | - this._core.unicodeService.activeVersion = version; |
339 | | - } |
340 | | -} |
0 commit comments