Example #1
0
        public void Should_Hide_Completed_Tasks()
        {
            // Given
            var taskFinished    = default(ProgressTask);
            var taskInProgress1 = default(ProgressTask);
            var taskInProgress2 = default(ProgressTask);
            var console         = new FakeAnsiConsole(ColorSystem.TrueColor, width: 10);

            var progress = new Progress(console)
                           .Columns(new[] { new ProgressBarColumn() })
                           .AutoRefresh(false)
                           .AutoClear(false)
                           .HideCompleted(true);

            // When
            progress.Start(ctx =>
            {
                taskInProgress1 = ctx.AddTask("foo");
                taskFinished    = ctx.AddTask("bar");
                taskInProgress2 = ctx.AddTask("baz");
                taskInProgress2.Increment(20);
                taskFinished.Value = taskFinished.MaxValue;
            });

            // Then
            console.Output
            .NormalizeLineEndings()
            .ShouldBe(
                "[?25l" +                                  // Hide cursor
                "          \n" +                            // top padding
                "━━━━━━━━━━\n" +               // taskInProgress1
                "━━━━━━━━━━\n" + // taskInProgress2
                "          \n" +                            // bottom padding
                "[?25h");                                  // show cursor
        }
Example #2
0
        public void Should_Render_Status_Correctly()
        {
            // Given
            var console = new FakeAnsiConsole(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" +
                "* foo\n" +
                "          \n" +
                "- bar\n" +
                "          \n" +
                "* baz\n" +
                "     [?25h");
        }
            public void Unknown_emojis_should_remain()
            {
                // Given
                var console = new FakeAnsiConsole(ColorSystem.Standard, AnsiSupport.Yes);

                // When
                console.Markup("Hello :globe_showing_flat_earth:!");

                // Then
                console.Output.ShouldBe("Hello :globe_showing_flat_earth:!");
            }
            public void Should_Leave_Single_Colons()
            {
                // Given
                var console = new FakeAnsiConsole(ColorSystem.Standard, AnsiSupport.Yes);

                // When
                console.Markup("Hello :globe_showing_europe_africa:! Output: good");

                // Then
                console.Output.ShouldBe("Hello 🌍! Output: good");
            }
            public void Can_Handle_Different_Combinations(string markup, string expected)
            {
                // Given
                var console = new FakeAnsiConsole(ColorSystem.Standard, AnsiSupport.Yes);

                // When
                console.Markup(markup);

                // Then
                console.Output.ShouldBe(expected);
            }
        public void Should_Write_Text_With_Multiple_Decorations_Correctly(Decoration decoration, string expected)
        {
            // Given
            var console = new FakeAnsiConsole(ColorSystem.TrueColor);

            // When
            console.Write("Hello World", new Style().Decoration(decoration));

            // Then
            console.Output.ShouldBe(expected);
        }
Example #7
0
            public void Should_Be_Able_To_Escape_Tags(string markup, string expected)
            {
                // Given
                var console = new FakeAnsiConsole(ColorSystem.Standard, AnsiSupport.Yes);

                // When
                console.Markup(markup);

                // Then
                console.Output.ShouldBe(expected);
            }
Example #8
0
            public void Should_Return_Eight_Bit_Ansi_Code_For_Known_Colors(bool foreground, string expected)
            {
                // Given
                var console = new FakeAnsiConsole(ColorSystem.TrueColor);

                // When
                console.Write("Hello", new Style().SetColor(Color.Purple, foreground));

                // Then
                console.Output.ShouldBe(expected);
            }
Example #9
0
            public void Should_Return_Correct_Code(bool foreground, string expected)
            {
                // Given
                var console = new FakeAnsiConsole(ColorSystem.TrueColor);

                // When
                console.Write("Hello", new Style().SetColor(new Color(128, 0, 128), foreground));

                // Then
                console.Output.ShouldBe(expected);
            }
