示例#1
0
        private static (bool Ansi, bool Legacy) DetectAnsi(AnsiConsoleSettings settings, System.IO.TextWriter buffer)
        {
            var supportsAnsi  = settings.Ansi == AnsiSupport.Yes;
            var legacyConsole = false;

            if (settings.Ansi == AnsiSupport.Detect)
            {
                (supportsAnsi, legacyConsole) = AnsiDetector.Detect(buffer.IsStandardError(), true);

                // Check whether or not this is a legacy console from the existing instance (if any).
                // We need to do this because once we upgrade the console to support ENABLE_VIRTUAL_TERMINAL_PROCESSING
                // on Windows, there is no way of detecting whether or not we're running on a legacy console or not.
                if (AnsiConsole.Created && !legacyConsole && (buffer.IsStandardOut() || buffer.IsStandardError()) && AnsiConsole.Profile.Capabilities.Legacy)
                {
                    legacyConsole = AnsiConsole.Profile.Capabilities.Legacy;
                }
            }
            else
            {
                if (buffer.IsStandardOut() || buffer.IsStandardError())
                {
                    // Are we running on Windows?
                    if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                    {
                        // Not the first console we're creating?
                        if (AnsiConsole.Created)
                        {
                            legacyConsole = AnsiConsole.Profile.Capabilities.Legacy;
                        }
                        else
                        {
                            // Try detecting whether or not this
                            (_, legacyConsole) = AnsiDetector.Detect(buffer.IsStandardError(), false);
                        }
                    }
                }
            }

            return(supportsAnsi, legacyConsole);
        }