FTXUI 6.1.9
C++ functional terminal UI.
Chargement...
Recherche...
Aucune correspondance
with_restored_io.cpp
Aller à la documentation de ce fichier.
1// Copyright 2022 Arthur Sonzogni. Tous droits réservés.
2// L'utilisation de ce code source est régie par la licence MIT qui se trouve
3// dans le fichier LICENSE.
4#include <cstdlib> // for system, EXIT_SUCCESS
5#include <iostream> // for operator<<, basic_ostream, basic_ostream::operator<<, cout, endl, flush, ostream, basic_ostream<>::__ostream_type, cin
6#include <memory> // for shared_ptr, __shared_ptr_access, allocator
7#include <string> // for getline, string
8
9#include "ftxui/component/captured_mouse.hpp" // for ftxui
10#include "ftxui/component/component.hpp" // for Button, Horizontal, Renderer
11#include "ftxui/component/component_base.hpp" // for ComponentBase
12#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
13#include "ftxui/dom/elements.hpp" // for operator|, filler, Element, borderEmpty, hbox, size, paragraph, vbox, LESS_THAN, border, center, HEIGHT, WIDTH
14
15int main() {
16 using namespace ftxui;
17
18 auto screen = ScreenInteractive::Fullscreen();
19
20 // En appuyant sur ce bouton, "screen.WithRestoredIO" désinstallera
21 // temporairement le hook du terminal et exécutera la fonction de rappel
22 // fournie. Cela permet d'exécuter l'application en mode non interactif.
23 auto btn_run = Button("Execute with restored IO", screen.WithRestoredIO([] {
24 std::cout << "This is a child program using stdin/stdout." << std::endl;
25 for (int i = 0; i < 10; ++i) {
26 std::cout << "Please enter 10 strings (" << i << "/10)" << std::flush;
27 std::string input;
28 std::getline(std::cin, input);
29 }
30 }));
31
32 auto btn_quit = Button("Quit", screen.ExitLoopClosure());
33
34 auto layout = Container::Horizontal({
35 btn_run,
36 btn_quit,
37 });
38
39 auto renderer = Renderer(layout, [&] {
40 auto explanation = paragraph(
41 "Après avoir cliqué sur ce bouton, le ScreenInteractive sera "
42 "suspendu et l'accès à stdin/stdout sera temporairement "
43 "restauré pour l'exécution d'une fonction.");
44 auto element = vbox({
45 explanation | borderEmpty,
46 hbox({
47 btn_run->Render(),
48 filler(),
49 btn_quit->Render(),
50 }),
51 });
52
53 element = element | borderEmpty | border | size(WIDTH, LESS_THAN, 80) |
54 size(HEIGHT, LESS_THAN, 20) | center;
55 return element;
56 });
57
58 screen.Loop(renderer);
59 return EXIT_SUCCESS;
60}
auto screen
L'espace de noms FTXUI ftxui::
Definition animation.hpp:10
int main()