Пример #1
0
        private void ShowFormattedSummary(IndentingTextWriter writer, string summary, int?columns)
        {
            _env.AssertValue(writer);

            if (string.IsNullOrWhiteSpace(summary))
            {
                return;
            }

            // REVIEW: should we replace consecutive spaces with a single space as a preprocessing step?
            int screenWidth = (columns ?? CmdParser.GetConsoleWindowWidth()) - 1;

            // GetConsoleWindowWidth returns 0 if command redirection operator is used
            if (screenWidth <= 0)
            {
                screenWidth = 80;
            }

            const int indentLen = 3;
            string    indent    = new string(' ', indentLen);
            var       builder   = new StringBuilder();

            // REVIEW: is using StringSplitOptions.RemoveEmptyEntries the right thing to do here?
            var blocks = summary.Split(new[] { "\n", "\r" }, StringSplitOptions.RemoveEmptyEntries);

            for (int i = 0; i < blocks.Length; i++)
            {
                AppendFormattedText(builder, blocks[i], indent, screenWidth);
            }

            writer.WriteLine("Summary:");
            writer.WriteLine(builder);
        }