| 55 | ** No event is generated when dispose() is called |
| 56 | */ |
| 57 | export class PtyTerminal extends EventEmitter { |
| 58 | protected writeEmitter = new vscode.EventEmitter<string>() ; |
| 59 | private didPrompt = false; |
| 60 | private curLine = ''; // This input entered by the user |
| 61 | private cursorPos = 1; // This a relative position ater any prompt or output text |
| 62 | public terminal: vscode.Terminal = null; |
| 63 | private disposing = false; |
| 64 | private isPaused = false; |
| 65 | protected promptTimer: ResettableTimeout = null; |
| 66 | public isReady = false; |
| 67 | protected pendingWrites: any[] = []; |
| 68 | private suspendPrompting: boolean = false; |
| 69 | |
| 70 | private static oldOnes: { [name: string]: PtyTerminal } = {}; |
| 71 | |
| 72 | private readonly pty: vscode.Pseudoterminal = { |
| 73 | onDidWrite: this.writeEmitter.event, |
| 74 | // onDidOverrideDimensions?: vscode.Event<vscode.TerminalDimensions>; |
| 75 | // onDidClose?: vscode.Event<number | void>; |
| 76 | open: () => { this.onOpen(); }, |
| 77 | close: () => { this.onClose(); }, |
| 78 | /* |
| 79 | open(initialDimensions: vscode.TerminalDimensions): void { |
| 80 | throw new Error('Method not implemented.'); |
| 81 | } |
| 82 | */ |
| 83 | handleInput: (data: string) => { this.handleInput(data); } |
| 84 | /* |
| 85 | setDimensions?(dimensions: vscode.TerminalDimensions): void { |
| 86 | throw new Error('Method not implemented.'); |
| 87 | } |
| 88 | */ |
| 89 | }; |
| 90 | |
| 91 | constructor(protected options: IPtyTerminalOptions) { |
| 92 | super(); |
| 93 | this.terminal = vscode.window.createTerminal({ |
| 94 | name: this.options.name, |
| 95 | pty: this.pty |
| 96 | }); |
| 97 | this.resetOptions(options); |
| 98 | PtyTerminal.oldOnes[this.options.name] = this; |
| 99 | vscode.window.onDidCloseTerminal((t) => { |
| 100 | if ((t === this.terminal) && !this.disposing) { |
| 101 | this.onClose(); |
| 102 | } |
| 103 | }); |
| 104 | } |
| 105 | |
| 106 | private onOpen() { |
| 107 | this.isReady = true; |
| 108 | if (this.pendingWrites.length) { |
| 109 | for (const data of this.pendingWrites) { |
| 110 | this.write(data); |
| 111 | } |
| 112 | this.pendingWrites = []; |
| 113 | } else { |
| 114 | this.doPrompt(); |
nothing calls this directly
no test coverage detected