public void Should_Render_Status_Correctly() { // Given var console = new TestableAnsiConsole(ColorSystem.TrueColor, width: 10); var status = new Status(console); status.AutoRefresh = false; status.Spinner = new DummySpinner1(); // When status.Start("foo", ctx => { ctx.Refresh(); ctx.Spinner(new DummySpinner2()); ctx.Status("bar"); ctx.Refresh(); ctx.Spinner(new DummySpinner1()); ctx.Status("baz"); }); // Then console.Output .NormalizeLineEndings() .ShouldBe( "[?25l \n" + "[38;5;11m*[0m foo\n" + " [1A[1A \n" + "[38;5;11m-[0m bar\n" + " [1A[1A \n" + "[38;5;11m*[0m baz\n" + " [2K[1A[2K[1A[2K[?25h"); }
public void Should_Return_Correct_Code_For_Known_Color(bool foreground, string expected) { // Given var console = new TestableAnsiConsole(ColorSystem.Standard); // When console.Write("Hello", new Style().SetColor(Color.Olive, foreground)); // Then console.Output.ShouldBe(expected); }
public void Should_Estimate_TrueColor_To_Nearest_Eight_Bit_Color(bool foreground, string expected) { // Given var console = new TestableAnsiConsole(ColorSystem.EightBit); // When console.Write("Hello", new Style().SetColor(new Color(126, 127, 0), foreground)); // Then console.Output.ShouldBe(expected); }
public void Should_Return_Eight_Bit_Ansi_Code_For_Known_Colors(bool foreground, string expected) { // Given var console = new TestableAnsiConsole(ColorSystem.TrueColor); // When console.Write("Hello", new Style().SetColor(Color.Purple, foreground)); // Then console.Output.ShouldBe(expected); }
public void Should_Return_Correct_Code(bool foreground, string expected) { // Given var console = new TestableAnsiConsole(ColorSystem.TrueColor); // When console.Write("Hello", new Style().SetColor(new Color(128, 0, 128), foreground)); // Then console.Output.ShouldBe(expected); }
public void Should_Output_Expected_Ansi_For_Markup(string markup, string expected) { // Given var console = new TestableAnsiConsole(ColorSystem.Standard, AnsiSupport.Yes); // When console.Markup(markup); // Then console.Output.ShouldBe(expected); }
public void Should_Be_Able_To_Escape_Tags(string markup, string expected) { // Given var console = new TestableAnsiConsole(ColorSystem.Standard, AnsiSupport.Yes); // When console.Markup(markup); // Then console.Output.ShouldBe(expected); }
public void Should_Substitute_Emoji_Shortcodes_In_Markdown() { // Given var console = new TestableAnsiConsole(ColorSystem.Standard, AnsiSupport.Yes); // When console.Markup("Hello :globe_showing_europe_africa:!"); // Then console.Output.ShouldBe("Hello 🌍!"); }
public void Should_Write_Text_With_Multiple_Decorations_Correctly(Decoration decoration, string expected) { // Given var console = new TestableAnsiConsole(ColorSystem.TrueColor); // When console.Write("Hello World", Style.WithDecoration(decoration)); // Then console.Output.ShouldBe(expected); }
public void Should_Reset_Colors_Correctly_After_Line_Break_In_Text() { // Given var console = new TestableAnsiConsole(ColorSystem.Standard, AnsiSupport.Yes); // When console.WriteLine("Hello\nWorld", Style.WithBackground(ConsoleColor.Red)); // Then console.Output.NormalizeLineEndings() .ShouldBe("[101mHello[0m\n[101mWorld[0m\n"); }
public void Should_Throw_If_Encounters_Closing_Tag() { // Given var console = new TestableAnsiConsole(ColorSystem.Standard, AnsiSupport.Yes); // When var result = Record.Exception(() => console.Markup("Hello[/]World")); // Then result.ShouldBeOfType <InvalidOperationException>() .Message.ShouldBe("Encountered closing tag when none was expected near position 5."); }
public void Should_Throw_If_Tags_Are_Unbalanced() { // Given var console = new TestableAnsiConsole(ColorSystem.Standard, AnsiSupport.Yes); // When var result = Record.Exception(() => console.Markup("[yellow][blue]Hello[/]")); // Then result.ShouldBeOfType <InvalidOperationException>() .Message.ShouldBe("Unbalanced markup stack. Did you forget to close a tag?"); }
public void Should_Throw_If_Encounters_Malformed_Tag(string markup, string expected) { // Given var console = new TestableAnsiConsole(ColorSystem.Standard, AnsiSupport.Yes); // When var result = Record.Exception(() => console.Markup(markup)); // Then result.ShouldBeOfType <InvalidOperationException>() .Message.ShouldBe(expected); }
public void Should_Map_TrueColor_To_Nearest_Four_Bit_Color_If_Possible( bool foreground, byte r, byte g, byte b, string expected) { // Given var console = new TestableAnsiConsole(ColorSystem.Standard); // When console.Write("Hello", new Style().SetColor(new Color(r, g, b), foreground)); // Then console.Output.ShouldBe(expected); }
public void Should_Estimate_TrueColor_To_Nearest_Three_Bit_Color( bool foreground, byte r, byte g, byte b, string expected) { // Given var console = new TestableAnsiConsole(ColorSystem.Legacy); // When console.Write("Hello", new Style().SetColor(new Color(r, g, b), foreground)); // Then console.Output.ShouldBe(expected); }
public void Should_Combine_Decoration_And_Colors() { // Given var console = new TestableAnsiConsole(ColorSystem.Standard); // When console.Write( "Hello", Style.WithForeground(Color.RoyalBlue1) .WithBackground(Color.NavajoWhite1) .WithDecoration(Decoration.Italic)); // Then console.Output.ShouldBe("\u001b[3;90;47mHello\u001b[0m"); }
public void Should_Not_Include_Decoration_If_Set_To_None() { // Given var console = new TestableAnsiConsole(ColorSystem.Standard); // When console.Write( "Hello", Style.WithForeground(Color.RoyalBlue1) .WithBackground(Color.NavajoWhite1) .WithDecoration(Decoration.None)); // Then console.Output.ShouldBe("\u001b[90;47mHello\u001b[0m"); }
public void Should_Not_Include_Background_If_Set_To_Default_Color() { // Given var console = new TestableAnsiConsole(ColorSystem.Standard); // When console.Write( "Hello", Style.WithForeground(Color.RoyalBlue1) .WithBackground(Color.Default) .WithDecoration(Decoration.Italic)); // Then console.Output.ShouldBe("\u001b[3;90mHello\u001b[0m"); }
public void Should_Not_Include_Foreground_If_Set_To_Default_Color() { // Given var console = new TestableAnsiConsole(ColorSystem.Standard); // When console.Write( "Hello", new Style() .Foreground(Color.Default) .Background(Color.NavajoWhite1) .Decoration(Decoration.Italic)); // Then console.Output.ShouldBe("\u001b[3;47mHello\u001b[0m"); }
public void Should_Not_Auto_Clear_If_Specified() { // Given var console = new TestableAnsiConsole(ColorSystem.TrueColor, width: 10); var progress = new Progress(console) .Columns(new[] { new ProgressBarColumn() }) .AutoRefresh(false) .AutoClear(false); // When progress.Start(ctx => ctx.AddTask("foo")); // Then console.Output .NormalizeLineEndings() .ShouldBe( "[?25l" + // Hide cursor " \n" + // Top padding "[38;5;8m━━━━━━━━━━[0m\n" + // Task " \n" + // Bottom padding "[?25h"); // show cursor }