Ejemplo n.º 1
0
        public void RenderToRegion(
            Span span,
            Region region)
        {
            if (region == null)
            {
                throw new ArgumentNullException(nameof(region));
            }

            if (span == null)
            {
                span = Span.Empty();
            }
            else if (_resetAfterRender)
            {
                span = new ContainerSpan(
                    span,
                    ForegroundColorSpan.Reset(),
                    BackgroundColorSpan.Reset());
            }

            SpanVisitor visitor = null;

            if (_mode == OutputMode.Auto)
            {
                _mode = _terminal?.DetectOutputMode() ??
                        OutputMode.PlainText;
            }

            switch (_mode)
            {
            case OutputMode.NonAnsi:
                visitor = new NonAnsiRenderingSpanVisitor(
                    _terminal,
                    region);
                break;

            case OutputMode.Ansi:
                visitor = new AnsiRenderingSpanVisitor(
                    _console,
                    region);
                break;

            case OutputMode.PlainText:
                visitor = new FileRenderingSpanVisitor(
                    _console.Out,
                    new Region(region.Left,
                               region.Top,
                               region.Width,
                               region.Height,
                               false));
                break;

            default:
                throw new NotSupportedException();
            }

            visitor.Visit(span);
        }
Ejemplo n.º 2
0
        public void RenderToRegion(
            Span span,
            Region region)
        {
            SpanVisitor visitor;

            if (span == null)
            {
                span = Span.Empty();
            }
            else if (_resetAfterRender)
            {
                span = new ContainerSpan(
                    span,
                    ForegroundColorSpan.Reset(),
                    BackgroundColorSpan.Reset());
            }

            switch (Mode)
            {
            case OutputMode.NonAnsi:
                visitor = new NonAnsiRenderingSpanVisitor(
                    _terminal,
                    region);
                break;

            case OutputMode.Ansi:
                visitor = new AnsiRenderingSpanVisitor(
                    _console,
                    region);
                break;

            case OutputMode.File:
                visitor = new FileRenderingSpanVisitor(
                    _console.Out,
                    new Region(region.Left,
                               region.Top,
                               region.Width,
                               region.Height,
                               false));
                break;

            default:
                throw new NotSupportedException();
            }

            visitor.Visit(span);
        }