FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
examples/component/input.cpp
Go to the documentation of this file.
1// Copyright 2020 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 <memory> // for allocator, __shared_ptr_access
5#include <string> // for char_traits, operator+, string, basic_string
6
7#include "ftxui/component/captured_mouse.hpp" // for ftxui
8#include "ftxui/component/component.hpp" // for Input, Renderer, Vertical
9#include "ftxui/component/component_base.hpp" // for ComponentBase
10#include "ftxui/component/component_options.hpp" // for InputOption
11#include "ftxui/component/screen_interactive.hpp" // for Component, ScreenInteractive
12#include "ftxui/dom/elements.hpp" // for text, hbox, separator, Element, operator|, vbox, border
13#include "ftxui/util/ref.hpp" // for Ref
14
15int main() {
16 using namespace ftxui;
17
18 // Los datos:
19 std::string first_name;
20 std::string last_name;
21 std::string password;
22 std::string phoneNumber;
23
24 // Los componentes básicos de entrada:
25 Component input_first_name = Input(&first_name, "first name");
26 Component input_last_name = Input(&last_name, "last name");
27
28 // El componente de entrada de contraseña:
29 InputOption password_option;
30 password_option.password = true;
31 Component input_password = Input(&password, "password", password_option);
32
33 // El componente de entrada de número de teléfono:
34 // Estamos usando `CatchEvent` para filtrar caracteres no numéricos. Component input_phone_number = Input(&phoneNumber, "phone number");
35 input_phone_number |= CatchEvent([&](Event event) {
36 return event.is_character() && !std::isdigit(event.character()[0]);
37 });
38 input_phone_number |= CatchEvent([&](Event event) {
39 return event.is_character() && phoneNumber.size() > 10;
40 });
41
42 // El árbol de componentes:
43 auto component = Container::Vertical({
44 input_first_name,
45 input_last_name,
46 input_password,
47 input_phone_number,
48 });
49
50 // Ajustar cómo se renderiza el árbol de componentes:
51 auto renderer = Renderer(component, [&] {
52 return vbox({
53 hbox(text(" First name : "), input_first_name->Render()),
54 hbox(text(" Last name : "), input_last_name->Render()),
55 hbox(text(" Password : "), input_password->Render()),
56 hbox(text(" Phone num : "), input_phone_number->Render()),
57 separator(),
58 text("Hello " + first_name + " " + last_name),
59 text("Your password is " + password),
60 text("Your phone number is " + phoneNumber),
61 }) |
62 border;
63 });
64
65 auto screen = ScreenInteractive::TerminalOutput();
66 screen.Loop(renderer);
67}
auto screen
std::string character() const
Definition event.hpp:107
Ref< bool > password
Oscurece el contenido del input usando '*'.
Representa un evento. Puede ser un evento de pulsación de tecla, un redimensionamiento de terminal,...
Definition event.hpp:29
Opción para el componente Input.
Element vbox(Elements children)
Un contenedor que muestra elementos verticalmente uno por uno.
Definition vbox.cpp:95
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
std::shared_ptr< ComponentBase > Component