ArthurSonzogni / FTXUI

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

[Question] Is it possible to "suspend" FTXUI component from writting to stdout #301

Closed vnepogodin closed 2 years ago

vnepogodin commented 2 years ago

Is it possible to " suspend" FTXUI component from writting to stdout. And " resume" after child process is done.

For example: I want to execute bash interactively(so I need to block FTXUI from writting to the input stream), and after exit, unlock FTXUI

ArthurSonzogni commented 2 years ago

Yes kind of...

I would do:


auto screen = ScreenInteractive::Fullscreen()
auto exit_loop = screen.ExitClosure(); // Movable and thread safe function.

auto component = CreateMyComponent(exit_loop);

while(true) {
  screen.Loop(component);
  execute_bash_interactively()
}

And someone somewhere call:

exit_loop();

Alternatively, it could be possible to expose and call: https://github.com/ArthurSonzogni/FTXUI/blob/84299de2e11522ad1d531a50f7610678ae0e5e67/include/ftxui/component/screen_interactive.hpp#L35-L36 while inside the loop, but I am not sure without giving it more thoughts.

vnepogodin commented 2 years ago

Thanks! I'll expose those functions. And try if it helps.

exit_loop will not help me as I spawn component from another component and if I execute execute_bash_interactively it will just ignore it

vnepogodin commented 2 years ago

@ArthurSonzogn, thanks again! It worked. Should I create PR with example?

ArthurSonzogni commented 2 years ago

Great! Yes, you can submit a PR. I will have to work a bit on top of your change if I want to merge it. I will add example.

vnepogodin commented 2 years ago

Great! Yes, you can submit a PR. I will have to work a bit on top of your change if I want to merge it. I will add example.

Ok I did submit a PR with example.