From e4c5c7b43b1d03e32e29e9b168286897f0e1cdbf Mon Sep 17 00:00:00 2001 From: ArthurSonzogni Date: Thu, 28 Apr 2022 11:03:39 +0200 Subject: [PATCH] Fix ButtonTest.Animate --- src/ftxui/component/button_test.cpp | 69 ++++++++++++++++------------- 1 file changed, 38 insertions(+), 31 deletions(-) diff --git a/src/ftxui/component/button_test.cpp b/src/ftxui/component/button_test.cpp index a2e35f1..e4c770c 100644 --- a/src/ftxui/component/button_test.cpp +++ b/src/ftxui/component/button_test.cpp @@ -94,6 +94,7 @@ TEST(ButtonTest, Basic) { } TEST(ButtonTest, Animation) { + Terminal::SetColorSupport(Terminal::Color::TrueColor); int press_count = 0; std::string last_press = ""; auto option = ButtonOption::Animated(); @@ -123,23 +124,23 @@ TEST(ButtonTest, Animation) { { Screen screen(12, 3); Render(screen, container->Render()); - EXPECT_EQ( - screen.ToString(), - "\x1B[1m\x1B[38;5;250m\x1B[48;5;16m \x1B[22m " - "\x1B[39m\x1B[49m\r\n\x1B[1m\x1B[38;5;250m\x1B[48;5;16m btn1 \x1B[22m " - "btn2 \x1B[39m\x1B[49m\r\n\x1B[1m\x1B[38;5;250m\x1B[48;5;16m " - "\x1B[22m \x1B[39m\x1B[49m"); + EXPECT_EQ(screen.ToString(), + "\x1B[1m\x1B[38;2;192;192;192m\x1B[48;2;0;0;0m \x1B[22m " + " \x1B[39m\x1B[49m\r\n\x1B[1m\x1B[38;2;192;192;192m\x1B[48;2;0;0;" + "0m btn1 \x1B[22m btn2 " + "\x1B[39m\x1B[49m\r\n\x1B[1m\x1B[38;2;192;192;192m\x1B[48;2;0;0;" + "0m \x1B[22m \x1B[39m\x1B[49m"); } selected = 1; { Screen screen(12, 3); Render(screen, container->Render()); - EXPECT_EQ( - screen.ToString(), - "\x1B[38;5;250m\x1B[48;5;16m \x1B[1m " - "\x1B[22m\x1B[39m\x1B[49m\r\n\x1B[38;5;250m\x1B[48;5;16m btn1 \x1B[1m " - "btn2 \x1B[22m\x1B[39m\x1B[49m\r\n\x1B[38;5;250m\x1B[48;5;16m " - "\x1B[1m \x1B[22m\x1B[39m\x1B[49m"); + EXPECT_EQ(screen.ToString(), + "\x1B[38;2;192;192;192m\x1B[48;2;0;0;0m \x1B[1m " + "\x1B[22m\x1B[39m\x1B[49m\r\n\x1B[38;2;192;192;192m\x1B[48;2;0;0;" + "0m btn1 \x1B[1m btn2 " + "\x1B[22m\x1B[39m\x1B[49m\r\n\x1B[38;2;192;192;192m\x1B[48;2;0;0;" + "0m \x1B[1m \x1B[22m\x1B[39m\x1B[49m"); } animation::Params params(2s); container->OnAnimation(params); @@ -148,11 +149,13 @@ TEST(ButtonTest, Animation) { Render(screen, container->Render()); EXPECT_EQ( screen.ToString(), - "\x1B[38;5;250m\x1B[48;5;16m \x1B[1m\x1B[38;5;231m\x1B[48;5;244m " - " \x1B[22m\x1B[39m\x1B[49m\r\n\x1B[38;5;250m\x1B[48;5;16m btn1 " - "\x1B[1m\x1B[38;5;231m\x1B[48;5;244m btn2 " - "\x1B[22m\x1B[39m\x1B[49m\r\n\x1B[38;5;250m\x1B[48;5;16m " - "\x1B[1m\x1B[38;5;231m\x1B[48;5;244m \x1B[22m\x1B[39m\x1B[49m"); + "\x1B[38;2;192;192;192m\x1B[48;2;0;0;0m " + "\x1B[1m\x1B[38;2;255;255;255m\x1B[48;2;128;128;128m " + "\x1B[22m\x1B[39m\x1B[49m\r\n\x1B[38;2;192;192;192m\x1B[48;2;0;0;0m " + "btn1 \x1B[1m\x1B[38;2;255;255;255m\x1B[48;2;128;128;128m btn2 " + "\x1B[22m\x1B[39m\x1B[49m\r\n\x1B[38;2;192;192;192m\x1B[48;2;0;0;0m " + " \x1B[1m\x1B[38;2;255;255;255m\x1B[48;2;128;128;128m " + "\x1B[22m\x1B[39m\x1B[49m"); } EXPECT_EQ(selected, 1); container->OnEvent(MousePressed(3, 1)); @@ -160,25 +163,29 @@ TEST(ButtonTest, Animation) { { Screen screen(12, 3); Render(screen, container->Render()); - EXPECT_EQ(screen.ToString(), - "\x1B[1m\x1B[38;5;253m\x1B[48;5;238m " - "\x1B[22m\x1B[38;5;231m\x1B[48;5;244m " - "\x1B[39m\x1B[49m\r\n\x1B[1m\x1B[38;5;253m\x1B[48;5;238m btn1 " - "\x1B[22m\x1B[38;5;231m\x1B[48;5;244m btn2 " - "\x1B[39m\x1B[49m\r\n\x1B[1m\x1B[38;5;253m\x1B[48;5;238m " - "\x1B[22m\x1B[38;5;231m\x1B[48;5;244m \x1B[39m\x1B[49m"); + EXPECT_EQ( + screen.ToString(), + "\x1B[1m\x1B[38;2;223;223;223m\x1B[48;2;64;64;64m " + "\x1B[22m\x1B[38;2;255;255;255m\x1B[48;2;128;128;128m " + "\x1B[39m\x1B[49m\r\n\x1B[1m\x1B[38;2;223;223;223m\x1B[48;2;64;64;64m " + "btn1 \x1B[22m\x1B[38;2;255;255;255m\x1B[48;2;128;128;128m btn2 " + "\x1B[39m\x1B[49m\r\n\x1B[1m\x1B[38;2;223;223;223m\x1B[48;2;64;64;64m " + " \x1B[22m\x1B[38;2;255;255;255m\x1B[48;2;128;128;128m " + "\x1B[39m\x1B[49m"); } container->OnAnimation(params); { Screen screen(12, 3); Render(screen, container->Render()); - EXPECT_EQ(screen.ToString(), - "\x1B[1m\x1B[38;5;231m\x1B[48;5;244m " - "\x1B[22m\x1B[38;5;250m\x1B[48;5;16m " - "\x1B[39m\x1B[49m\r\n\x1B[1m\x1B[38;5;231m\x1B[48;5;244m btn1 " - "\x1B[22m\x1B[38;5;250m\x1B[48;5;16m btn2 " - "\x1B[39m\x1B[49m\r\n\x1B[1m\x1B[38;5;231m\x1B[48;5;244m " - "\x1B[22m\x1B[38;5;250m\x1B[48;5;16m \x1B[39m\x1B[49m"); + EXPECT_EQ( + screen.ToString(), + "\x1B[1m\x1B[38;2;255;255;255m\x1B[48;2;128;128;128m " + "\x1B[22m\x1B[38;2;192;192;192m\x1B[48;2;0;0;0m " + "\x1B[39m\x1B[49m\r\n\x1B[1m\x1B[38;2;255;255;255m\x1B[48;2;128;128;" + "128m btn1 \x1B[22m\x1B[38;2;192;192;192m\x1B[48;2;0;0;0m btn2 " + "\x1B[39m\x1B[49m\r\n\x1B[1m\x1B[38;2;255;255;255m\x1B[48;2;128;128;" + "128m \x1B[22m\x1B[38;2;192;192;192m\x1B[48;2;0;0;0m " + "\x1B[39m\x1B[49m"); } }