2
>
* Copyright (c) Microsoft Corporation. All rights reserved.
3
>
* Licensed under the MIT License. See License.txt in the project root for license information.
4
>
*--------------------------------------------------------------------------------------------*/
5
>
6
>
import { Emitter, Event } from '../../../base/common/event.js';
7
>
import { DeferredPromise } from '../../../base/common/async.js';
8
>
import { Disposable, DisposableStore } from '../../../base/common/lifecycle.js';
9
>
import type { ILogService } from '../../log/common/log.js';
10
>
import pkg from '@xterm/headless';
11
>
12
>
type XtermTerminal = pkg.Terminal;
13
>
const { Terminal: XtermTerminal } = pkg;
14
>
15
>
export interface IAgentHostHeadlessTerminalOptions {
16
>
cols: number;
17
>
rows: number;
18
>
scrollback: number;
19
>
logService: ILogService;
20
>
terminalFactory?: (options: IXtermTerminalOptions) => XtermTerminal;
21
>
}
22
>
23
>
/**
24
>
* Mirrors an agent-host PTY into xterm's interpreted terminal model.
25
>
*
26
>
* The mirror is intentionally internal to the agent host. Protocol-visible
27
>
* terminal data still flows through the existing OSC 633 parser and content
28
>
* model; this class provides terminal responses for programs that query
29
>
* terminal state.
30
>
*/
31
>
export class AgentHostHeadlessTerminal extends Disposable {
32
>
33
>
private readonly _terminal: XtermTerminal;
34
>
private readonly _logService: ILogService;
35
>
private readonly _onResponseData = this._register(new Emitter<string>());
36
>
readonly onResponseData: Event<string> = this._onResponseData.event;
37
>
private _writeBarrier: Promise<void> = Promise.resolve();
38
>
private _isDisposed = false;
39
>
40
>
constructor(options: IAgentHostHeadlessTerminalOptions) {
41
super();
42
this._logService = options.logService;