FTXUI 7.1.0
C++ functional terminal UI.
Loading...
Searching...
No Matches
print_above.cpp
Go to the documentation of this file.
1// Copyright 2026 Arthur Sonzogni. All rights reserved.
2// Use of this source code is governed by the MIT license that can be found in
3// the LICENSE file.
4#include <string> // for string
5
6#include "ftxui/component/app.hpp" // for App
7#include "ftxui/component/component.hpp" // for Input, Renderer, CatchEvent
8#include "ftxui/component/event.hpp" // for Event
9#include "ftxui/dom/elements.hpp" // for text, paragraph, borderStyled, vbox
10
11// A chat-like app. The messages are printed above the input, and scroll into
12// the terminal scrollback. Only the input is redrawn.
13int main() {
14 using namespace ftxui;
15
16 auto app = App::TerminalOutput();
17
18 std::string input_text;
19 auto input = Input(&input_text, "Type a message, then press Enter.");
20
21 input |= CatchEvent([&](Event event) {
22 if (event != Event::Return) {
23 return false;
24 }
25 if (input_text.empty()) {
26 return true;
27 }
28 app.PrintAbove(vbox({
29 paragraph(input_text) | borderStyled(LIGHT, Color::GrayDark),
30 paragraph("You said " + std::to_string(input_text.size()) +
31 " characters."),
32 }));
33 input_text.clear();
34 return true;
35 });
36
37 auto renderer = Renderer(input, [&] {
38 return vbox({
39 separator(),
40 hbox({text("> "), input->Render()}),
41 text("Press Ctrl+C to quit.") | dim,
42 });
43 });
44
45 app.Loop(renderer);
46}
The FTXUI ftxui:: namespace.
Definition animation.hpp:11
int main()