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. All rights reserved.
2// このソースコードの使用は、LICENSEファイルにあるMITライセンスに準拠しています。
3#include <memory> // for allocator, __shared_ptr_access
4#include <string> // for char_traits, operator+, string, basic_string
5
6#include "ftxui/component/captured_mouse.hpp" // for ftxui
7#include "ftxui/component/component.hpp" // for Input, Renderer, Vertical
8#include "ftxui/component/component_base.hpp" // for ComponentBase
9#include "ftxui/component/component_options.hpp" // for InputOption
10#include "ftxui/component/screen_interactive.hpp" // for Component, ScreenInteractive
11#include "ftxui/dom/elements.hpp" // for text, hbox, separator, Element, operator|, vbox, border
12#include "ftxui/util/ref.hpp" // for Ref
13
14int main() {
15 using namespace ftxui;
16
17 // データ:
18 std::string first_name;
19 std::string last_name;
20 std::string password;
21 std::string phoneNumber;
22
23 // 基本的な入力コンポーネント:
24 Component input_first_name = Input(&first_name, "first name");
25 Component input_last_name = Input(&last_name, "last name");
26
27 // パスワード入力コンポーネント:
28 InputOption password_option;
29 password_option.password = true;
30 Component input_password = Input(&password, "password", password_option);
31
32 // 電話番号入力コンポーネント:
33 // 数字以外の文字を除外するために `CatchEvent` を使用しています。
34 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 // コンポーネントツリー:
43 auto component = Container::Vertical({
44 input_first_name,
45 input_last_name,
46 input_password,
47 input_phone_number,
48 });
49
50 // コンポーネントツリーのレンダリング方法を調整します:
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}
std::string character() const
Definition event.hpp:106
Ref< bool > password
入力内容を'*'で隠します。
イベントを表します。キープレスイベント、ターミナルのリサイズなど、さまざまなイベントがあります。
Definition event.hpp:28
Inputコンポーネントのオプション。
FTXUI ftxui:: 名前空間
Definition animation.hpp:9
std::shared_ptr< ComponentBase > Component