Conversation
Hi @AustinWise, I'm your friendly neighborhood .NET Foundation Pull Request Bot (You can call me DNFBOT). Thanks for your contribution! The agreement was validated by .NET Foundation and real humans are currently evaluating your PR. TTYL, DNFBOT; |
@@ -140,6 +140,8 @@ private static int ProcessArgs(string[] args) | |||
{ | |||
// mimic the env variable | |||
Environment.SetEnvironmentVariable(CommandContext.Variables.Verbose, verbose.ToString()); | |||
// Use the current value of AnsiPassThru but make sure child processes have it set to true. | |||
CommandContext.ShouldPassAnsiCodesThrough(); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
I changed the way the environmental variable is read to be explicit, instead of calling a getter method for the side effect of lazy initialization. |
Environment.SetEnvironmentVariable(CommandContext.Variables.Verbose, verbose.ToString()); | ||
} | ||
//This process should inherit AnsiPassThrough or use the default of false. | ||
CommandContext.InitializeAnsiPassThroughFromEnvironment(); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
I push a new commit that just applies the environmental variable to all children created with the Command class. I think this is the right place to set the variable as the Command does the output forwarding that depends on this variable being set in children. |
@@ -28,6 +28,7 @@ private Command(CommandSpec commandSpec) | |||
RedirectStandardError = true, | |||
RedirectStandardOutput = true | |||
}; | |||
psi.Environment[CommandContext.Variables.AnsiPassThru] = bool.TrueString; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This LGTM. We are having some issues with tests on the CI right now so we'll hold off on merging for the moment. I'd also like to see how this interacts with the new streamforwarder changes in #1240. I don't expect any issues but there is potential. |
If #1240 get's merged first I'll rebase ontop of it and try it out. It does not look like it would cause any problem. |
I rebased onto the tip of 1.0.0 to fix the merge conflicts. |
I rebased and it seems like #1364 has fixed the build problems. |
I think we should merge this today. @anurse want to take a quick look? |
LGTM too. ANSI pass-through should be able to go away once we change Command.cs to only redirect stdout/stderr when we actually want to capture the output. It's only there because Windows uses APIs to manage Console Colors rather than ANSI codes :) |
Since ANSI pass through is temporary, when I rebased I did not add the new parameter to ICommand. As an aside, during testing I discovered that Windows 10 v1511 added support for these ANSI codes. |
@dotnet-bot Windows_NT Debug Build please |
@brthor Odd, I don't understand why ProcessStartInfo.Enironment stopped working on just Windows. Do you have any ideas?
|
@@ -149,6 +149,7 @@ public ICommand ForwardStdOut(TextWriter to = null, bool onlyIfVerbose = false) | |||
if (to == null) | |||
{ | |||
_stdOut.ForwardTo(writeLine: Reporter.Output.WriteLine); | |||
_process.StartInfo.Environment[CommandContext.Variables.AnsiPassThru] = bool.TrueString; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@AustinWise Not sure, seems weird only on Windows. Will need to investigate |
Only apply the ANSI passthrough for child commands. Otherwise the escape codes are printed to the console on Windows Make Report.Write process escape codes so that forwarded output will have its escape codes processed. Also make verbose be inherited by all child processes.
@dotnet-bot Windows_NT Debug Build please |
@brthor I fixed the compile error. As part of doing that I put the ansiPassThrough back on Command and added it to ICommand. |
Fix color printing and --verbose
Thanks @AustinWise! |
@piotrpMSFT Thanks for @brthor reviewing my code. I'm looking forward to seeing pretty colors in my terminal again! |
I noticed that the escape codes are being printed instead of colors on Windows. There were a couple problems:
Calling ShouldPassAnsiCodesThrough() for the side effect of reading the environmental variable seems a little lame. Perhaps instead Command.CreateDotNet should always set this variable? I'm not sure if Microsoft.DotNet.Cli.Utils is meant for consumption by externals tools as a means of invoking dotnet.exe, so I did not do it there.