private static object FormatIntermediateValue(FormattingIntermediate preFormattedValue, int width)
        {
            if (preFormattedValue.TextValue != null)
                return preFormattedValue.TextValue;

            return preFormattedValue.RenderableValue;
        }
        public void SetUp()
        {
            _simpleValue = new FormattingIntermediate(SimpleText);
            _multiLineValue = new FormattingIntermediate("Simple text string" + Environment.NewLine +
                                                         "for the purposes of measuring things.");
            _renderable = new RecordingConsoleAdapter();
            RenderText();
            _renderableValue = new FormattingIntermediate(_renderable);

            _renderableTable = new RecordingConsoleAdapter();
            RenderTable();
            _renderableTableValue = new FormattingIntermediate(_renderableTable);
        }
        public void SizingValuesCanBeRetrieved()
        {
            const string longB = "BBBBBBBBBBBBBBBBBB";
            var colValues0 = new FormattingIntermediate[] { "A", "B B B B B B", "CCCC" };
            var colValues1 = new FormattingIntermediate[] { "A", "B B B B B B " + longB + " B B B B B B B", "CCCC" };
            _sizer.AddColumn(_columnFormats[1], colValues1);
            _sizer.AddColumn(_columnFormats[0], colValues0);

            Assert.That(_sizer.GetSizeValues(1), Is.EqualTo(new [] {colValues0[1], colValues1[1]}));
        }
 private static IEnumerable<string> FormatColWithIntermediate(PropertyColumnFormat pcf, FormattingIntermediate preFormattedValue, 
     int width, int tabLength, int firstLineHangingIndent)
 {
     return PropertyStackFormatter.Format(pcf.Format, FormatIntermediateValue(preFormattedValue, width), width, tabLength, firstLineHangingIndent);
 }
        private int FitToLines(FormattingIntermediate v, int maxLineBreaks)
        {
            var width = v.Width;
            if (width == 0) return 1;

            var tooWide = 0;
            var tooNarrow = 0;
            do
            {
                var breaks = v.RenderableValue != null
                                 ? v.RenderableValue.CountWordWrapLineBreaks(width)
                                 : ColumnWrapper.CountWordwrapLineBreaks(v, _format, width);
                if (breaks <= maxLineBreaks)
                    tooWide = width;
                else
                    tooNarrow = width;

                if (tooWide - tooNarrow == 1) return tooWide;

                if (tooWide == 0)
                    width *= 2;
                else
                    width = tooNarrow + (tooWide - tooNarrow) / 2;
            } while (true);
        }