FTXUI 6.1.9
C++ functional terminal UI.
Chargement...
Recherche...
Aucune correspondance
examples/component/input.cpp
Aller à la documentation de ce fichier.
1// Copyright 2020 Arthur Sonzogni. Tous droits réservés.
2// L'utilisation de ce code source est régie par la licence MIT que l'on peut trouver dans
3// le fichier 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 // Les données :
19 std::string first_name;
20 std::string last_name;
21 std::string password;
22 std::string phoneNumber;
23
24 // Les composants d'entrée de base :
25 Component input_first_name = Input(&first_name, "first name");
26 Component input_last_name = Input(&last_name, "last name");
27
28 // Le composant d'entrée du mot de passe :
29 InputOption password_option;
30 password_option.password = true;
31 Component input_password = Input(&password, "password", password_option);
32
33 // Le composant d'entrée du numéro de téléphone :
34 // Nous utilisons `CatchEvent` pour filtrer les caractères non numériques.
35 Component input_phone_number = Input(&phoneNumber, "phone number");
36 input_phone_number |= CatchEvent([&](Event event) {
37 return event.is_character() && !std::isdigit(event.character()[0]);
38 });
39 input_phone_number |= CatchEvent([&](Event event) {
40 return event.is_character() && phoneNumber.size() > 10;
41 });
42
43 // L'arbre des composants :
44 auto component = Container::Vertical({
45 input_first_name,
46 input_last_name,
47 input_password,
48 input_phone_number,
49 });
50
51 // Ajuster la façon dont l'arbre des composants est rendu :
52 auto renderer = Renderer(component, [&] {
53 return vbox({
54 hbox(text(" First name : "), input_first_name->Render()),
55 hbox(text(" Last name : "), input_last_name->Render()),
56 hbox(text(" Password : "), input_password->Render()),
57 hbox(text(" Phone num : "), input_phone_number->Render()),
58 separator(),
59 text("Hello " + first_name + " " + last_name),
60 text("Your password is " + password),
61 text("Your phone number is " + phoneNumber),
62 }) |
63 border;
64 });
65
66 auto screen = ScreenInteractive::TerminalOutput();
67 screen.Loop(renderer);
68}
auto screen
std::string character() const
Definition event.hpp:106
Ref< bool > password
Obscurcit le contenu de l'entrée en utilisant '*'.
Représente un événement. Il peut s'agir d'un événement de touche, d'un redimensionnement de terminal,...
Definition event.hpp:28
Option pour le composant Input.
L'espace de noms FTXUI ftxui::
Definition animation.hpp:10
std::shared_ptr< ComponentBase > Component