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. 無断複写・転載を禁じます。
2// このソースコードの使用は、LICENSEファイルにあるMITライセンスに従います。
3#include <cstdlib> // for system, EXIT_SUCCESS
4#include <iostream> // for operator<<, basic_ostream, basic_ostream::operator<<, cout, endl, flush, ostream, basic_ostream<>::__ostream_type, cin
5#include <memory> // for shared_ptr, __shared_ptr_access, allocator
6#include <string> // for getline, string
7
8#include "ftxui/component/captured_mouse.hpp" // for ftxui
9#include "ftxui/component/component.hpp" // for Button, Horizontal, Renderer
10#include "ftxui/component/component_base.hpp" // for ComponentBase
11#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
12#include "ftxui/dom/elements.hpp" // for operator|, filler, Element, borderEmpty, hbox, size, paragraph, vbox, LESS_THAN, border, center, HEIGHT, WIDTH
13
14int main() {
15 using namespace ftxui;
16
17 auto screen = ScreenInteractive::Fullscreen();
18
19 // このボタンを押すと、「screen.WithRestoredIO」はターミナルフックを一時的に
20 // アンインストールし、提供されたコールバック関数を実行します。これにより、
21 // アプリケーションを非対話モードで実行できます。
22 auto btn_run = Button("Execute with restored IO", screen.WithRestoredIO([] {
23 std::cout << "これはstdin/stdoutを使用する子プログラムです。" << std::endl;
24 for (int i = 0; i < 10; ++i) {
25 std::cout << "10個の文字列を入力してください (" << i << "/10)" << std::flush;
26 std::string input;
27 std::getline(std::cin, input);
28 }
29 }));
30
31 auto btn_quit = Button("Quit", screen.ExitLoopClosure());
32
33 auto layout = Container::Horizontal({
34 btn_run,
35 btn_quit,
36 });
37
38 auto renderer = Renderer(layout, [&] {
39 auto explanation = paragraph(
40 "このボタンをクリックすると、ScreenInteractiveが一時停止され、"
41 "stdin/stdoutへのアクセスが一時的に回復され、関数が実行されます。");
42 auto element = vbox({
43 explanation | borderEmpty,
44 hbox({
45 btn_run->Render(),
46 filler(),
47 btn_quit->Render(),
48 }),
49 });
50
51 element = element | borderEmpty | border | size(WIDTH, LESS_THAN, 80) |
52 size(HEIGHT, LESS_THAN, 20) | center;
53 return element;
54 });
55
56 screen.Loop(renderer);
57 return EXIT_SUCCESS;
58}
Element borderEmpty(Element child)
要素の周囲に空のボーダーを描画します。
FTXUI ftxui:: 名前空間
Definition animation.hpp:9
return size
Definition string.cpp:1516
int main()