FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
with_restored_io.cpp
Go to the documentation of this file.
1// Copyright 2022 Arthur Sonzogni. Todos los derechos reservados.
2// El uso de este código fuente se rige por la licencia MIT que se puede encontrar en
3// el archivo 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 // Al presionar este botón, "screen.WithRestoredIO" desinstalará temporalmente
21 // el "hook" del terminal y ejecutará la función de "callback" proporcionada.
22 // Esto permite ejecutar la aplicación en un modo no interactivo.
23 auto btn_run = Button("Ejecutar con E/S restaurada", screen.WithRestoredIO([] {
24 std::cout << "Este es un programa hijo usando stdin/stdout." << std::endl;
25 for (int i = 0; i < 10; ++i) {
26 std::cout << "Por favor, introduce 10 cadenas (" << i << "/10)" << std::flush;
27 std::string input;
28 std::getline(std::cin, input);
29 }
30 }));
31
32 auto btn_quit = Button("Salir", 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 "Después de hacer clic en este botón, ScreenInteractive se "
42 "suspenderá y el acceso a stdin/stdout se restaurará temporalmente "
43 "para ejecutar una función.");
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
Element vbox(Elements children)
Un contenedor que muestra elementos verticalmente uno por uno.
Definition vbox.cpp:95
return dimx size(HEIGHT, EQUAL, dimy)
return hbox({ text(std::to_string(int(progress *100))+"% ")|size(WIDTH, EQUAL, 5), gauge(progress), })
El espacio de nombres ftxui:: de FTXUI.
Definition animation.hpp:10
int main()