vscode-powershell icon indicating copy to clipboard operation
vscode-powershell copied to clipboard

Start-Transcript + Write-Progress + yarn + MacOS: ^[[23;1R

Open dkattan opened this issue 8 months ago • 4 comments

Prerequisites

  • [x] I have written a descriptive issue title.
  • [x] I have searched all open and closed issues to ensure it has not already been reported.
  • [x] I have read the troubleshooting guide.
  • [x] I am sure this issue is with the extension itself and does not reproduce in a standalone PowerShell instance.
  • [x] I have verified that I am using the latest version of Visual Studio Code and the PowerShell extension.
  • [x] If this is a security issue, I have read the security issue reporting guidance.

Summary

An ANSI escape sequence is emitted and script execution is blocked until you hit Enter a bunch of times.

PowerShell Version

Name                           Value
----                           -----
PSVersion                      7.5.0
PSEdition                      Core
GitCommitId                    7.5.0
OS                             Darwin 24.3.0 Darwin Kernel Version 24.3.0: Thu Jan  2 20:24:22 PST 2025; root:xnu-11215.81.4~3/RELEASE_ARM64_T6041
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Name             : ConsoleHost
Version          : 7.5.0
InstanceId       : 54662023-751e-4a90-bdac-1799cccf6dfb
UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture   : en-US
CurrentUICulture : en-US
PrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
DebuggerEnabled  : True
IsRunspacePushed : False
Runspace         : System.Management.Automation.Runspaces.LocalRunspace

Visual Studio Code Version

1.98.2
ddc367ed5c8936efe395cffeec279b04ffd7db78
arm64

Extension Version

[email protected]

Steps to Reproduce

Run on MacOS in VS Code

# test.ps1
Start-Transcript -Path (New-TemporaryFile).FullName
Write-Progress "a"
yarn --version
Stop-Transcript
PS /Users/user/code> ./test.ps1
Transcript started, output file is /var/folders/c0/vqmgyfpx38q4bwrxrkcgwcyr0000gn/T/tmpMneggD.tmp
1.22.22                                                                                                                 
^[[6;1R

Details

  • Does not happen on VS Code in Windows
  • Does not happen from zsh Terminal outside of VS Code when run from `pwsh -File ./test.ps1

Visuals

Image

Logs

No response

dkattan avatar Mar 21 '25 17:03 dkattan

Hey, can you test in a PowerShell terminal that's in VS Code, but is not the extension terminal? Can you also test with VS Code's shell integration feature disabled?

andyleejordan avatar Mar 21 '25 18:03 andyleejordan

Hey, can you test in a PowerShell terminal that's in VS Code, but is not the extension terminal? Can you also test with VS Code's shell integration feature disabled?

Okay this is fun. If I paste it in as multiple lines like individual commands, no issue.

However, if I put it all on one line: Start-Transcript -Path (New-TemporaryFile).FullName;Write-Progress "a"; yarn --version; Stop-Transcript; it breaks on both pwsh and PowerShell Extension terminals.

Using F5 is likely running the whole thing as a single command.

I'm having a hard time disabling the shell integration. I set "terminal.integrated.shellIntegration.enabled": false but $env:TERM_PROGRAM still shows vscode even after relaunching. I'll hammer on it more tomorrow.

dkattan avatar Mar 27 '25 21:03 dkattan

I'm having a hard time disabling the shell integration. I set "terminal.integrated.shellIntegration.enabled": false but $env:TERM_PROGRAM still shows vscode even after relaunching. I'll hammer on it more tomorrow.

For posterity: It appears $env:TERM_PROGRAM is an unreliable indicator of whether shellIntegration is enabled or disabled. The more obvious way to tell if the shellIntegration is disabled is to open a new pwsh and hover over it and look for the presence or absence of "Shell integration activated"

Image

Also I find it interesting that shellIntegration-bash.sh uses VSCODE_SHELL_INTEGRATION=1 to prevent installing more than once per session but shellIntegration.ps1 uses $global:__VSCodeOriginalPrompt but I digress.

Ultimately disabling the shell integration did not fix it:

Image

dkattan avatar Mar 28 '25 11:03 dkattan

Okay here's something interesting and potentially unrelated but on Windows Write-Progress output is included in the transcript and gets clobbered by yarn --version's output:

**********************
PowerShell transcript start
Start time: 20250328063748
Username: AzureAD\DarrenKattan
RunAs User: AzureAD\DarrenKattan
Configuration Name: 
Machine: DKATTAN-PC3 (Microsoft Windows NT 10.0.26100.0)
Host Application: C:\Program Files\PowerShell\7\pwsh.dll -WorkingDirectory ~
Process ID: 26296
PSVersion: 7.5.0
PSEdition: Core
GitCommitId: 7.5.0
OS: Microsoft Windows 10.0.26100
Platform: Win32NT
PSCompatibleVersions: 1.0, 2.0, 3.0, 4.0, 5.0, 5.1, 6.0, 7.0
PSRemotingProtocolVersion: 2.3
SerializationVersion: 1.1.0.1
WSManStackVersion: 3.0
**********************
Transcript started, output file is C:\Users\DKattan\AppData\Local\Temp\tmpgp3yin.tmp
1.22.19essing                                                                                                        ]
**********************
PowerShell transcript end
End time: 20250328063748
**********************

However, if I don't run yarn at all, Write-Progress output is not included:

Start-Transcript -Path (New-TemporaryFile).FullName;"Running Write-Progress";Write-Progress "a";"Stopping Transcript"; Stop-Transcript;
**********************
PowerShell transcript start
Start time: 20250328064528
Username: AzureAD\DarrenKattan
RunAs User: AzureAD\DarrenKattan
Configuration Name: 
Machine: DKATTAN-PC3 (Microsoft Windows NT 10.0.26100.0)
Host Application: C:\Program Files\PowerShell\7\pwsh.dll -WorkingDirectory ~
Process ID: 26296
PSVersion: 7.5.0
PSEdition: Core
GitCommitId: 7.5.0
OS: Microsoft Windows 10.0.26100
Platform: Win32NT
PSCompatibleVersions: 1.0, 2.0, 3.0, 4.0, 5.0, 5.1, 6.0, 7.0
PSRemotingProtocolVersion: 2.3
SerializationVersion: 1.1.0.1
WSManStackVersion: 3.0
**********************
Transcript started, output file is C:\Users\DKattan\AppData\Local\Temp\tmplq1ybd.tmp
Running Write-Progress
Stopping Transcript
**********************
PowerShell transcript end
End time: 20250328064528
**********************

On MacOS if I continuously hit Enter to get through it while including yarn, Write-Progress output is not included, and Write-Progress is also not included without yarn.

So I guess the question is, should Write-Progress messages be included in the transcript? It seems like they shouldn't. But for some reason they are when NativeCommands like yarn are run.

I suppose the strangest thing is that I can't repro is in a Terminal outside of VS Code. If I open Terminal on MacOS and then type pwsh and paste this same repro line in it works just fine.

Final clue! If I redirect stderr to stdout, everything works as expected:

$global:__VSCodeOriginalPrompt;Start-Transcript -Path (New-TemporaryFile).FullName;Write-Progress "a"; yarn --version 2>&1; Stop-Transcript;

dkattan avatar Mar 28 '25 12:03 dkattan