mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-09-17 16:38:09 +08:00
Prefer std::string over std::wstring. (#179)
In the past, FTXUI switched from std::string to std::wstring to support fullwidth characters. The reasons was that fullwidth characters can be stored inside a single wchar_t. Then FTXUI added support for combining characters. A single glygh doesn't even fit a wchar_t. Instead, a glyph can be arbitrary large. The usage of wstring doesn't really fit the new model and have several drawbacks: 1. It doesn't simplify the implementation of FTXUI, because of combining characters. 2. It reduces drawing performance by 2x. 3. It increase Screen's memory allocation by 2x. This patch converts FTXUI to use std::string internally. It now exposes std::string based API. The std::wstring API remains, but is now deprecated. Tests and examples haven't been update to show the breakage is limited. They will be updated in a second set of patches. Bug: https://github.com/ArthurSonzogni/FTXUI/issues/153 Co-authored-by: Tushar Maheshwari <tushar27192@gmail.com>
This commit is contained in:
@@ -10,7 +10,7 @@ using namespace ftxui;
|
||||
static void BencharkBasic(benchmark::State& state) {
|
||||
while (state.KeepRunning()) {
|
||||
auto document = vbox({
|
||||
text(L"Test"),
|
||||
text("Test"),
|
||||
separator(),
|
||||
hbox({
|
||||
gauge(0.9),
|
||||
@@ -20,7 +20,7 @@ static void BencharkBasic(benchmark::State& state) {
|
||||
gauge(0.1),
|
||||
separator(),
|
||||
}),
|
||||
text(L"Test"),
|
||||
text("Test"),
|
||||
}) |
|
||||
border;
|
||||
auto root = gauge(1.0);
|
||||
|
@@ -1,6 +1,7 @@
|
||||
#include <algorithm> // for max
|
||||
#include <iterator> // for begin, end
|
||||
#include <memory> // for make_shared, __shared_ptr_access
|
||||
#include <memory> // for allocator, make_shared, __shared_ptr_access
|
||||
#include <string> // for basic_string, string
|
||||
#include <utility> // for move
|
||||
#include <vector> // for vector, __alloc_traits<>::value_type
|
||||
|
||||
@@ -12,10 +13,11 @@
|
||||
|
||||
namespace ftxui {
|
||||
|
||||
static wchar_t simple_border_charset[] = L"╭╮╰╯─│┬┴┤├";
|
||||
static std::string simple_border_charset[] = {"╭", "╮", "╰", "╯", "─",
|
||||
"│", "┬", "┴", "┤", "├"};
|
||||
|
||||
// For reference, here is the charset for normal border:
|
||||
// L"┌┐└┘─│┬┴┤├";
|
||||
// {"┌", "┐", "└", "┘", "─", "│", "┬", "┴", "┤", "├"};
|
||||
// TODO(arthursonzogni): Consider adding options to choose the kind of borders
|
||||
// to use.
|
||||
|
||||
@@ -29,7 +31,7 @@ class Border : public Node {
|
||||
: Node(std::move(children)), charset_pixel(10, pixel) {}
|
||||
|
||||
std::vector<Pixel> charset_pixel;
|
||||
std::vector<wchar_t> charset;
|
||||
std::vector<std::string> charset;
|
||||
|
||||
void ComputeRequirement() override {
|
||||
Node::ComputeRequirement();
|
||||
@@ -120,10 +122,10 @@ class Border : public Node {
|
||||
///
|
||||
/// ```cpp
|
||||
/// // Use 'border' as a function...
|
||||
/// Element document = border(text(L"The element"));
|
||||
/// Element document = border(text("The element"));
|
||||
///
|
||||
/// // ...Or as a 'pipe'.
|
||||
/// Element document = text(L"The element") | border;
|
||||
/// Element document = text("The element") | border;
|
||||
/// ```
|
||||
///
|
||||
/// ### Output
|
||||
@@ -146,8 +148,8 @@ Element border(Element child) {
|
||||
/// ### Example
|
||||
///
|
||||
/// ```cpp
|
||||
/// Element document = window(text(L"Title"),
|
||||
/// text(L"content")
|
||||
/// Element document = window(text("Title"),
|
||||
/// text("content")
|
||||
/// );
|
||||
/// ```
|
||||
///
|
||||
|
@@ -52,7 +52,7 @@ class FgColor : public NodeDecorator {
|
||||
/// ### Example
|
||||
///
|
||||
/// ```cpp
|
||||
/// Element document = color(Color::Green, text(L"Success")),
|
||||
/// Element document = color(Color::Green, text("Success")),
|
||||
/// ```
|
||||
Element color(Color color, Element child) {
|
||||
return std::make_shared<FgColor>(std::move(child), color);
|
||||
@@ -67,7 +67,7 @@ Element color(Color color, Element child) {
|
||||
/// ### Example
|
||||
///
|
||||
/// ```cpp
|
||||
/// Element document = bgcolor(Color::Green, text(L"Success")),
|
||||
/// Element document = bgcolor(Color::Green, text("Success")),
|
||||
/// ```
|
||||
Element bgcolor(Color color, Element child) {
|
||||
return std::make_shared<BgColor>(std::move(child), color);
|
||||
@@ -81,7 +81,7 @@ Element bgcolor(Color color, Element child) {
|
||||
/// ### Example
|
||||
///
|
||||
/// ```cpp
|
||||
/// Element document = text(L"red") | color(Color::Red);
|
||||
/// Element document = text("red") | color(Color::Red);
|
||||
/// ```
|
||||
Decorator color(Color c) {
|
||||
return [c](Element child) { return color(c, std::move(child)); };
|
||||
@@ -95,7 +95,7 @@ Decorator color(Color c) {
|
||||
/// ### Example
|
||||
///
|
||||
/// ```cpp
|
||||
/// Element document = text(L"red") | bgcolor(Color::Red);
|
||||
/// Element document = text("red") | bgcolor(Color::Red);
|
||||
/// ```
|
||||
Decorator bgcolor(Color color) {
|
||||
return [color](Element child) { return bgcolor(color, std::move(child)); };
|
||||
|
@@ -103,9 +103,9 @@ Element filler() {
|
||||
///
|
||||
/// ~~~cpp
|
||||
/// hbox({
|
||||
/// text(L"left") | border ,
|
||||
/// text(L"middle") | border | flex,
|
||||
/// text(L"right") | border,
|
||||
/// text("left") | border ,
|
||||
/// text("middle") | border | flex,
|
||||
/// text("right") | border,
|
||||
/// });
|
||||
/// ~~~
|
||||
///
|
||||
|
@@ -1,4 +1,5 @@
|
||||
#include <memory> // for make_shared
|
||||
#include <memory> // for allocator, make_shared
|
||||
#include <string> // for string
|
||||
|
||||
#include "ftxui/dom/elements.hpp" // for Element, gauge
|
||||
#include "ftxui/dom/node.hpp" // for Node
|
||||
@@ -8,12 +9,13 @@
|
||||
|
||||
namespace ftxui {
|
||||
|
||||
static std::string charset[] =
|
||||
#if defined(FTXUI_MICROSOFT_TERMINAL_FALLBACK)
|
||||
// Microsoft's terminals often use fonts not handling the 8 unicode characters
|
||||
// for representing the whole gauge. Fallback with less.
|
||||
static wchar_t charset[] = L" ▌▌▌███";
|
||||
// Microsoft's terminals often use fonts not handling the 8 unicode
|
||||
// characters for representing the whole gauge. Fallback with less.
|
||||
{" ", " ", " ", " ", "▌", "▌", "▌", "█", "█", "█"};
|
||||
#else
|
||||
static wchar_t charset[] = L" ▏▎▍▌▋▊▉█";
|
||||
{" ", " ", "▏", "▎", "▍", "▌", "▋", "▊", "▉", "█"};
|
||||
#endif
|
||||
|
||||
class Gauge : public Node {
|
||||
|
@@ -1,5 +1,6 @@
|
||||
#include <functional> // for function
|
||||
#include <memory> // for make_shared
|
||||
#include <memory> // for allocator, make_shared
|
||||
#include <string> // for string
|
||||
#include <vector> // for vector
|
||||
|
||||
#include "ftxui/dom/elements.hpp" // for GraphFunction, Element, graph
|
||||
@@ -10,12 +11,13 @@
|
||||
|
||||
namespace ftxui {
|
||||
|
||||
// Microsoft's terminals often use fonts not handling the 8 unicode characters
|
||||
// for representing the whole gauge. Fallback with less.
|
||||
static std::string charset[] =
|
||||
#if defined(FTXUI_MICROSOFT_TERMINAL_FALLBACK)
|
||||
const wchar_t charset[] = L" █ █████";
|
||||
// Microsoft's terminals often use fonts not handling the 8 unicode
|
||||
// characters for representing the whole graph. Fallback with less.
|
||||
{" ", " ", "█", " ", "█", "█", "█", "█", "█"};
|
||||
#else
|
||||
const wchar_t charset[] = L" ▗▐▖▄▟▌▙█";
|
||||
{" ", "▗", "▐", "▖", "▄", "▟", "▌", "▙", "█"};
|
||||
#endif
|
||||
|
||||
class Graph : public Node {
|
||||
@@ -43,8 +45,7 @@ class Graph : public Node {
|
||||
int yy = 2 * y;
|
||||
int i_1 = yy < height_1 ? 0 : yy == height_1 ? 3 : 6;
|
||||
int i_2 = yy < height_2 ? 0 : yy == height_2 ? 1 : 2;
|
||||
wchar_t pix = charset[i_1 + i_2];
|
||||
screen.at(x, y) = pix;
|
||||
screen.at(x, y) = charset[i_1 + i_2];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -136,8 +136,8 @@ class HBox : public Node {
|
||||
///
|
||||
/// ```cpp
|
||||
/// hbox({
|
||||
/// text(L"Left"),
|
||||
/// text(L"Right"),
|
||||
/// text("Left"),
|
||||
/// text("Right"),
|
||||
/// });
|
||||
/// ```
|
||||
Element hbox(Elements children) {
|
||||
|
@@ -1,13 +1,14 @@
|
||||
#include <gtest/gtest-message.h> // for Message
|
||||
#include <gtest/gtest-test-part.h> // for TestPartResult
|
||||
#include <gtest/gtest-message.h> // for Message
|
||||
#include <gtest/gtest-test-part.h> // for SuiteApiResolver, TestFactoryImpl, TestPartResult
|
||||
#include <string> // for allocator, basic_string, string
|
||||
#include <vector> // for vector
|
||||
|
||||
#include "ftxui/dom/elements.hpp" // for text, operator|, Element, flex_grow
|
||||
#include "ftxui/dom/deprecated.hpp" // for text
|
||||
#include "ftxui/dom/elements.hpp" // for operator|, Element, flex_grow, flex_shrink, hbox
|
||||
#include "ftxui/dom/node.hpp" // for Render
|
||||
#include "ftxui/screen/box.hpp" // for ftxui
|
||||
#include "ftxui/screen/screen.hpp" // for Screen
|
||||
#include "gtest/gtest_pred_impl.h" // for Test, SuiteApiResolver, EXPECT_EQ
|
||||
#include "gtest/gtest_pred_impl.h" // for Test, EXPECT_EQ, TEST
|
||||
|
||||
using namespace ftxui;
|
||||
using namespace ftxui;
|
||||
|
@@ -1,7 +1,8 @@
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <sstream> // for basic_istream, wstringstream
|
||||
#include <string> // for allocator, char_traits, getline, operator+, wstring, basic_string
|
||||
|
||||
#include "ftxui/dom/elements.hpp"
|
||||
#include "ftxui/dom/deprecated.hpp" // for text, paragraph
|
||||
#include "ftxui/dom/elements.hpp" // for Elements
|
||||
|
||||
namespace ftxui {
|
||||
|
||||
@@ -14,9 +15,22 @@ Elements paragraph(std::wstring the_text) {
|
||||
Elements output;
|
||||
std::wstringstream ss(the_text);
|
||||
std::wstring word;
|
||||
while (std::getline(ss, word, L' ')) {
|
||||
while (std::getline(ss, word, L' '))
|
||||
output.push_back(text(word + L' '));
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
/// @brief Return a vector of ftxui::text for every word of the string. This is
|
||||
/// useful combined with ftxui::hflow.
|
||||
/// @param the_text The string to be splitted.
|
||||
/// @ingroup dom
|
||||
/// @see hflow.
|
||||
Elements paragraph(std::string the_text) {
|
||||
Elements output;
|
||||
std::stringstream ss(the_text);
|
||||
std::string word;
|
||||
while (std::getline(ss, word, ' '))
|
||||
output.push_back(text(word + ' '));
|
||||
return output;
|
||||
}
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
#include <memory> // for make_shared
|
||||
#include <string> // for wstring
|
||||
#include <string> // for string
|
||||
|
||||
#include "ftxui/dom/elements.hpp" // for Element, separator
|
||||
#include "ftxui/dom/node.hpp" // for Node
|
||||
@@ -22,11 +22,11 @@ class Separator : public Node {
|
||||
bool is_column = (box_.x_max == box_.x_min);
|
||||
bool is_line = (box_.y_min == box_.y_max);
|
||||
|
||||
wchar_t c = U'+';
|
||||
std::string c = "+";
|
||||
if (is_line && !is_column)
|
||||
c = U'─';
|
||||
c = "─";
|
||||
else
|
||||
c = U'│';
|
||||
c = "│";
|
||||
|
||||
for (int y = box_.y_min; y <= box_.y_max; ++y) {
|
||||
for (int x = box_.x_min; x <= box_.x_max; ++x) {
|
||||
|
@@ -1,6 +1,6 @@
|
||||
#include <stddef.h> // for size_t
|
||||
#include <memory> // for allocator, allocator_traits<>::value_type
|
||||
#include <string> // for basic_string, wstring
|
||||
#include <string> // for string
|
||||
#include <utility> // for move
|
||||
#include <vector> // for vector, __alloc_traits<>::value_type
|
||||
|
||||
@@ -8,242 +8,242 @@
|
||||
|
||||
namespace ftxui {
|
||||
|
||||
static const std::vector<std::vector<std::vector<std::wstring>>> elements = {
|
||||
static const std::vector<std::vector<std::vector<std::string>>> elements = {
|
||||
{
|
||||
{L"Replaced by the gauge"},
|
||||
{"Replaced by the gauge"},
|
||||
},
|
||||
{
|
||||
{L". "},
|
||||
{L".. "},
|
||||
{L"..."},
|
||||
{". "},
|
||||
{".. "},
|
||||
{"..."},
|
||||
},
|
||||
{
|
||||
{L"|"},
|
||||
{L"/"},
|
||||
{L"-"},
|
||||
{L"\\"},
|
||||
{"|"},
|
||||
{"/"},
|
||||
{"-"},
|
||||
{"\\"},
|
||||
},
|
||||
{
|
||||
{L"+"},
|
||||
{L"x"},
|
||||
{"+"},
|
||||
{"x"},
|
||||
},
|
||||
{
|
||||
{L"| "},
|
||||
{L"|| "},
|
||||
{L"|||"},
|
||||
{"| "},
|
||||
{"|| "},
|
||||
{"|||"},
|
||||
},
|
||||
{
|
||||
{L"←"},
|
||||
{L"↖"},
|
||||
{L"↑"},
|
||||
{L"↗"},
|
||||
{L"→"},
|
||||
{L"↘"},
|
||||
{L"↓"},
|
||||
{L"↙"},
|
||||
{"←"},
|
||||
{"↖"},
|
||||
{"↑"},
|
||||
{"↗"},
|
||||
{"→"},
|
||||
{"↘"},
|
||||
{"↓"},
|
||||
{"↙"},
|
||||
},
|
||||
{
|
||||
{L"▁"},
|
||||
{L"▂"},
|
||||
{L"▃"},
|
||||
{L"▄"},
|
||||
{L"▅"},
|
||||
{L"▆"},
|
||||
{L"▇"},
|
||||
{L"█"},
|
||||
{L"▇"},
|
||||
{L"▆"},
|
||||
{L"▅"},
|
||||
{L"▄"},
|
||||
{L"▃"},
|
||||
{L"▁"},
|
||||
{"▁"},
|
||||
{"▂"},
|
||||
{"▃"},
|
||||
{"▄"},
|
||||
{"▅"},
|
||||
{"▆"},
|
||||
{"▇"},
|
||||
{"█"},
|
||||
{"▇"},
|
||||
{"▆"},
|
||||
{"▅"},
|
||||
{"▄"},
|
||||
{"▃"},
|
||||
{"▁"},
|
||||
},
|
||||
{
|
||||
{L"▉"},
|
||||
{L"▊"},
|
||||
{L"▋"},
|
||||
{L"▌"},
|
||||
{L"▍"},
|
||||
{L"▎"},
|
||||
{L"▏"},
|
||||
{L"▎"},
|
||||
{L"▍"},
|
||||
{L"▌"},
|
||||
{L"▋"},
|
||||
{L"▊"},
|
||||
{"▉"},
|
||||
{"▊"},
|
||||
{"▋"},
|
||||
{"▌"},
|
||||
{"▍"},
|
||||
{"▎"},
|
||||
{"▏"},
|
||||
{"▎"},
|
||||
{"▍"},
|
||||
{"▌"},
|
||||
{"▋"},
|
||||
{"▊"},
|
||||
},
|
||||
{
|
||||
{L"▖"},
|
||||
{L"▘"},
|
||||
{L"▝"},
|
||||
{L"▗"},
|
||||
{"▖"},
|
||||
{"▘"},
|
||||
{"▝"},
|
||||
{"▗"},
|
||||
},
|
||||
{
|
||||
{L"◢"},
|
||||
{L"◣"},
|
||||
{L"◤"},
|
||||
{L"◥"},
|
||||
{"◢"},
|
||||
{"◣"},
|
||||
{"◤"},
|
||||
{"◥"},
|
||||
},
|
||||
{
|
||||
{L"◰"},
|
||||
{L"◳"},
|
||||
{L"◲"},
|
||||
{L"◱"},
|
||||
{"◰"},
|
||||
{"◳"},
|
||||
{"◲"},
|
||||
{"◱"},
|
||||
},
|
||||
{
|
||||
{L"◴"},
|
||||
{L"◷"},
|
||||
{L"◶"},
|
||||
{L"◵"},
|
||||
{"◴"},
|
||||
{"◷"},
|
||||
{"◶"},
|
||||
{"◵"},
|
||||
},
|
||||
{
|
||||
{L"◐"},
|
||||
{L"◓"},
|
||||
{L"◑"},
|
||||
{L"◒"},
|
||||
{"◐"},
|
||||
{"◓"},
|
||||
{"◑"},
|
||||
{"◒"},
|
||||
},
|
||||
{
|
||||
{L"◡"},
|
||||
{L"⊙"},
|
||||
{L"◠"},
|
||||
{"◡"},
|
||||
{"⊙"},
|
||||
{"◠"},
|
||||
},
|
||||
{
|
||||
{L"⠁"},
|
||||
{L"⠂"},
|
||||
{L"⠄"},
|
||||
{L"⡀"},
|
||||
{L"⢀"},
|
||||
{L"⠠"},
|
||||
{L"⠐"},
|
||||
{L"⠈"},
|
||||
{"⠁"},
|
||||
{"⠂"},
|
||||
{"⠄"},
|
||||
{"⡀"},
|
||||
{"⢀"},
|
||||
{"⠠"},
|
||||
{"⠐"},
|
||||
{"⠈"},
|
||||
},
|
||||
{
|
||||
{L"⠋"},
|
||||
{L"⠙"},
|
||||
{L"⠹"},
|
||||
{L"⠸"},
|
||||
{L"⠼"},
|
||||
{L"⠴"},
|
||||
{L"⠦"},
|
||||
{L"⠧"},
|
||||
{L"⠇"},
|
||||
{L"⠏"},
|
||||
{"⠋"},
|
||||
{"⠙"},
|
||||
{"⠹"},
|
||||
{"⠸"},
|
||||
{"⠼"},
|
||||
{"⠴"},
|
||||
{"⠦"},
|
||||
{"⠧"},
|
||||
{"⠇"},
|
||||
{"⠏"},
|
||||
},
|
||||
{
|
||||
{L"(*----------)"}, {L"(-*---------)"}, {L"(--*--------)"},
|
||||
{L"(---*-------)"}, {L"(----*------)"}, {L"(-----*-----)"},
|
||||
{L"(------*----)"}, {L"(-------*---)"}, {L"(--------*--)"},
|
||||
{L"(---------*-)"}, {L"(----------*)"}, {L"(---------*-)"},
|
||||
{L"(--------*--)"}, {L"(-------*---)"}, {L"(------*----)"},
|
||||
{L"(-----*-----)"}, {L"(----*------)"}, {L"(---*-------)"},
|
||||
{L"(--*--------)"}, {L"(-*---------)"},
|
||||
{"(*----------)"}, {"(-*---------)"}, {"(--*--------)"},
|
||||
{"(---*-------)"}, {"(----*------)"}, {"(-----*-----)"},
|
||||
{"(------*----)"}, {"(-------*---)"}, {"(--------*--)"},
|
||||
{"(---------*-)"}, {"(----------*)"}, {"(---------*-)"},
|
||||
{"(--------*--)"}, {"(-------*---)"}, {"(------*----)"},
|
||||
{"(-----*-----)"}, {"(----*------)"}, {"(---*-------)"},
|
||||
{"(--*--------)"}, {"(-*---------)"},
|
||||
},
|
||||
{
|
||||
{L"[ ]"},
|
||||
{L"[= ]"},
|
||||
{L"[== ]"},
|
||||
{L"[=== ]"},
|
||||
{L"[==== ]"},
|
||||
{L"[===== ]"},
|
||||
{L"[======]"},
|
||||
{L"[===== ]"},
|
||||
{L"[==== ]"},
|
||||
{L"[=== ]"},
|
||||
{L"[== ]"},
|
||||
{L"[= ]"},
|
||||
{"[ ]"},
|
||||
{"[= ]"},
|
||||
{"[== ]"},
|
||||
{"[=== ]"},
|
||||
{"[==== ]"},
|
||||
{"[===== ]"},
|
||||
{"[======]"},
|
||||
{"[===== ]"},
|
||||
{"[==== ]"},
|
||||
{"[=== ]"},
|
||||
{"[== ]"},
|
||||
{"[= ]"},
|
||||
},
|
||||
{
|
||||
{L"[ ]"},
|
||||
{L"[= ]"},
|
||||
{L"[== ]"},
|
||||
{L"[=== ]"},
|
||||
{L"[==== ]"},
|
||||
{L"[===== ]"},
|
||||
{L"[======]"},
|
||||
{L"[ =====]"},
|
||||
{L"[ ====]"},
|
||||
{L"[ ===]"},
|
||||
{L"[ ==]"},
|
||||
{L"[ =]"},
|
||||
{"[ ]"},
|
||||
{"[= ]"},
|
||||
{"[== ]"},
|
||||
{"[=== ]"},
|
||||
{"[==== ]"},
|
||||
{"[===== ]"},
|
||||
{"[======]"},
|
||||
{"[ =====]"},
|
||||
{"[ ====]"},
|
||||
{"[ ===]"},
|
||||
{"[ ==]"},
|
||||
{"[ =]"},
|
||||
},
|
||||
{
|
||||
{L"[== ]"},
|
||||
{L"[== ]"},
|
||||
{L"[== ]"},
|
||||
{L"[== ]"},
|
||||
{L"[== ]"},
|
||||
{L" [== ]"},
|
||||
{L"[ == ]"},
|
||||
{L"[ == ]"},
|
||||
{L"[ ==]"},
|
||||
{L"[ ==]"},
|
||||
{L"[ ==]"},
|
||||
{L"[ ==]"},
|
||||
{L"[ ==]"},
|
||||
{L"[ ==] "},
|
||||
{L"[ == ]"},
|
||||
{L"[ == ]"},
|
||||
{"[== ]"},
|
||||
{"[== ]"},
|
||||
{"[== ]"},
|
||||
{"[== ]"},
|
||||
{"[== ]"},
|
||||
{" [== ]"},
|
||||
{"[ == ]"},
|
||||
{"[ == ]"},
|
||||
{"[ ==]"},
|
||||
{"[ ==]"},
|
||||
{"[ ==]"},
|
||||
{"[ ==]"},
|
||||
{"[ ==]"},
|
||||
{"[ ==] "},
|
||||
{"[ == ]"},
|
||||
{"[ == ]"},
|
||||
},
|
||||
{{
|
||||
L" ─╮",
|
||||
L" │",
|
||||
L" ",
|
||||
" ─╮",
|
||||
" │",
|
||||
" ",
|
||||
},
|
||||
{
|
||||
L" ╮",
|
||||
L" │",
|
||||
L" ╯",
|
||||
" ╮",
|
||||
" │",
|
||||
" ╯",
|
||||
},
|
||||
{
|
||||
L" ",
|
||||
L" │",
|
||||
L" ─╯",
|
||||
" ",
|
||||
" │",
|
||||
" ─╯",
|
||||
},
|
||||
{
|
||||
L" ",
|
||||
L" ",
|
||||
L"╰─╯",
|
||||
" ",
|
||||
" ",
|
||||
"╰─╯",
|
||||
},
|
||||
{
|
||||
L" ",
|
||||
L"│ ",
|
||||
L"╰─ ",
|
||||
" ",
|
||||
"│ ",
|
||||
"╰─ ",
|
||||
},
|
||||
{
|
||||
L"╭ ",
|
||||
L"│ ",
|
||||
L"╰ ",
|
||||
"╭ ",
|
||||
"│ ",
|
||||
"╰ ",
|
||||
},
|
||||
{
|
||||
L"╭─ ",
|
||||
L"│ ",
|
||||
L" ",
|
||||
"╭─ ",
|
||||
"│ ",
|
||||
" ",
|
||||
},
|
||||
{
|
||||
L"╭─╮",
|
||||
L" ",
|
||||
L" ",
|
||||
"╭─╮",
|
||||
" ",
|
||||
" ",
|
||||
}},
|
||||
{{
|
||||
L" /\\O ",
|
||||
L" /\\/ ",
|
||||
L" /\\ ",
|
||||
L" / \\ ",
|
||||
L"LOL LOL",
|
||||
" /\\O ",
|
||||
" /\\/ ",
|
||||
" /\\ ",
|
||||
" / \\ ",
|
||||
"LOL LOL ",
|
||||
},
|
||||
{
|
||||
L" _O ",
|
||||
L" //|_ ",
|
||||
L" | ",
|
||||
L" /| ",
|
||||
L" LLOL ",
|
||||
" _O ",
|
||||
" //|_ ",
|
||||
" | ",
|
||||
" /| ",
|
||||
" LLOL ",
|
||||
},
|
||||
{
|
||||
L" O ",
|
||||
L" /_ ",
|
||||
L" |\\ ",
|
||||
L" / | ",
|
||||
L" LOLLOL ",
|
||||
" O ",
|
||||
" /_ ",
|
||||
" |\\ ",
|
||||
" / | ",
|
||||
" LOLLOL ",
|
||||
}}};
|
||||
|
||||
/// @brief Useful to represent the effect of time and/or events. This display an
|
||||
|
@@ -1,13 +1,14 @@
|
||||
#include <algorithm> // for max
|
||||
#include <memory> // for make_shared
|
||||
#include <string> // for wstring
|
||||
#include <memory> // for make_shared
|
||||
#include <string> // for string
|
||||
#include <vector> // for vector
|
||||
|
||||
#include "ftxui/dom/deprecated.hpp" // for text, vtext
|
||||
#include "ftxui/dom/elements.hpp" // for Element, text, vtext
|
||||
#include "ftxui/dom/node.hpp" // for Node
|
||||
#include "ftxui/dom/requirement.hpp" // for Requirement
|
||||
#include "ftxui/screen/box.hpp" // for Box
|
||||
#include "ftxui/screen/screen.hpp" // for Screen
|
||||
#include "ftxui/screen/string.hpp" // for wchar_width, wstring_width
|
||||
#include "ftxui/screen/screen.hpp" // for Pixel, Screen
|
||||
#include "ftxui/screen/string.hpp" // for string_width, Utf8ToGlyphs, to_string
|
||||
|
||||
namespace ftxui {
|
||||
|
||||
@@ -15,10 +16,10 @@ using ftxui::Screen;
|
||||
|
||||
class Text : public Node {
|
||||
public:
|
||||
Text(std::wstring text) : text_(text) {}
|
||||
Text(std::string text) : text_(text) {}
|
||||
|
||||
void ComputeRequirement() override {
|
||||
requirement_.min_x = wstring_width(text_);
|
||||
requirement_.min_x = string_width(text_);
|
||||
requirement_.min_y = 1;
|
||||
}
|
||||
|
||||
@@ -27,33 +28,26 @@ class Text : public Node {
|
||||
int y = box_.y_min;
|
||||
if (y > box_.y_max)
|
||||
return;
|
||||
for (wchar_t c : text_) {
|
||||
const int width = wchar_width(c);
|
||||
if (width >= 1) {
|
||||
if (x > box_.x_max)
|
||||
return;
|
||||
screen.PixelAt(x, y).character = c;
|
||||
} else {
|
||||
screen.PixelAt(x - 1, y).character += c;
|
||||
}
|
||||
x += std::max(width, 0);
|
||||
for (const auto& cell : Utf8ToGlyphs(text_)) {
|
||||
if (x > box_.x_max)
|
||||
return;
|
||||
screen.PixelAt(x, y).character = cell;
|
||||
++x;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
std::wstring text_;
|
||||
std::string text_;
|
||||
};
|
||||
|
||||
class VText : public Node {
|
||||
public:
|
||||
VText(std::wstring text) : text_(text) {
|
||||
for (auto& c : text_)
|
||||
width_ = std::max(width_, wchar_width(c));
|
||||
}
|
||||
VText(std::string text)
|
||||
: text_(text), width_{std::min(string_width(text_), 1)} {}
|
||||
|
||||
void ComputeRequirement() override {
|
||||
requirement_.min_x = width_;
|
||||
requirement_.min_y = text_.size();
|
||||
requirement_.min_y = string_width(text_);
|
||||
}
|
||||
|
||||
void Render(Screen& screen) override {
|
||||
@@ -61,20 +55,39 @@ class VText : public Node {
|
||||
int y = box_.y_min;
|
||||
if (x + width_ - 1 > box_.x_max)
|
||||
return;
|
||||
for (wchar_t c : text_) {
|
||||
for (const auto& it : Utf8ToGlyphs(text_)) {
|
||||
if (y > box_.y_max)
|
||||
return;
|
||||
screen.at(x, y) = c;
|
||||
screen.PixelAt(x, y).character = it;
|
||||
y += 1;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
std::wstring text_;
|
||||
std::string text_;
|
||||
int width_ = 1;
|
||||
};
|
||||
|
||||
/// @brief Display a pieve of unicode text.
|
||||
/// @brief Display a piece of UTF8 encoded unicode text.
|
||||
/// @ingroup dom
|
||||
/// @see ftxui::to_wstring
|
||||
///
|
||||
/// ### Example
|
||||
///
|
||||
/// ```cpp
|
||||
/// Element document = text("Hello world!");
|
||||
/// ```
|
||||
///
|
||||
/// ### Output
|
||||
///
|
||||
/// ```bash
|
||||
/// Hello world!
|
||||
/// ```
|
||||
Element text(std::string text) {
|
||||
return std::make_shared<Text>(text);
|
||||
}
|
||||
|
||||
/// @brief Display a piece of UTF16 encoded unicode text.
|
||||
/// @ingroup dom
|
||||
/// @see ftxui::to_wstring
|
||||
///
|
||||
@@ -90,10 +103,40 @@ class VText : public Node {
|
||||
/// Hello world!
|
||||
/// ```
|
||||
Element text(std::wstring text) {
|
||||
return std::make_shared<Text>(text);
|
||||
return std::make_shared<Text>(to_string(text));
|
||||
}
|
||||
|
||||
/// @brief Display a pieve of unicode text vertically.
|
||||
/// @brief Display a piece of unicode text vertically.
|
||||
/// @ingroup dom
|
||||
/// @see ftxui::to_wstring
|
||||
///
|
||||
/// ### Example
|
||||
///
|
||||
/// ```cpp
|
||||
/// Element document = vtext("Hello world!");
|
||||
/// ```
|
||||
///
|
||||
/// ### Output
|
||||
///
|
||||
/// ```bash
|
||||
/// H
|
||||
/// e
|
||||
/// l
|
||||
/// l
|
||||
/// o
|
||||
///
|
||||
/// w
|
||||
/// o
|
||||
/// r
|
||||
/// l
|
||||
/// d
|
||||
/// !
|
||||
/// ```
|
||||
Element vtext(std::string text) {
|
||||
return std::make_shared<VText>(text);
|
||||
}
|
||||
|
||||
/// @brief Display a piece of UTF16 encoded unicode text vertically.
|
||||
/// @ingroup dom
|
||||
/// @see ftxui::to_wstring
|
||||
///
|
||||
@@ -120,7 +163,7 @@ Element text(std::wstring text) {
|
||||
/// !
|
||||
/// ```
|
||||
Element vtext(std::wstring text) {
|
||||
return std::make_shared<VText>(text);
|
||||
return std::make_shared<VText>(to_string(text));
|
||||
}
|
||||
|
||||
} // namespace ftxui
|
||||
|
@@ -2,12 +2,13 @@
|
||||
#include <gtest/gtest-test-part.h> // for SuiteApiResolver, TestFactoryImpl, TestPartResult
|
||||
#include <string> // for allocator, wstring
|
||||
|
||||
#include "ftxui/dom/elements.hpp" // for text, operator|, border, Element
|
||||
#include "ftxui/dom/node.hpp" // for Render
|
||||
#include "ftxui/screen/box.hpp" // for ftxui
|
||||
#include "ftxui/screen/screen.hpp" // for Screen
|
||||
#include "ftxui/screen/string.hpp" // for to_string
|
||||
#include "gtest/gtest_pred_impl.h" // for Test, EXPECT_EQ, TEST
|
||||
#include "ftxui/dom/deprecated.hpp" // for text
|
||||
#include "ftxui/dom/elements.hpp" // for operator|, border, Element
|
||||
#include "ftxui/dom/node.hpp" // for Render
|
||||
#include "ftxui/screen/box.hpp" // for ftxui
|
||||
#include "ftxui/screen/screen.hpp" // for Screen
|
||||
#include "ftxui/screen/string.hpp" // for to_string
|
||||
#include "gtest/gtest_pred_impl.h" // for Test, EXPECT_EQ, TEST
|
||||
|
||||
using namespace ftxui;
|
||||
|
||||
|
@@ -56,10 +56,10 @@ Elements operator|(Elements elements, Decorator decorator) {
|
||||
///
|
||||
/// Both of these are equivalent:
|
||||
/// ```cpp
|
||||
/// bold(text(L"Hello"));
|
||||
/// bold(text("Hello"));
|
||||
/// ```
|
||||
/// ```cpp
|
||||
/// text(L"Hello") | bold;
|
||||
/// text("Hello") | bold;
|
||||
/// ```
|
||||
Element operator|(Element element, Decorator decorator) {
|
||||
return decorator(std::move(element));
|
||||
|
@@ -137,8 +137,8 @@ class VBox : public Node {
|
||||
///
|
||||
/// ```cpp
|
||||
/// vbox({
|
||||
/// text(L"Up"),
|
||||
/// text(L"Down"),
|
||||
/// text("Up"),
|
||||
/// text("Down"),
|
||||
/// });
|
||||
/// ```
|
||||
Element vbox(Elements children) {
|
||||
|
@@ -1,14 +1,15 @@
|
||||
#include <gtest/gtest-message.h> // for Message
|
||||
#include <gtest/gtest-test-part.h> // for TestPartResult
|
||||
#include <gtest/gtest-message.h> // for Message
|
||||
#include <gtest/gtest-test-part.h> // for SuiteApiResolver, TestFactoryImpl, TestPartResult
|
||||
#include <algorithm> // for remove
|
||||
#include <string> // for allocator, basic_string, string
|
||||
#include <vector> // for vector
|
||||
|
||||
#include "ftxui/dom/elements.hpp" // for vtext, operator|, Element, flex_grow
|
||||
#include "ftxui/dom/deprecated.hpp" // for vtext
|
||||
#include "ftxui/dom/elements.hpp" // for operator|, Element, flex_grow, flex_shrink, vbox
|
||||
#include "ftxui/dom/node.hpp" // for Render
|
||||
#include "ftxui/screen/box.hpp" // for ftxui
|
||||
#include "ftxui/screen/screen.hpp" // for Screen
|
||||
#include "gtest/gtest_pred_impl.h" // for Test, SuiteApiResolver, EXPECT_EQ
|
||||
#include "gtest/gtest_pred_impl.h" // for Test, EXPECT_EQ, TEST
|
||||
|
||||
using namespace ftxui;
|
||||
using namespace ftxui;
|
||||
|
Reference in New Issue
Block a user