Ejemplo n.º 1
0
        public void AppendingMultipleMultistringsWithLines()
        {
            var builder = new ColoredMultistringBuilder();

            builder.AppendLine("Foo");
            builder.AppendLine(CreateCMS(", bar", ", baz!"));

            builder.ToString().Should().Be("Foo" + Environment.NewLine + ", bar, baz!" + Environment.NewLine);
        }
Ejemplo n.º 2
0
        private ColoredMultistring Format(IEnumerable <Section> sections)
        {
            // Start composing the content.
            var builder = new ColoredMultistringBuilder();

            // Generate and sequence sections.
            var firstSection = true;

            foreach (var section in sections)
            {
                if (!firstSection)
                {
                    for (var i = 0; i < _options.BlankLinesBetweenSections; ++i)
                    {
                        builder.AppendLine();
                    }
                }

                // Add header.
                if ((_options.SectionHeaders?.Include ?? false) && !string.IsNullOrEmpty(section.Name))
                {
                    if (_options.UseColor)
                    {
                        builder.AppendLine(new ColoredString(section.Name, _options.SectionHeaders.Color));
                    }
                    else
                    {
                        builder.AppendLine(section.Name);
                    }
                }

                // Add content.
                foreach (var entry in section.Entries)
                {
                    var text = (ColoredMultistring)entry.Wrap(
                        _options.MaxWidth.GetValueOrDefault(ArgumentSetHelpOptions.DefaultMaxWidth),
                        blockIndent: section.BodyIndentWidth,
                        hangingIndent: section.HangingIndentWidth);

                    if (_options.UseColor)
                    {
                        builder.AppendLine(text);
                    }
                    else
                    {
                        builder.AppendLine(text.ToString());
                    }
                }

                firstSection = false;
            }

            return(builder.ToMultistring());
        }
Ejemplo n.º 3
0
        public void AppendingMultipleStringsWithLines()
        {
            var builder = new ColoredMultistringBuilder();

            builder.AppendLine(new ColoredString[] { "Hello, ", "world" });

            builder.ToString().Should().Be("Hello, world" + Environment.NewLine);
        }
        public void TestThatAppendingLineInsertsNewLine()
        {
            var builder = new ColoredMultistringBuilder();

            builder.AppendLine(Enumerable.Empty <ColoredMultistring>());

            builder.ShouldProduce(new ColoredString(Environment.NewLine));
        }
Ejemplo n.º 5
0
        protected ColoredMultistring Format(IEnumerable <Section> sections)
        {
            // Start composing the content.
            var builder = new ColoredMultistringBuilder();

            // Generate and sequence sections.
            var firstSection = true;

            foreach (var section in sections)
            {
                if (!firstSection)
                {
                    builder.AppendLine();
                }

                // Add header.
                if (!string.IsNullOrEmpty(section.Name))
                {
                    var header = new ColoredString(section.Name, UseColor ? new ConsoleColor?(HeaderForegroundColor) : null);
                    builder.AppendLine(header);
                }

                // Add content.
                foreach (var entry in section.Entries)
                {
                    var text = (ColoredMultistring)entry.Wrap(
                        MaxWidth,
                        indent: section.BodyIndentWidth,
                        hangingIndent: section.HangingIndentWidth);

                    if (UseColor)
                    {
                        builder.AppendLine(text);
                    }
                    else
                    {
                        builder.AppendLine(text.ToString());
                    }
                }

                firstSection = false;
            }

            return(builder.ToMultistring());
        }