ArthurSonzogni / FTXUI

:computer: C++ Functional Terminal User Interface. :heart:
MIT License
6.64k stars 399 forks source link

Resizing not working on Windows Terminal, Powershell and CMD #50

Closed s1nisteR closed 3 years ago

s1nisteR commented 3 years ago
Element document =
        hbox({
           text(L"|") | border, text(L"Welcome To Axzil V1.0") | color(Color::BlueViolet) | border | flex, text(L"|") | border
        });

auto screen = Screen::Create(
        Dimension::Full(),
        Dimension::Fit(document)
        );
Render(screen, document);
std::cout << screen.ToString() << std::endl;

Basic example code, when resizing turns into garbled text. Is there already a fix for it or am I doing something wrong?

ArthurSonzogni commented 3 years ago

Once the text has been printed on the screen, it is printed. Then if the terminal is resized, the previous lines might be wrapped by the terminal emulator.

Maybe you want to use the ftxui/component/ objects. You can display a component that will render itself after every events (key pressed, terminal resized, ...)

I would suggest using ScreenInteractive::Fullscreen() if you want no issues with line wrapping at all.

You can try the examples:

where it uses ScreenInteractive::Fullscreen();

class MyComponent : public Component {
 public:
  MyComponent() = default;
  ~MyComponent() final = default;

  Element Render() override {
    return hbox({
        text(L"|") | border,
        text(L"Welcome To Axzil V1.0") | color(Color::BlueViolet) | border |
            flex,
        text(L"|") | border,
    });
  }
};

int main(int argc, const char* argv[]) {
  auto screen = ScreenInteractive::Fullscreen();

  MyComponent component;
  screen.Loop(&component);

  return 0;
}

(I haven't tried this code)