vscode: Can't create terminal with a pseudo tty in the Web

Here is my code snippet

		const ptyWriteEmitter = new vscode.EventEmitter<string>();
		const pty = {
			onDidWrite: this.ptyWriteEmitter.event,
			open: () => {
				this.ptyWriteEmitter.fire(`\x1b[31m${name}\x1b[0m\r\n\r\n`);
			},
			close: () => {
			},
			handleInput: (data: string) => {
				// Echo the data
				if (data === '\r') {
					data = '\n';
				}
				if (data.charCodeAt(0) === 127) {
					// Delete last character
					this.ptyWriteEmitter.fire('\x1b[D\x1b[P');
					this.inputBuffer.splice(this.inputBuffer.length - 1, 1);
				} else {
					this.ptyWriteEmitter.fire(data === '\n' ? '\r\n' : data);
					this.inputBuffer.push(data);
				}
				if (data === '\n' && this.lineAvailable !== undefined) {
					this.lineAvailable();
				}
			}
		};

		const terminal = window.createTerminal({ name: 'Python Terminal', pty: pty  });
		terminal.show();

Trying to run this creates:

ERR A container element needs to be set with `attachToElement` and be part of the DOM before calling `_open`: Error: A container element needs to be set with `attachToElement` and be part of the DOM before calling `_open`
    at Ui._open (https://main.vscode-cdn.net/insider/b3546b4bb5aff5254ef857cfd68a3da8534c068f/out/vs/workbench/workbench.web.main.js:3097:46503)
    at Ui.setVisible (https://main.vscode-cdn.net/insider/b3546b4bb5aff5254ef857cfd68a3da8534c068f/out/vs/workbench/workbench.web.main.js:3099:2561)
    at h.showPanel (https://main.vscode-cdn.net/insider/b3546b4bb5aff5254ef857cfd68a3da8534c068f/out/vs/workbench/workbench.web.main.js:3097:22123)

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 16 (16 by maintainers)

Commits related to this issue

Most upvoted comments

@dbaeumer yeah, removing that await should ensure the view is visible so the element will be there to attach which means no exception that ruins the state.