Example #10
0
        public void Should_Substitute_Emoji_Shortcodes_In_Markdown()
        {
            // Given
            var console = new FakeAnsiConsole(ColorSystem.Standard, AnsiSupport.Yes);

            // When
            console.Markup("Hello :globe_showing_europe_africa:!");

            // Then
            console.Output.ShouldBe("Hello 🌍!");
        }
Example #11
0
            public void Should_Output_Expected_Ansi_For_Markup(string markup, string expected)
            {
                // Given
                var console = new FakeAnsiConsole(ColorSystem.Standard, AnsiSupport.Yes);

                // When
                console.Markup(markup);

                // Then
                console.Output.ShouldBe(expected);
            }
Example #12
0
            public void Should_Estimate_TrueColor_To_Nearest_Eight_Bit_Color(bool foreground, string expected)
            {
                // Given
                var console = new FakeAnsiConsole(ColorSystem.EightBit);

                // When
                console.Write("Hello", new Style().SetColor(new Color(126, 127, 0), foreground));

                // Then
                console.Output.ShouldBe(expected);
            }
Example #13
0
            public void Should_Output_Expected_Ansi_For_Link_With_Only_Url()
            {
                // Given
                var console = new FakeAnsiConsole(ColorSystem.Standard, AnsiSupport.Yes);

                // When
                console.Markup("[link]https://patriksvensson.se[/]");

                // Then
                console.Output.ShouldMatch("]8;id=[0-9]*;https:\\/\\/patriksvensson\\.se\\\\https:\\/\\/patriksvensson\\.se]8;;\\\\");
            }
Example #14
0
            public void Should_Return_Correct_Code_For_Known_Color(bool foreground, string expected)
            {
                // Given
                var console = new FakeAnsiConsole(ColorSystem.EightBit);

                // When
                console.Write("Hello", new Style().SetColor(Color.Olive, foreground));

                // Then
                console.Output.ShouldBe(expected);
            }
Example #15
0
        public void Should_not_fail_with_brackets_on_calls_without_args()
        {
            // Given
            var console = new FakeAnsiConsole(ColorSystem.Standard, AnsiSupport.Yes);

            // When
            console.MarkupLine("{");

            // Then
            console.Output.NormalizeLineEndings()
            .ShouldBe("{\n");
        }
