chrisant996 / clink

Bash's powerful command line editing in cmd.exe
https://chrisant996.github.io/clink/
GNU General Public License v3.0
3.62k stars 143 forks source link

Odd "CLINK" being printed out during the middle of build process in Visual Studio #515

Closed ben-may closed 1 year ago

ben-may commented 1 year ago

Hi,

I have a strange issue where when we launch Visual Studio from a clink command prompt, we see

CLINK 

being printed out before some of our bat files we launch/execute. I can't find anywhere in the clink code or anything we are doing where we try to print out C\bL\b\I\bN\K\b \b since the unknown characters are BS or backspace characters.

Looking through the clink source I do see some things going on with \b being written out so perhaps it could be the culprit. since the letters are CLINK then I assume it must have something to do with clink.

If we launch Visual Studio not from a clink command prompt the issue does not occur.

We are using CLINK 1.3.0.f070e4

Thanks!

clink_issue
chrisant996 commented 1 year ago

See this code, and this global.

In order for Clink to detect when CMD is trying to print the prompt, Clink has to override the %PROMPT% variable to something both predictable and unique.

Since launching programs inherits environment variables, launching other programs from a Clink window gets the tagged prompt value. Launching CMD instances from those other programs inherits the tagged prompt value as well.

When CMD prints the tagged prompt value, the "C\bL\bI\bN\bK\b{original%PROMPT%value}" looks fine because the \b (Backspace) characters backspace over the tag characters, and the prompt looks fine.

But if a program (like Visual Studio) redirects the terminal output and does custom drawing of the terminal output and doesn't handle \b characters as doing a backspace, then the custom drawing will end up showing the "hidden" tag.

You could work around the issue by setting %PROMPT% inside the CMD shell launched inside Visual Studio.

There isn't a way for Clink to intercept the prompt without altering the prompt text.

chrisant996 commented 1 year ago

I marked it "working as intended" -- but I want to be clear that I don't mean the side effects are desirable, only that they're unavoidable and are part of the designed behavior.

ben-may commented 1 year ago

ah excellent thank-you for the explanation!