Hello! I am just starting with FTXUI, and tried to make a quick AI chat app.
However, I have encountered an issue that my text sometimes disappears for no apparent reason:
The grey boxes are supposed to contain user messages (expected behavior). Instead, the text disappears, and only the grey boxes remain
Here is the offending code:
#include "ftxui/component/component.hpp"
#include "ftxui/component/component_base.hpp"
#include "ftxui/component/component_options.hpp"
#include "ftxui/component/event.hpp"
#include "ftxui/component/screen_interactive.hpp"
#include "ftxui/dom/elements.hpp"
//#include "openai/openai.hpp"
#include <ftxui/dom/elements.hpp>
#include <ftxui/screen/screen.hpp>
#include <iostream>
#include <string>
#include <vector>
std::string get_ai_response(std::vector<std::string> messages) {
// requests provider for an answer. Returns some multiline string
return "I am a helpful assistant! \n Let me know what you need help with today."
}
int main(void) {
using namespace ftxui;
// define the buffer at the top
std::vector<std::string> message_list;
// the actual input area
std::string input_text = "I am input text";
InputOption input_option = InputOption::Default();
auto input = Input(&input_text, input_option);
input |= CatchEvent([&](Event event) {
if (event == Event::Return) {
message_list.push_back(input_text);
std::string response = get_ai_response(message_list);
message_list.push_back(response);
input_text = "";
return true;
}
return false;
});
auto component = Container::Vertical({
input,
}) |
size(HEIGHT, GREATER_THAN, 3);
// Tweak how the component tree is rendered:
auto renderer = Renderer(component, [&] {
// it's not very efficient way to render this, but I don't see why this shouldn't work
auto n_messages = message_list.size();
std::vector<Element> message_history;
message_history.reserve(n_messages);
for (int i = 0; i < n_messages; i++) {
if (i % 2) {
message_history.push_back(paragraph(message_list[i]));
} else {
message_history.push_back(paragraph(message_list[i]) |
borderStyled(LIGHT, Color::GrayDark));
}
}
return vbox({vbox(message_history), separator(), component->Render()});
});
auto screen = ScreenInteractive::TerminalOutput();
screen.Loop(renderer);
return EXIT_SUCCESS;
}
I am using version 6.1.9 downloaded from GitHub releases, and running under Linux in Ptyxis 49.3 and Ghostty 1.3.1-1.fc43.
Hello! I am just starting with FTXUI, and tried to make a quick AI chat app.
However, I have encountered an issue that my text sometimes disappears for no apparent reason:
The grey boxes are supposed to contain user messages (expected behavior). Instead, the text disappears, and only the grey boxes remain
Here is the offending code:
I am using version 6.1.9 downloaded from GitHub releases, and running under Linux in Ptyxis 49.3 and Ghostty 1.3.1-1.fc43.