diff --git a/ftxui/include/ftxui/component/screen_interactive.hpp b/ftxui/include/ftxui/component/screen_interactive.hpp index 5a45348..ac56a9c 100644 --- a/ftxui/include/ftxui/component/screen_interactive.hpp +++ b/ftxui/include/ftxui/component/screen_interactive.hpp @@ -25,8 +25,7 @@ class ScreenInteractive : public ftxui::screen::Screen { class Delegate; std::unique_ptr delegate_; - void Clear(); - void Draw(); + void PrepareDraw(); bool quit_ = false; enum class Dimension { diff --git a/ftxui/src/ftxui/component/screen_interactive.cpp b/ftxui/src/ftxui/component/screen_interactive.cpp index 7111e23..d964ff9 100644 --- a/ftxui/src/ftxui/component/screen_interactive.cpp +++ b/ftxui/src/ftxui/component/screen_interactive.cpp @@ -127,21 +127,20 @@ void ScreenInteractive::Loop() { terminal_configuration_new.c_lflag &= ~ECHO; tcsetattr(STDIN_FILENO, TCSANOW, &terminal_configuration_new); - Draw(); + std::string reset_position; while (!quit_) { - delegate_->OnEvent(GetEvent()); + PrepareDraw(); + std::cout << reset_position << ToString() << std::flush; + reset_position = ResetPosition(); Clear(); - Draw(); + delegate_->OnEvent(GetEvent()); } - while (!quit_) - ; - // std::cout << std::endl; // Restore the old terminal configuration. tcsetattr(STDIN_FILENO, TCSANOW, &terminal_configuration_old); } -void ScreenInteractive::Draw() { +void ScreenInteractive::PrepareDraw() { auto document = delegate_->component()->Render(); size_t dimx; size_t dimy; @@ -168,12 +167,6 @@ void ScreenInteractive::Draw() { } Render(*this, document.get()); - std::cout << ToString() << std::flush; -} - -void ScreenInteractive::Clear() { - std::cout << ResetPosition(); - Screen::Clear(); } component::Delegate* ScreenInteractive::delegate() { diff --git a/ftxui/src/ftxui/dom/vbox.cpp b/ftxui/src/ftxui/dom/vbox.cpp index 1ad9896..ab2e2b7 100644 --- a/ftxui/src/ftxui/dom/vbox.cpp +++ b/ftxui/src/ftxui/dom/vbox.cpp @@ -51,7 +51,7 @@ class VBox : public Node { remaining_flex -= child->requirement().flex.y; child_box.bottom += added_space; } - child_box.bottom = std::min(child_box.bottom, box.bottom-1); + child_box.bottom = std::min(child_box.bottom, box.bottom); child->SetBox(child_box); y = child_box.bottom + 1; diff --git a/ftxui/src/ftxui/screen/screen.cpp b/ftxui/src/ftxui/screen/screen.cpp index 3c5abd9..da8c68a 100644 --- a/ftxui/src/ftxui/screen/screen.cpp +++ b/ftxui/src/ftxui/screen/screen.cpp @@ -56,17 +56,18 @@ std::string Screen::ToString() { Pixel previous_pixel; for (size_t y = 0; y < dimy_; ++y) { + if (y != 0) + ss << '\n'; for (size_t x = 0; x < dimx_; ++x) { UpdatePixelStyle(ss, previous_pixel, pixels_[y][x]); ss << pixels_[y][x].character; } - if (y + 1 < dimy_) - ss << '\n'; - Pixel final_pixel; - UpdatePixelStyle(ss, previous_pixel, final_pixel); } + Pixel final_pixel; + UpdatePixelStyle(ss, previous_pixel, final_pixel); + return to_string(ss.str()); } @@ -93,10 +94,10 @@ Screen Screen::TerminalOutput(std::unique_ptr& element) { std::string Screen::ResetPosition() { std::stringstream ss; + //ss << '\r'; for (size_t y = 1; y < dimy_; ++y) { ss << "\e[2K\r\e[1A"; } - ss << '\r'; return ss.str(); }