Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Powershell Core OSC9;9 string leaves residue in prompt after using grep from git-for-windows with pipe #13572

Closed
3N4N opened this issue Jul 22, 2022 · 6 comments
Labels
Resolution-Duplicate There's another issue on the tracker that's pretty much the same thing.

Comments

@3N4N
Copy link

3N4N commented Jul 22, 2022

This is a port of an issue previously filed here: MicrosoftDocs/terminal#425.

Output of the bug

PS C:\Users\ACER> dir | grep 'pattern'           # no match
PS C:\Users\ACER> ←]9;9;"C:\Users\ACER"
PS C:\Users\ACER>
PS C:\Users\ACER> dir | grep 'Documents'     # matches
d-r--           10/9/2021 11:04 PM                Documents
PS C:\Users\ACER> ←]9;9;"C:\Users\ACER"
PS C:\Users\ACER>
PS C:\Users\ACER> grep -HnrIi 'damn' .\Documents\PowerShell\        # to show that without piping the bug doesn't appear
.\Documents\PowerShell\/Scripts/scratch.ps1:1:function Damn([string]$sym)
PS C:\Users\ACER>
PS C:\Users\ACER> dir | win32yank.exe -i  # to show that the problem is not with piping
PS C:\Users\ACER>

Reproduction steps

  1. Put the following in the $PROFILE.
    function prompt
    {
    $loc = Get-Location
    
    # Emulate standard PS prompt with location followed by ">"
    $out = "PS $loc> "
    
    # Add current working directory (FileSystem)
    if ($loc.Provider.Name -eq "FileSystem") {
        $out += "$([char]27)]9;9;`"$($loc.Path)`"$([char]7)"
    }
    
    return $out
    }
  2. Open a new PWSH tab in windows terminal.
  3. Make sure git is in the $env:path and invoke:
    dir | grep -i "pattern"

Versions of tools used

  • Windows Terminal: 1.15.2003.0 (why does wt -v not print in the console? I cannot even copy from the popup window.)
  • PowerShell Core: PowerShell 7.1.4
  • GIt for Windows: git version 2.33.0.windows.2

Discussions elsewhere

I mentioned in another issue -- may or may not be related -- that Windows Terminal crashes randomly if I use OSC9;9 string in the prompt. But I've been using the preview build for a week and it hasn't crashed yet. Update: I have had no crashes since then.

@ghost ghost added Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Needs-Tag-Fix Doesn't match tag requirements labels Jul 22, 2022
@DHowett
Copy link
Member

DHowett commented Jul 22, 2022

why does wt -v not print in the console?

It is too sad to countenance. Funny enough, if you press Ctrl+C in any standard Windows message box, it DOES unexpectedly give you a hard copy of it:

---------------------------
Help
---------------------------
Windows Terminal Preview
1.16.2004.0
---------------------------
OK   
---------------------------

I'm guessing this is related to msys restoring the console mode and turning off VT input . . . let me go digging, because I wrote this up before.

@3N4N
Copy link
Author

3N4N commented Jul 22, 2022

let me go digging, because I wrote this up before.

This is way too fast a response. I feel guilty now. Take your time.

Funny enough, if you press Ctrl+C in any standard Windows message box, it DOES unexpectedly give you a hard copy of it

Live and learn.

@DHowett
Copy link
Member

DHowett commented Jul 22, 2022

I feel guilty now.

Ha, don't! It's not a problem at all.

The symptoms here feel very similar to the ones dissected in #4921 (comment), which we traced back to an issue in the MSYS2 runtime that Git uses. I'm not sure whether the state of this issue has changed between 2.33 (the version you have installed) and 2.37 (the current version).

@3N4N
Copy link
Author

3N4N commented Jul 22, 2022

I can reproduce issue 4921. Although, I need to press enter once, then ←]9;9;"C:\Users\ACER" appears. Also, after git gui, if I run a command that produces an exception (apparently powershell errors and exceptions are different), the output is like this.

C:\Users\ACER> git gui
C:\Users\ACER> wrong_cmd hello world
←[91mwrong_cmd: ←[91mThe term 'wrong_cmd' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.←[0m
C:\Users\ACER> ←]9;9;"C:\Users\ACER"

So, basically terminal loses the ability to recognize the escape/special characters as escape/special characters, right?

I'm not sure whether the state of this issue has changed between 2.33 (the version you have installed) and 2.37 (the current version).

This issue persists with Msys2's grep command, too. And I regularly update msys.

@zadjii-msft
Copy link
Member

Yea, this looks like the same thing. I'm game to call this a dupe (and reopen if I'm wrong).

/dup #4921

@zadjii-msft zadjii-msft closed this as not planned Won't fix, can't repro, duplicate, stale Jul 25, 2022
@ghost
Copy link

ghost commented Jul 25, 2022

Hi! We've identified this issue as a duplicate of another one that already exists on this Issue Tracker. This specific instance is being closed in favor of tracking the concern over on the referenced thread. Thanks for your report!

@ghost ghost closed this as completed Jul 25, 2022
@ghost ghost added Resolution-Duplicate There's another issue on the tracker that's pretty much the same thing. and removed Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Needs-Tag-Fix Doesn't match tag requirements labels Jul 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution-Duplicate There's another issue on the tracker that's pretty much the same thing.
Projects
None yet
Development

No branches or pull requests

3 participants