Inheritance: System.CommandLine.Rendering.ColorSpan
 public override void VisitForegroundColorSpan(ForegroundColorSpan span)
 {
     if (span.RgbColor == null &&
         _foregroundColorMappings.TryGetValue(span.Name, out var color))
     {
         Terminal.ForegroundColor = color;
     }
     else
     {
         var backgroundColor = Terminal.BackgroundColor;
         Terminal.ResetColor();
         Terminal.BackgroundColor = backgroundColor;
     }
 }
        public override void VisitForegroundColorSpan(ForegroundColorSpan span)
        {
            AnsiControlCode controlCode;

            if (span.RgbColor is RgbColor rgb)
            {
                controlCode = Color.Foreground.Rgb(rgb.Red, rgb.Green, rgb.Blue);
            }
            else if (!_foregroundColorControlCodeMappings.TryGetValue(span.Name, out controlCode))
            {
                return;
            }

            Writer.Write(controlCode.EscapeSequence);
        }
Esempio n. 3
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);
        }