Newline/Linefeed character? #941
-
Ok, bit of a convoluted question here, but the gist of it is this: I'm trying to create a CYOA text game that utilizes FTXUI, and have run into an issue regarding formatting of paragraphs. I need to print multiple, separate paragraphs to a vbox with the click of a button, and have been utilizing a vector of strings (paragraphs) that is indexed through when a button is clicked. This works fine, but I need to print multiple paragraphs simultaneously, separated by white space. I tried using both text() and paragraph() with a newline character, but neither of these functions seem to parse the standard '\n' like cout/printf would. Does FTXUI have support for any sort of newline or linefeed character when using the text() or paragraph() functions? If not, is there some relatively simple code that can replicate it? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hello! What about splitting the text by '\n', then mapping each part into a #include <ftxui/dom/elements.hpp> // for paragraph, vbox, Elements
#include <string> // for string, getline
#include <sstream> // for stringstream
using namespace ftxui;
Elements splitAndDisplay(const std::string& text) {
Elements elements;
std::stringstream ss(text);
std::string line;
// Directly create and add paragraph elements while splitting the text
while (std::getline(ss, line, '\n')) {
elements.push_back(paragraph(line));
}
// Join the paragraphs with a vbox
return vbox(elements);
} |
Beta Was this translation helpful? Give feedback.
You could use one of:
separatorEmpty()
separatorStyled(EMPTY)