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

ANSI color code interpretation broken in terminal #31326

Closed
oliversalzburg opened this issue Jul 24, 2017 · 8 comments
Closed

ANSI color code interpretation broken in terminal #31326

oliversalzburg opened this issue Jul 24, 2017 · 8 comments
Assignees
Labels
terminal General terminal issues that don't fall under another label upstream Issue identified as 'upstream' component related (exists outside of VS Code)
Milestone

Comments

@oliversalzburg
Copy link

  • VSCode Version: Code 1.14.2 (cb82feb, 2017-07-19T23:34:09.706Z)
  • OS Version: Windows_NT ia32 10.0.15063
  • Extensions:
Extension Author (truncated) Version
vscode-eslint dba 1.2.11
pgsql dou 0.0.8
EditorConfig Edi 0.9.4
JSDocTagComplete Hoo 0.0.2
vscode-esformatter how 1.5.2
output-colorizer IBM 0.1.2
vscode-puglint mrm 2.3.0

Steps to Reproduce:

When I issue certain commands in the terminal, color code interpretation seems to break at certain points in the output:

image

I don't know what it is specifically about the output that breaks the interpreter, but I can reproduce this at will with the CLI application I am using there.

To my knowledge, this worked previously and this works fine in other terminals.

@vscodebot vscodebot bot added the terminal General terminal issues that don't fall under another label label Jul 24, 2017
@Tyriar
Copy link
Member

Tyriar commented Jul 24, 2017

@oliversalzburg can you setup a small project/set of files that demonstrates the issue?

@Tyriar Tyriar added the info-needed Issue requires more information from poster label Jul 24, 2017
@oliversalzburg
Copy link
Author

oliversalzburg commented Jul 24, 2017

I'm having a really hard time isolating the issue due to how complex the scenario appears to be. However this is where I'm at right now: https://github.com/oliversalzburg/vscode-31326

To give some insight into what is happening. release will spawn git to create a commit. git will try to sign the commit with gpg2. gpg2 will ask gpg-agent for the key, which then spawns pinentry, a GUI application, to ask me for the password.

Now, if you don't have gpg signing of commits enabled, you won't see the issue.
image

Simple output to the console will also not break the terminal. For example, when git generated output and it gets printed to the console by the simple-git wrapper.
image

What is especially interesting here is that all git output is captured and the You need a passphrase... string is actually from gpg-agent. I have no idea how it is able to write to the console. But, when it does, it breaks the VS Code terminal.
image

@Tyriar
Copy link
Member

Tyriar commented Jul 24, 2017

@rprichard any ideas why this would be happening?

@Tyriar Tyriar added bug Issue identified by VS Code Team member as probable bug upstream Issue identified as 'upstream' component related (exists outside of VS Code) and removed info-needed Issue requires more information from poster labels Jul 24, 2017
@Tyriar Tyriar added this to the Backlog milestone Jul 24, 2017
@rprichard
Copy link

My guess: node.js turns ENABLE_VIRTUAL_TERMINAL_PROCESSING on, then sends escape sequences to the console to set the color. node.js runs gpg, which I'm guessing is an MSYS2/Cygwin-based program. The Cygwin runtime sets the console mode for various reasons, and incidentally turns ENABLE_VIRTUAL_TERMINAL_PROCESSING back off.

@rprichard
Copy link

@oliversalzburg Does this issue reproduce in an ordinary Windows console? e.g. using Start -> Run, run this command:

c:\msys64\usr\bin\bash.exe --login

Don't use mintty, and don't use ConEmu. If you have ConEmu configured to handle all new console windows, you may have to disable that option temporarily.

I see the same behavior if I run this JavaScript code (Windows 10 v2 console, 10.0.10563, with MSYS2 gpg.exe in the PATH):

// FWIW, I'm using node v8.1.0
const { spawnSync } = require("child_process");
process.stdout.write("\x1b[32m" + "color" + "\x1b[0m" + "\n");
spawnSync("gpg.exe", ["--foo-bar"], {stdio: "inherit"});
process.stdout.write("\x1b[32m" + "color" + "\x1b[0m" + "\n");

example

FWIW, the standalone ConoutMode test program in the winpty repository might be helpful for debugging this issue. It can show whether ENABLE_VIRTUAL_TERMINAL_PROCESSING flag is enabled, or set/unset the flag. It might not behave as expected if you run it from cmd.exe / powershell.exe, though, because those shells modify ENABLE_VIRTUAL_TERMINAL_PROCESSING themselves.

Here are some comments I made the last time I looked into this VT mode flag: rprichard/winpty#92 (comment).

@oliversalzburg
Copy link
Author

@rprichard Seems like you're right and this is not specific to VS Code.

When I run the command from cmd.exe, I see the same issue:
image

No idea why it works in ConEmu and I could have sworn this worked fine in VS Code previously. I even ran into a similar issue today, which happens when I cancel running unit tests:
image

All of this seems new to me. But maybe a Windows 10 update is to blame?

@rprichard
Copy link

No idea why it works in ConEmu ...

By default, ConEmu injects a hook DLL into processes attached to its hidden underlying console (which it calls the "RealConsole"). The ConEmu DLL overrides functions like WriteFile and WriteConsole{A,W} to interpret VT escape sequences. This ConEmu ability preceded the official Win10 v2 console support for VT escapes, which is controlled by the ENABLE_VIRTUAL_TERMINAL_PROCESSING mode flag. My guess is that the ability is unaffected by the ENABLE_VIRTUAL_TERMINAL_PROCESSING flag.

... I could have sworn this worked fine in VS Code previously. ... But maybe a Windows 10 update is to blame?

Lots of possibilities:

@Tyriar
Copy link
Member

Tyriar commented Jul 31, 2017

Closing as it looks to be at the Windows level 😃

@Tyriar Tyriar closed this as completed Jul 31, 2017
@Tyriar Tyriar removed the bug Issue identified by VS Code Team member as probable bug label Jul 31, 2017
@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 17, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
terminal General terminal issues that don't fall under another label upstream Issue identified as 'upstream' component related (exists outside of VS Code)
Projects
None yet
Development

No branches or pull requests

3 participants