Repository: vscode
Issue: Shell integration with a `Pseudoterminal` does not capture output correctly
Labels: bug,help wanted,terminal-shell-integration

Type: <b>Bug</b>

Steps to reproduce:

1. Install this test extension: 
[pseudoterm-0.0.1.vsix.zip](https://github.com/microsoft/vscode/files/11226333/pseudoterm-0.0.1.vsix.zip)

2. In the terminal that automatically opens upon activation (it has the prompt `PSEUDOTERM>`), type a few characters, then press `Enter`. Some `OUTPUT` will be printed along with a new prompt. 
3. Observe that the "command" finished successfully and a blue dot is in the gutter next to it.
4. Right-click on the dot and copy the command. Verify that it says `INPUT`. This was set explicitly by `OSC 633 ; E`.
5. Right-click on the dot again and this time copy the output. The expected value when you paste is `OUTPUT`, but the observed value is `PSEUDOTERM>` plus whatever you typed. 

The source code for the test `Pseuoterminal` is pasted below.

```typescript
class PTY implements vscode.Pseudoterminal {
	private _writeEmitter = new vscode.EventEmitter<string>();
	onDidWrite: vscode.Event<string> = this._writeEmitter.event;
	private _closeEmitter = new vscode.EventEmitter<void>();
	onDidClose: vscode.Event<void> = this._closeEmitter.event;

	open(): void {
		// Print opening prompt
		this._writeEmitter.fire("\x1b]633;A\x07PSEUDOTERM>\x1b]633;B\x07");
	}
	close(): void {}
	handleInput(data: string): void {
		if (data == "\r") {
			// Start the execution
			this._writeEmitter.fire("\x1b]633;C\x07");
			// Set the command input
			this._writeEmitter.fire("\x1b]633;E;INPUT\x07");
			// Print the output
			this._writeEmitter.fire("\r\nOUTPUT");
			// End the execution
			this._writeEmitter.fire("\x1b]633;D;0\x07");
			// Print the next prompt
			this._writeEmitter.fire("\r\n\x1b]633;A\x07PSEUDOTERM>\x1b]633;B\x07");
		} else {
			this._writeEmitter.fire(data);
		}
	}
}
```

VS Code version: Code 1.77.3 (704ed70d4fd1c6bd6342c436f1ede30d1cff4710, 2023-04-12T09:41:48.638Z)
OS version: Darwin arm64 22.4.0
Modes:
Sandboxed: Yes

<details>
<summary>System Info</summary>

|Item|Value|
|---|---|
|CPUs|Apple M1 Max (10 x 24)|
|GPU Status|2d_canvas: enabled<br>canvas_oop_rasterization: disabled_off<br>direct_rendering_display_compositor: disabled_off_ok<br>gpu_compositing: enabled<br>metal: disabled_off<br>multiple_raster_threads: enabled_on<br>opengl: enabled_on<br>rasterization: enabled<br>raw_draw: disabled_off_ok<br>skia_renderer: enabled_on<br>video_decode: enabled<br>video_encode: enabled<br>vulkan: disabled_off<br>webgl: enabled<br>webgl2: enabled<br>webgpu: disabled_off|
|Load (avg)|3, 3, 3|
|Memory (System)|32.00GB (0.72GB free)|
|Process Argv|--enable-proposed-api intersystems-community.vscode-objectscript --crash-reporter-id b0028a94-14ad-4b84-8689-ef5145eb7f83|
|Screen Reader|no|
|VM|0%|
</details><details><summary>Extensions (6)</summary>

Extension|Author (truncated)|Version
---|---|---
objectscript-pack|int|1.0.3
servermanager|int|3.2.2
vscode-objectscript|int|2.8.1-beta.1
language-server|int|2.3.2
cpptools|ms-|1.14.5
vscode-lldb|vad|1.9.0


</details><details>
<summary>A/B Experiments</summary>

```
vsliv368cf:30146710
vsreu685:30147344
python383cf:30185419
vspor879:30202332
vspor708:30202333
vspor363:30204092
vslsvsres303:30308271
vserr242cf:30382550
pythontb:30283811
vsjup518:30340749
pythonptprofiler:30281270
vsdfh931cf:30280410
vshan820:30294714
vstes263:30335439
vscoreces:30445986
pythondataviewer:30285071
vscod805:30301674
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
cmake_vspar411:30581797
vsaa593cf:30376535
pythonvs932:30410667
cppdebug:30492333
vsclangdc:30486549
c4g48928:30535728
dsvsc012cf:30540253
pynewext54:30695312
azure-dev_surveyone:30548225
nodejswelcome1:30587005
282f8724:30602487
pyind779:30671433
f6dab269:30613381
pythonsymbol12:30671437
vsctsb:30705553
functionswalk:30687959
pythonms35:30701012
pythonclientmv:30713943

```

</details>

<!-- generated by issue reporter -->