Example #1
0
        protected override IEnumerable <Segment> Render(RenderContext context, int maxWidth)
        {
            lock (_lock)
            {
                if (_renderable != null)
                {
                    var segments = _renderable.Render(context, maxWidth);
                    var lines    = Segment.SplitLines(context, segments);

                    var shape = SegmentShape.Calculate(context, lines);
                    _shape = _shape == null ? shape : _shape.Value.Inflate(shape);
                    _shape.Value.Apply(context, ref lines);

                    foreach (var(_, _, last, line) in lines.Enumerate())
                    {
                        foreach (var item in line)
                        {
                            yield return(item);
                        }

                        if (!last)
                        {
                            yield return(Segment.LineBreak);
                        }
                    }

                    yield break;
                }

                _shape = null;
            }
        }
Example #2
0
 public SegmentShape Inflate(SegmentShape other)
 {
     return(new SegmentShape(
                Math.Max(Width, other.Width),
                Math.Max(Height, other.Height)));
 }
Example #3
0
        protected override IEnumerable <Segment> Render(RenderContext context, int maxWidth)
        {
            lock (_lock)
            {
                DidOverflow = false;

                if (_renderable != null)
                {
                    var segments = _renderable.Render(context, maxWidth);
                    var lines    = Segment.SplitLines(segments);

                    var shape = SegmentShape.Calculate(context, lines);
                    if (shape.Height > _console.Profile.Height)
                    {
                        if (Overflow == VerticalOverflow.Crop)
                        {
                            if (OverflowCropping == VerticalOverflowCropping.Bottom)
                            {
                                // Remove bottom lines
                                var index = Math.Min(_console.Profile.Height, lines.Count);
                                var count = lines.Count - index;
                                lines.RemoveRange(index, count);
                            }
                            else
                            {
                                // Remove top lines
                                var start = lines.Count - _console.Profile.Height;
                                lines.RemoveRange(0, start);
                            }

                            shape = SegmentShape.Calculate(context, lines);
                        }
                        else if (Overflow == VerticalOverflow.Ellipsis)
                        {
                            var ellipsisText = _console.Profile.Capabilities.Unicode ? "…" : "...";
                            var ellipsis     = new SegmentLine(((IRenderable) new Markup($"[yellow]{ellipsisText}[/]")).Render(context, maxWidth));

                            if (OverflowCropping == VerticalOverflowCropping.Bottom)
                            {
                                // Remove bottom lines
                                var index = Math.Min(_console.Profile.Height - 1, lines.Count);
                                var count = lines.Count - index;
                                lines.RemoveRange(index, count);
                                lines.Add(ellipsis);
                            }
                            else
                            {
                                // Remove top lines
                                var start = lines.Count - _console.Profile.Height;
                                lines.RemoveRange(0, start + 1);
                                lines.Insert(0, ellipsis);
                            }

                            shape = SegmentShape.Calculate(context, lines);
                        }

                        DidOverflow = true;
                    }

                    _shape = _shape == null ? shape : _shape.Value.Inflate(shape);
                    _shape.Value.Apply(context, ref lines);

                    foreach (var(_, _, last, line) in lines.Enumerate())
                    {
                        foreach (var item in line)
                        {
                            yield return(item);
                        }

                        if (!last)
                        {
                            yield return(Segment.LineBreak);
                        }
                    }

                    yield break;
                }

                _shape = null;
            }
        }