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

Change color for cmd command? #613

Closed
vict0rfr opened this issue Jun 6, 2024 · 7 comments
Closed

Change color for cmd command? #613

vict0rfr opened this issue Jun 6, 2024 · 7 comments
Labels
bug Something isn't working

Comments

@vict0rfr
Copy link

vict0rfr commented Jun 6, 2024

When I run the cmd /C "commands here" command, the text in the quotes is red, which is very misleading because it is not an error, how can I change the color for whatever is in the quotes?

@chrisant996
Copy link
Owner

What is the specific text in "commands here"?

I'm guessing that it isn't a program, and instead it's a CMD command like if ... or for ... do ... or etc?

@chrisant996 chrisant996 added the bug Something isn't working label Jun 6, 2024
@vict0rfr
Copy link
Author

vict0rfr commented Jun 6, 2024

"c:\Users\victo.vscode\extensions\ms-vscode.cpptools-1.20.5-win32-x64\debugAdapters\bin\WindowsDebugLauncher.exe --stdin=Microsoft-MIEngine-In-cjnjhnqy.ovv --stdout=Microsoft-MIEngine-Out-mxax5mwy.zip --stderr=Microsoft-MIEngine-Error-ka2yim3k.5no --pid=Microsoft-MIEngine-Pid-jfms5ffr.104 --dbgExe=C:\msys64\ucrt64\bin\gdb.exe --interpreter=mi" This. When I run c++ files.

@chrisant996
Copy link
Owner

Ah ok, thanks.

The issue here isn't the color, it's the parser that's running on the text after cmd /c.

(Interestingly, in the cited example, the quotes aren't needed. But the parser needs to better handle when quotes are present.)

The problem in the parser is that CMD can end up treating cmd /c "..." two different ways depending on what specific ... text is inside the quotes. It can end up getting treated as a quoted program name, or as a quoted command line.

I'll work on a fix.

You can clink set color.unrecognized clear, but of course that will also remove coloring from places where the input parser accurately recognized that the input isn't executable.

@vict0rfr
Copy link
Author

vict0rfr commented Jun 7, 2024

Thank you for your support. clink set color.unrecognized clear will do for me. As I only use cmd /C in vscode.

@chrisant996
Copy link
Owner

Yes, but I wanted to warn you that it affects more than just cmd /c.

@chrisant996
Copy link
Owner

And here are some quirky cases:

Command Line Behavior
echo hello & world Echoes "hello" and executes "world":
hello
'"world"' is not recognized...
"echo hello & world" Executes "echo hello & world":
'"echo hello & world"' is not recognized...
"echo hello" & world Executes "echo hello" and "world":
'"echo hello"' is not recognized...
'"world"' is not recognized...
cmd /c "echo hello" & world Echoes "hello" and executes "world.exe":
hello
'"world"' is not recognized...
cmd /c "echo hello & world" Echoes "hello" and executes "world.exe":
hello
'"world"' is not recognized...

This is because CMD has a bunch of special case rules for whether to strip a pair of quotes after /c, /k, and /r. Depending on how many quotes exist and what's between the quotes, CMD may or may not strip the first and last quotes.

That makes it quite difficult to accurately parse an input line that contains cmd followed by /cor/kor/r` (or an alias that expands to that). I intend to try...

@chrisant996
Copy link
Owner

It's way too convoluted to try to parse all the edge case and nested weirdnesses.

So instead, I've made it simply disable input line coloring by argmatchers for the rest of the line if the next thing after /C or /K or /R is a quote.

(It doesn't disable all input line coloring, it just applies the color.input color to the rest of the line, and prevents argmatchers from applying further colors. But other things can still apply coloring past that point; for example history expansion will still apply coloring past that point. This is a very nice compromise which achieves exactly what's desired the vast majority of the time.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants