public void A_ForegroundColorSpan_and_a_BackgroundColorSpan_having_the_same_name_are_not_equal() { var one = new ForegroundColorSpan("green", Ansi.Color.Foreground.Green); var two = new BackgroundColorSpan("green", Ansi.Color.Foreground.Green); one.Equals(two).Should().BeFalse(); }
public void BackgroundColorSpans_with_different_names_are_not_equal() { var one = new BackgroundColorSpan("red", Ansi.Color.Foreground.Red); var two = new BackgroundColorSpan("green", Ansi.Color.Foreground.Green); one.Equals(two).Should().BeFalse(); }
public void SpanVisitor_visits_child_spans_in_depth_first_order() { var outerContainer = new ContainerSpan( BackgroundColorSpan.Green(), new ContainerSpan( ForegroundColorSpan.Red(), new ContentSpan("the content"), ForegroundColorSpan.Reset()), BackgroundColorSpan.Reset()); var visitor = new RecordingSpanVisitor(); visitor.Visit(outerContainer); visitor.VisitedSpans .Select(s => s.GetType()) .Should() .BeEquivalentSequenceTo( typeof(ContainerSpan), typeof(BackgroundColorSpan), typeof(ContainerSpan), typeof(ForegroundColorSpan), typeof(ContentSpan), typeof(ForegroundColorSpan), typeof(BackgroundColorSpan)); }
public void A_ForegroundColorSpan_and_a_BackgroundColorSpan_having_the_same_name_do_not_have_the_same_hash_code() { var one = new ForegroundColorSpan("green", Ansi.Color.Foreground.Green); var two = new BackgroundColorSpan("green", Ansi.Color.Foreground.Green); one.GetHashCode().Should().NotBe(two.GetHashCode()); }
public void BackgroundColorSpans_with_equivalent_content_have_the_same_hash_code() { var one = new BackgroundColorSpan("green", Ansi.Color.Foreground.Green); var two = new BackgroundColorSpan("green", Ansi.Color.Foreground.Green); one.GetHashCode().Should().Be(two.GetHashCode()); }
public void BackgroundColorSpans_are_replaced_with_System_Console_calls_during_non_ANSI_rendering() { var span = _textSpanFormatter.ParseToSpan( $"{BackgroundColorSpan.Red()}red {BackgroundColorSpan.Blue()}blue {BackgroundColorSpan.Green()}green {BackgroundColorSpan.Reset()}or a {BackgroundColorSpan.Rgb(12, 34, 56)}little of each." ); var renderer = new ConsoleRenderer(_terminal, OutputMode.NonAnsi); renderer.RenderToRegion(span, new Region(0, 0, 200, 1, false)); _terminal.Events .Should() .BeEquivalentSequenceTo( new CursorPositionChanged(new Point(0, 0)), new BackgroundColorChanged(ConsoleColor.DarkRed), new ContentWritten("red "), new BackgroundColorChanged(ConsoleColor.DarkBlue), new ContentWritten("blue "), new BackgroundColorChanged(ConsoleColor.DarkGreen), new ContentWritten("green "), new ColorReset(), new ForegroundColorChanged(ConsoleColor.White), new ContentWritten("or a "), new ColorReset(), new ForegroundColorChanged(ConsoleColor.White), new ContentWritten("little of each.") ); }
public static ContainerSpan StyleHighlight(this string @string, BackgroundColorSpan color) { return(new ContainerSpan( color, new ContentSpan(@string), BackgroundColorSpan.Reset())); }
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); }
public void BackgroundColorSpans_with_the_same_name_are_equal() { var one = new BackgroundColorSpan("green", Ansi.Color.Foreground.Green); var two = new BackgroundColorSpan("green", Ansi.Color.Foreground.Green); one.Equals(two).Should().BeTrue(); one.Invoking(code => code.Equals(null)).Should().NotThrow <NullReferenceException>(); }
public void BackgroundColorSpans_are_removed_during_file_rendering() { var span = _spanFormatter.ParseToSpan( $"{BackgroundColorSpan.Red()}red {BackgroundColorSpan.Blue()}blue {BackgroundColorSpan.Green()}green {BackgroundColorSpan.Reset()}or a {BackgroundColorSpan.Rgb(12, 34, 56)}little of each."); var renderer = new ConsoleRenderer(_console, OutputMode.File); var expected = "red blue green or a little of each."; renderer.RenderToRegion(span, new Region(0, 0, expected.Length, 1, false)); _console.Out.ToString().Should().Be(expected); }
public async ValueTask DestroyProgressBar() { await context.Factory.Run(() => { ReportProgress(1.0); progress = null; WriteLine(new ContainerSpan( CursorControlSpan.Show(), ForegroundColorSpan.Reset(), BackgroundColorSpan.Reset())); }); }
public void BackgroundColorSpans_are_replaced_with_ANSI_codes_during_ANSI_rendering() { var span = _spanFormatter.ParseToSpan( $"{BackgroundColorSpan.Red()}red {BackgroundColorSpan.Blue()}blue {BackgroundColorSpan.Green()}green {BackgroundColorSpan.Reset()}or a {BackgroundColorSpan.Rgb(12, 34, 56)}little of each."); var renderer = new ConsoleRenderer(_console, OutputMode.Ansi); renderer.RenderToRegion(span, new Region(0, 0, 200, 1, false)); _console.Out .ToString() .Should() .Contain( $"{Ansi.Color.Background.Red.EscapeSequence}red {Ansi.Color.Background.Blue.EscapeSequence}blue {Ansi.Color.Background.Green.EscapeSequence}green {Ansi.Color.Background.Default.EscapeSequence}or a {Ansi.Color.Background.Rgb(12, 34, 56).EscapeSequence}little of each."); }
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); }
public void FormatSpans_do_not_have_default_string_representations() { $"{ForegroundColorSpan.DarkGray()}The {BackgroundColorSpan.Cyan()}quick{StyleSpan.BlinkOn()} brown fox jumped over the lazy dog.{StyleSpan.BoldOff()}{ForegroundColorSpan.Reset()}{BackgroundColorSpan.Reset()}" .Should() .Be("The quick brown fox jumped over the lazy dog."); }
public virtual void VisitBackgroundColorSpan(BackgroundColorSpan span) { }
public override void VisitBackgroundColorSpan(BackgroundColorSpan span) => VisitedSpans.Add(span);
public static void OutputFatal(this ITerminal terminal, string content) => terminal.OutputColor(BackgroundColorSpan.Red(), content);
public static void OutputColor(this ITerminal terminal, BackgroundColorSpan color, string content) { terminal.Render(color); terminal.Output(content); terminal.Render(BackgroundColorSpan.Reset()); }
private static void HandleFormatRun(ISpannable spannableString, IAttributedTextRun run) { var attributes = run.Attributes; var start = run.Start; var end = start + run.Length; var fontName = attributes.GetFontName(); if (fontName != null) { var typefaceSpan = new TypefaceSpan(fontName); spannableString.SetSpan(typefaceSpan, start, end, SpanTypes.ExclusiveExclusive); } if (attributes.GetBold() && attributes.GetItalic()) { var span = new StyleSpan(TypefaceStyle.BoldItalic); spannableString.SetSpan(span, start, end, SpanTypes.ExclusiveExclusive); } else if (attributes.GetBold()) { var span = new StyleSpan(TypefaceStyle.Bold); spannableString.SetSpan(span, start, end, SpanTypes.ExclusiveExclusive); } else if (attributes.GetItalic()) { var span = new StyleSpan(TypefaceStyle.Italic); spannableString.SetSpan(span, start, end, SpanTypes.ExclusiveExclusive); } if (attributes.GetUnderline()) { var span = new UnderlineSpan(); spannableString.SetSpan(span, start, end, SpanTypes.ExclusiveExclusive); } var foregroundColor = attributes.GetForegroundColor()?.ParseAsInts()?.ToColor(); if (foregroundColor != null) { var span = new ForegroundColorSpan((global::Android.Graphics.Color)foregroundColor); spannableString.SetSpan(span, start, end, SpanTypes.ExclusiveExclusive); } var backgroundColor = attributes.GetBackgroundColor()?.ParseAsInts()?.ToColor(); if (backgroundColor != null) { var span = new BackgroundColorSpan((global::Android.Graphics.Color)backgroundColor); spannableString.SetSpan(span, start, end, SpanTypes.ExclusiveExclusive); } if (attributes.GetSubscript()) { var span = new SubscriptSpan(); spannableString.SetSpan(span, start, end, SpanTypes.ExclusiveExclusive); } if (attributes.GetSuperscript()) { var span = new SuperscriptSpan(); spannableString.SetSpan(span, start, end, SpanTypes.ExclusiveExclusive); } if (attributes.GetStrikethrough()) { var span = new StrikethroughSpan(); spannableString.SetSpan(span, start, end, SpanTypes.ExclusiveExclusive); } if (attributes.GetUnorderedList()) { var bulletSpan = new BulletSpan(); spannableString.SetSpan(bulletSpan, start, end, SpanTypes.ExclusiveExclusive); } }