Example #16
0
            public void Should_Throw_If_Tags_Are_Unbalanced()
            {
                // Given
                var console = new FakeAnsiConsole(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?");
            }
Example #17
0
            public void Should_Throw_If_Encounters_Closing_Tag()
            {
                // Given
                var console = new FakeAnsiConsole(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 async Task Should_Render_Correct_Ansi()
        {
            // Given
            var console = new FakeAnsiConsole(ColorSystem.EightBit, width: 80);
            var chart   = Fixture.GetChart().Width(60).FullSize();

            // When
            console.Render(chart);

            // Then
            await Verifier.Verify(console.Output);
        }
            public void Should_Reset_Colors_Correctly_After_Line_Break_In_Text()
            {
                // Given
                var console = new FakeAnsiConsole(ColorSystem.Standard, AnsiSupport.Yes);

                // When
                console.WriteLine("Hello\nWorld", new Style().Background(ConsoleColor.Red));

                // Then
                console.Output.NormalizeLineEndings()
                .ShouldBe("Hello\nWorld\n");
            }
Example #20
0
            public void Should_Throw_If_Encounters_Malformed_Tag(string markup, string expected)
            {
                // Given
                var console = new FakeAnsiConsole(ColorSystem.Standard, AnsiSupport.Yes);

                // When
                var result = Record.Exception(() => console.Markup(markup));

                // Then
                result.ShouldBeOfType <InvalidOperationException>()
                .Message.ShouldBe(expected);
            }
Example #21
0
                public void Should_Return_Correct_Ansi_Code(CursorDirection direction, string expected)
                {
                    // Given
                    var console = new FakeAnsiConsole(ColorSystem.Standard, AnsiSupport.Yes);

                    // When
                    console.Write("Hello");
                    console.Cursor.Move(direction, 2);
                    console.Write("World");

                    // Then
                    console.Output.ShouldBe(expected);
                }
        public void Should_Clear_Screen(bool home, string expected)
        {
            // Given
            var console = new FakeAnsiConsole(ColorSystem.Standard);

            // When
            console.Write("Hello");
            console.Clear(home);
            console.Write("World");

            // Then
            console.Output.ShouldBe(expected);
        }
Example #23
0
                public void Should_Return_Correct_Ansi_Code()
                {
                    // Given
                    var console = new FakeAnsiConsole(ColorSystem.Standard, AnsiSupport.Yes);

                    // When
                    console.Write("Hello");
                    console.Cursor.SetPosition(5, 3);
                    console.Write("World");

                    // Then
                    console.Output.ShouldBe("HelloWorld");
                }
Example #24
0
        public async Task Simple_Measure()
        {
            // Given
            var console = new FakeAnsiConsole(ColorSystem.Standard);
            var panel   = new Panel(new Canvas(width: 2, height: 2)
                                    .SetPixel(0, 0, Color.Aqua)
                                    .SetPixel(1, 1, Color.Grey));

            // When
            console.Render(panel);

            // Then
            await Verifier.Verify(console.Output);
        }
Example #25
0
            public void Should_Estimate_TrueColor_To_Nearest_Three_Bit_Color(
                bool foreground,
                byte r, byte g, byte b,
                string expected)
            {
                // Given
                var console = new FakeAnsiConsole(ColorSystem.Legacy);

                // When
                console.Write("Hello", new Style().SetColor(new Color(r, g, b), foreground));

                // Then
                console.Output.ShouldBe(expected);
            }
Example #26
0
            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 FakeAnsiConsole(ColorSystem.Standard);

                // When
                console.Write("Hello", new Style().SetColor(new Color(r, g, b), foreground));

                // Then
                console.Output.ShouldBe(expected);
            }
Example #27
0
        public void Should_Not_Render_Canvas_If_Canvas_Cannot_Be_Scaled_Down()
        {
            // Given
            var console = new FakeAnsiConsole(ColorSystem.Standard, width: 10);
            var canvas  = new Canvas(width: 20, height: 2);

            canvas.SetPixel(0, 0, Color.Aqua);
            canvas.SetPixel(19, 1, Color.Grey);

            // When
            console.Render(canvas);

            // Then
            console.Output.ShouldBeEmpty();
        }
Example #28
0
        public async Task Should_Scale_Down_Canvas_Is_Bigger_Than_Terminal()
        {
            // Given
            var console = new FakeAnsiConsole(ColorSystem.Standard, width: 10);
            var canvas  = new Canvas(width: 20, height: 10);

            canvas.SetPixel(0, 0, Color.Aqua);
            canvas.SetPixel(19, 9, Color.Grey);

            // When
            console.Render(canvas);

            // Then
            await Verifier.Verify(console.Output);
        }
        public void Should_Not_Include_Background_If_Set_To_Default_Color()
        {
            // Given
            var console = new FakeAnsiConsole(ColorSystem.Standard);

            // When
            console.Write(
                "Hello",
                new Style()
                .Foreground(Color.RoyalBlue1)
                .Background(Color.Default)
                .Decoration(Decoration.Italic));

            // Then
            console.Output.ShouldBe("\u001b[3;90mHello\u001b[0m");
        }
        public void Should_Not_Include_Decoration_If_Set_To_None()
        {
            // Given
            var console = new FakeAnsiConsole(ColorSystem.Standard);

            // When
            console.Write(
                "Hello",
                new Style()
                .Foreground(Color.RoyalBlue1)
                .Background(Color.NavajoWhite1)
                .Decoration(Decoration.None));

            // Then
            console.Output.ShouldBe("\u001b[90;47mHello\u001b[0m");
        }