Repository: vscode
Issue: Long prompt text with shell integration causes "ghost" text display in the VSCode bash terminal
Labels: bug,terminal-shell-bash

Type: <b>Bug</b>

When `$PS1` is enough long, and when shell integration is enabled, the bash terminal in VSCode sometimes gets weird text before each prompt.

Example:

```
$ PS1='\n\[\e[32m\]Short prompt text, OK.\[\e[0m\]\n$ '

Short prompt text, OK.
$ 

Short prompt text, OK.
$ echo $PS1
\[\]\n\[\e[32m\]Short prompt text, OK.\[\e[0m\]\n$ \[\]

Short prompt text, OK.
$ PS1='\n\[\e[36m\]A bit longer prompt text, OK. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.\[\e[0m\]\n$ '

A bit longer prompt text, OK. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.
$ 

A bit longer prompt text, OK. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.
$ echo $PS1
\[\]\n\[\e[36m\]A bit longer prompt text, OK. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.\[\e[0m\]\n$ \[\]

A bit longer prompt text, OK. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.
$ PS1='\n\[\e[35m\]Very long prompt text, bad! Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\[\e[0m\]\n$ '
por incididunt ut labore et dolore magna aliqua.\\[\\e[0m\\]\\n$ ';43490313-b88b-4f99-af78-d356ca0b3e38
Very long prompt text, bad! Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
$ 
empor incididunt ut labore et dolore magna aliqua.\x1b[0m\x0d\x0a$ 
Very long prompt text, bad! Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
$ echo $PS1
\[\]\n\[\e[35m\]Very long prompt text, bad! Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\[\e[0m\]\n$ \[\]
empor incididunt ut labore et dolore magna aliqua.\x1b[0m\x0d\x0a$ 
                                                                   Very long prompt text, bad! Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
 eiusmod tempor incididunt ut labore et dolore magna aliqua.
$
```

But you would prefer screenshot:

![vscode-ghost-in-the-shell](https://github.com/microsoft/vscode/assets/9891867/2de53f2e-d593-4c3e-badf-8959fa1c3a8c)

The reason I call them ghosts is because they can be purified by vertical resizing of the terminal:

![vscode-ghost-in-the-shell](https://github.com/microsoft/vscode/assets/9891867/c95d32bd-7d3a-4742-991a-68ad1081d165)

Notes:

- This issue occurs even when all extensions are disabled.
- This issue doesn't occur when shell integration is disabled or in standalone Git Bash (by Git for Windows).
- My actual `$PS1` when encountered this issue is ``\[\033]0;$TITLEPREFIX:$PWD\007\]\n\[\033[32m\]\u@\h \[\033[35m\]$MSYSTEM \[\033[33m\]\w\[\033[36m\]`__git_ps1 " (%s) \[\033[1;34m\]$(gitGetUserConfigs)"`\[\033[0m\]\n$ ``. This generates prompt such as `user@host MINGW64 /c/path/to/my/supercalifragilisticexpialidocious/repo (main =) Phroneris <email@example.com> [local]` and it sometimes gets enough long to cause this issue.
- I was initially going to report this on Git for Windows because this happened to me just after updating it from v2.24.0 to v2.45.2, but then I tried many things and found that this occurs only in the VSCode terminal with shell integration enabled, so here I am.
- Not sure of the relevance, but I notice that echoed `$PS1` always has additional `\[\]` to both ends; this addition occurs only in the VSCode terminal with shell integration enabled.
- Region/Language: Japan/Japanese

VS Code version: Code 1.90.1 (611f9bfce64f25108829dd295f54a6894e87339d, 2024-06-11T21:01:24.262Z)
OS version: Windows_NT x64 10.0.19045
Modes:

<details>
<summary>System Info</summary>

|Item|Value|
|---|---|
|CPUs|Intel(R) Core(TM) i5-3470 CPU @ 3.20GHz (4 x 3193)|
|GPU Status|2d_canvas: enabled<br>canvas_oop_rasterization: enabled_on<br>direct_rendering_display_compositor: disabled_off_ok<br>gpu_compositing: enabled<br>multiple_raster_threads: enabled_on<br>opengl: enabled_on<br>rasterization: enabled<br>raw_draw: disabled_off_ok<br>skia_graphite: disabled_off<br>video_decode: enabled<br>video_encode: unavailable_off<br>vulkan: disabled_off<br>webgl: enabled<br>webgl2: enabled<br>webgpu: enabled|
|Load (avg)|undefined|
|Memory (System)|31.89GB (23.51GB free)|
|Process Argv|--crash-reporter-id 0d0f4325-8fb8-4df0-af46-0539e77eed8e|
|Screen Reader|no|
|VM|0%|
</details>Extensions: none<details>
<summary>A/B Experiments</summary>

```
vsliv368cf:30146710
vspor879:30202332
vspor708:30202333
vspor363:30204092
vscod805cf:30301675
binariesv615:30325510
vsaa593:30376534
py29gd2263:31024239
c4g48928:30535728
azure-dev_surveyone:30548225
a9j8j154:30646983
962ge761:30959799
pythongtdpath:30769146
pythonidxpt:30866567
pythonnoceb:30805159
asynctok:30898717
pythontestfixt:30902429
pythonregdiag2:30936856
pythonmypyd1:30879173
h48ei257:31000450
pythontbext0:30879054
dsvsc016:30899300
dsvsc017:30899301
dsvsc018:30899302
cppperfnew:31000557
dsvsc020:30976470
pythonait:31006305
jchc7451:31067544
dsvsc021:30996838
g316j359:31013175
pythoncenvpt:31062603
a69g1124:31058053
dvdeprecation:31068756
pythonprt:31056678
dwnewjupytercf:31046870

```

</details>

<!-- generated by issue reporter -->