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:
Arthur Sonzogni
2021-08-08 23:25:20 +02:00
committed by GitHub
parent 1ff894f6f5
commit 3b4ab618a3
84 changed files with 1234 additions and 996 deletions

View File

@@ -1,9 +1,10 @@
#include <ftxui/dom/elements.hpp>
#include <ftxui/screen/screen.hpp>
#include <memory>
#include <ftxui/dom/elements.hpp> // for operator|, vbox, border, Element, hbox
#include <ftxui/screen/screen.hpp> // for Dimension, Screen
#include <memory> // for allocator
#include "ftxui/dom/node.hpp"
#include "ftxui/screen/box.hpp"
#include "ftxui/dom/deprecated.hpp" // for text
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
int main(int argc, const char* argv[]) {
using namespace ftxui;

View File

@@ -7,7 +7,8 @@
using namespace ftxui;
#include "./color_info_sorted_2d.ipp" // for ColorInfoSorted2D
#include "ftxui/dom/elements.hpp" // for text, bgcolor, color, vbox, hbox, separator, operator|, Elements, Element, border
#include "ftxui/dom/deprecated.hpp" // for text
#include "ftxui/dom/elements.hpp" // for bgcolor, color, vbox, hbox, separator, operator|, Elements, Element, border
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/color.hpp" // for Color, Color::Black, Color::Blue, Color::BlueLight, Color::Cyan, Color::CyanLight, Color::Default, Color::GrayDark, Color::GrayLight, Color::Green, Color::GreenLight, Color::Magenta, Color::MagentaLight, Color::Red, Color::RedLight, Color::White, Color::Yellow, Color::YellowLight, Color::Palette256, ftxui

View File

@@ -1,17 +1,18 @@
#include <ftxui/dom/elements.hpp>
#include <ftxui/screen/color_info.hpp>
#include <ftxui/screen/screen.hpp>
#include <string>
#include <utility>
#include <vector>
#include <ftxui/dom/elements.hpp> // for bgcolor, hbox, operator|, Elements, vbox, Element
#include <ftxui/screen/color_info.hpp> // for ColorInfo
#include <ftxui/screen/screen.hpp> // for Dimension, Screen
#include <string> // for allocator, string
#include <utility> // for move
#include <vector> // for vector
#include "ftxui/dom/node.hpp"
#include "ftxui/screen/box.hpp"
#include "ftxui/screen/color.hpp"
#include "ftxui/screen/string.hpp"
#include "ftxui/dom/deprecated.hpp" // for text
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
#include "ftxui/screen/color.hpp" // for Color, Color::Palette256
#include "ftxui/screen/string.hpp" // for to_wstring
using namespace ftxui;
#include "./color_info_sorted_2d.ipp" // ColorInfoSorted2D.
#include "./color_info_sorted_2d.ipp" // for ColorInfoSorted2D
int main(int argc, const char* argv[]) {
std::vector<std::vector<ColorInfo>> info_columns = ColorInfoSorted2D();

View File

@@ -1,11 +1,12 @@
#include <ftxui/dom/elements.hpp>
#include <ftxui/screen/screen.hpp>
#include <memory>
#include <utility>
#include <ftxui/dom/elements.hpp> // for operator|, Elements, bgcolor, color, hbox, vbox, Element
#include <ftxui/screen/screen.hpp> // for Dimension, Screen
#include <memory> // for allocator
#include <utility> // for move
#include "ftxui/dom/node.hpp"
#include "ftxui/screen/box.hpp"
#include "ftxui/screen/color.hpp"
#include "ftxui/dom/deprecated.hpp" // for text
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
#include "ftxui/screen/color.hpp" // for Color
int main(int argc, const char* argv[]) {
using namespace ftxui;

View File

@@ -1,11 +1,12 @@
#include <ftxui/dom/elements.hpp>
#include <ftxui/screen/screen.hpp>
#include <memory>
#include <utility>
#include <ftxui/dom/elements.hpp> // for hbox, bgcolor, operator|, vbox, Elements, window, Element
#include <ftxui/screen/screen.hpp> // for Dimension, Screen
#include <memory> // for allocator
#include <utility> // for move
#include "ftxui/dom/node.hpp"
#include "ftxui/screen/box.hpp"
#include "ftxui/screen/color.hpp"
#include "ftxui/dom/deprecated.hpp" // for text
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
#include "ftxui/screen/color.hpp" // for Color
int main(int argc, const char* argv[]) {
using namespace ftxui;

View File

@@ -1,9 +1,10 @@
#include <ftxui/dom/elements.hpp>
#include <ftxui/screen/screen.hpp>
#include <memory>
#include <ftxui/dom/elements.hpp> // for operator|, border, Element, vbox, center, dbox
#include <ftxui/screen/screen.hpp> // for Dimension, Screen
#include <memory> // for allocator
#include "ftxui/dom/node.hpp"
#include "ftxui/screen/box.hpp"
#include "ftxui/dom/deprecated.hpp" // for text
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
int main(int argc, const char* argv[]) {
using namespace ftxui;

View File

@@ -1,12 +1,13 @@
#include <chrono>
#include <ftxui/dom/elements.hpp>
#include <ftxui/screen/screen.hpp>
#include <iostream>
#include <string>
#include <thread>
#include <chrono> // for operator""s, chrono_literals
#include <ftxui/dom/elements.hpp> // for gauge, operator|, flex, hbox, Element
#include <ftxui/screen/screen.hpp> // for Screen
#include <iostream> // for cout, endl, ostream
#include <string> // for allocator, operator+, char_traits, operator<<, to_wstring, basic_string, string, wstring
#include <thread> // for sleep_for
#include "ftxui/dom/node.hpp"
#include "ftxui/screen/box.hpp"
#include "ftxui/dom/deprecated.hpp" // for text
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
int main(int argc, const char* argv[]) {
using namespace ftxui;

View File

@@ -1,12 +1,13 @@
#include <stddef.h> // for size_t
#include <ftxui/dom/elements.hpp> // for operator|, size, Element, text, hcenter, Decorator, WIDTH, hflow, window, EQUAL, GREATER_THAN, HEIGHT, bold, border, dim, LESS_THAN
#include <ftxui/dom/elements.hpp> // for operator|, size, Element, hcenter, Decorator, WIDTH, hflow, window, EQUAL, GREATER_THAN, HEIGHT, bold, border, dim, LESS_THAN
#include <ftxui/screen/screen.hpp> // for Dimension, Screen
#include <ftxui/screen/string.hpp> // for to_wstring
#include <memory> // for shared_ptr
#include <string> // for allocator, operator+, char_traits, wstring
#include <memory> // for allocator, shared_ptr
#include <string> // for operator+, char_traits, wstring
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
#include "ftxui/dom/deprecated.hpp" // for text
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
int main(int argc, const char* argv[]) {
using namespace ftxui;

View File

@@ -5,7 +5,8 @@
#include <string> // for operator<<, string
#include <thread> // for sleep_for
#include "ftxui/dom/elements.hpp" // for paragraph, text, operator|, Element, border, color, hflow, spinner, vbox, bold, dim, underlined
#include "ftxui/dom/deprecated.hpp" // for paragraph, text
#include "ftxui/dom/elements.hpp" // for operator|, Element, border, color, hflow, spinner, vbox, bold, dim, underlined
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
#include "ftxui/screen/color.hpp" // for Color, Color::Red

View File

@@ -1,18 +1,19 @@
#include <chrono>
#include <ftxui/dom/elements.hpp>
#include <ftxui/screen/screen.hpp>
#include <ftxui/screen/string.hpp>
#include <iostream>
#include <list>
#include <memory>
#include <string>
#include <thread>
#include <utility>
#include <vector>
#include <chrono> // for operator""s, chrono_literals
#include <ftxui/dom/elements.hpp> // for operator|, Element, hbox, bold, color, filler, separator, vbox, window, gauge, size, dim, EQUAL, WIDTH
#include <ftxui/screen/screen.hpp> // for Screen, Dimension
#include <ftxui/screen/string.hpp> // for to_wstring
#include <iostream> // for cout, endl, ostream
#include <list> // for list, operator!=, _List_iterator, _List_iterator<>::_Self
#include <memory> // for allocator, shared_ptr, allocator_traits<>::value_type
#include <string> // for wstring, operator<<, string
#include <thread> // for sleep_for
#include <utility> // for move
#include <vector> // for vector
#include "ftxui/dom/node.hpp"
#include "ftxui/screen/box.hpp"
#include "ftxui/screen/color.hpp"
#include "ftxui/dom/deprecated.hpp" // for text
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
#include "ftxui/screen/color.hpp" // for Color, Color::Green, Color::Red, Color::RedLight
int main(int argc, const char* argv[]) {
using namespace ftxui;

View File

@@ -1,10 +1,11 @@
#include <stdio.h>
#include <ftxui/dom/elements.hpp>
#include <ftxui/screen/screen.hpp>
#include <string>
#include <stdio.h> // for getchar
#include <ftxui/dom/elements.hpp> // for operator|, hflow, border, Element, hbox, flex, vbox
#include <ftxui/screen/screen.hpp> // for Dimension, Screen
#include <string> // for allocator, wstring
#include "ftxui/dom/node.hpp"
#include "ftxui/screen/box.hpp"
#include "ftxui/dom/deprecated.hpp" // for paragraph
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
int main(int argc, const char* argv[]) {
using namespace ftxui;

View File

@@ -1,9 +1,10 @@
#include <ftxui/dom/elements.hpp>
#include <ftxui/screen/screen.hpp>
#include <memory>
#include <ftxui/dom/elements.hpp> // for center, separator, operator|, flex, Element, vbox, hbox, border
#include <ftxui/screen/screen.hpp> // for Dimension, Screen
#include <memory> // for allocator
#include "ftxui/dom/node.hpp"
#include "ftxui/screen/box.hpp"
#include "ftxui/dom/deprecated.hpp" // for text
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
int main(int argc, const char* argv[]) {
using namespace ftxui;

View File

@@ -1,12 +1,13 @@
#include <ftxui/dom/elements.hpp>
#include <ftxui/screen/screen.hpp>
#include <ftxui/screen/string.hpp>
#include <memory>
#include <string>
#include <utility>
#include <ftxui/dom/elements.hpp> // for operator|, Element, hcenter, hbox, size, window, Elements, bold, dim, EQUAL, WIDTH
#include <ftxui/screen/screen.hpp> // for Screen, Dimension
#include <ftxui/screen/string.hpp> // for to_wstring
#include <memory> // for allocator, shared_ptr
#include <string> // for wstring
#include <utility> // for move
#include "ftxui/dom/node.hpp"
#include "ftxui/screen/box.hpp"
#include "ftxui/dom/deprecated.hpp" // for text
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
int main(int argc, const char* argv[]) {
using namespace ftxui;

View File

@@ -1,15 +1,16 @@
#include <chrono>
#include <ftxui/dom/elements.hpp>
#include <ftxui/screen/screen.hpp>
#include <ftxui/screen/string.hpp>
#include <iostream>
#include <string>
#include <thread>
#include <utility>
#include <vector>
#include <chrono> // for operator""s, chrono_literals
#include <ftxui/dom/elements.hpp> // for Element, operator|, separator, filler, hbox, size, spinner, vbox, bold, border, EQUAL, WIDTH
#include <ftxui/screen/screen.hpp> // for Screen, Dimension
#include <ftxui/screen/string.hpp> // for to_wstring
#include <iostream> // for cout, endl, ostream
#include <string> // for operator<<, string
#include <thread> // for sleep_for
#include <utility> // for move
#include <vector> // for vector
#include "ftxui/dom/node.hpp"
#include "ftxui/screen/box.hpp"
#include "ftxui/dom/deprecated.hpp" // for text
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
int main(int argc, const char* argv[]) {
using namespace ftxui;

View File

@@ -1,9 +1,10 @@
#include <ftxui/dom/elements.hpp>
#include <ftxui/screen/screen.hpp>
#include <memory>
#include <ftxui/dom/elements.hpp> // for operator|, blink, hbox, Element
#include <ftxui/screen/screen.hpp> // for Dimension, Screen
#include <memory> // for allocator
#include "ftxui/dom/node.hpp"
#include "ftxui/screen/box.hpp"
#include "ftxui/dom/deprecated.hpp" // for text
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
int main(int argc, const char* argv[]) {
using namespace ftxui;

View File

@@ -1,9 +1,10 @@
#include <ftxui/dom/elements.hpp>
#include <ftxui/screen/screen.hpp>
#include <memory>
#include <ftxui/dom/elements.hpp> // for operator|, bold, hbox, Element
#include <ftxui/screen/screen.hpp> // for Dimension, Screen
#include <memory> // for allocator
#include "ftxui/dom/node.hpp"
#include "ftxui/screen/box.hpp"
#include "ftxui/dom/deprecated.hpp" // for text
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
int main(int argc, const char* argv[]) {
using namespace ftxui;

View File

@@ -1,9 +1,10 @@
#include <ftxui/screen/screen.hpp> // for Dimension, Screen
#include <memory> // for allocator
#include "ftxui/dom/elements.hpp" // for text, bgcolor, color, vbox, filler, hbox
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
#include "ftxui/dom/deprecated.hpp" // for text
#include "ftxui/dom/elements.hpp" // for bgcolor, color, vbox, filler, hbox
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
#include "ftxui/screen/color.hpp" // for Color, Color::Black, Color::Blue, Color::BlueLight, Color::Cyan, Color::CyanLight, Color::Default, Color::GrayDark, Color::GrayLight, Color::Green, Color::GreenLight, Color::Magenta, Color::MagentaLight, Color::Red, Color::RedLight, Color::White, Color::Yellow, Color::YellowLight
int main(int argc, const char* argv[]) {

View File

@@ -1,9 +1,10 @@
#include <ftxui/dom/elements.hpp>
#include <ftxui/screen/screen.hpp>
#include <memory>
#include <ftxui/dom/elements.hpp> // for operator|, dim, hbox, Element
#include <ftxui/screen/screen.hpp> // for Dimension, Screen
#include <memory> // for allocator
#include "ftxui/dom/node.hpp"
#include "ftxui/screen/box.hpp"
#include "ftxui/dom/deprecated.hpp" // for text
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
int main(int argc, const char* argv[]) {
using namespace ftxui;

View File

@@ -1,10 +1,11 @@
#include <ftxui/dom/elements.hpp>
#include <ftxui/screen/screen.hpp>
#include <memory>
#include <ftxui/dom/elements.hpp> // for operator|, Element, bgcolor, color, blink, bold, dim, inverted, underlined, hbox
#include <ftxui/screen/screen.hpp> // for Dimension, Screen
#include <memory> // for allocator
#include "ftxui/dom/node.hpp"
#include "ftxui/screen/box.hpp"
#include "ftxui/screen/color.hpp"
#include "ftxui/dom/deprecated.hpp" // for text
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
#include "ftxui/screen/color.hpp" // for Color, Color::Blue
int main(int argc, const char* argv[]) {
using namespace ftxui;

View File

@@ -1,9 +1,10 @@
#include <ftxui/dom/elements.hpp>
#include <ftxui/screen/screen.hpp>
#include <memory>
#include <ftxui/dom/elements.hpp> // for operator|, inverted, hbox, Element
#include <ftxui/screen/screen.hpp> // for Dimension, Screen
#include <memory> // for allocator
#include "ftxui/dom/node.hpp"
#include "ftxui/screen/box.hpp"
#include "ftxui/dom/deprecated.hpp" // for text
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
int main(int argc, const char* argv[]) {
using namespace ftxui;

View File

@@ -1,9 +1,10 @@
#include <ftxui/dom/elements.hpp>
#include <ftxui/screen/screen.hpp>
#include <memory>
#include <ftxui/dom/elements.hpp> // for operator|, underlined, hbox, Element
#include <ftxui/screen/screen.hpp> // for Dimension, Screen
#include <memory> // for allocator
#include "ftxui/dom/node.hpp"
#include "ftxui/screen/box.hpp"
#include "ftxui/dom/deprecated.hpp" // for text
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
int main(int argc, const char* argv[]) {
using namespace ftxui;

View File

@@ -1,10 +1,11 @@
#include <stdio.h>
#include <ftxui/dom/elements.hpp>
#include <ftxui/screen/screen.hpp>
#include <memory>
#include <stdio.h> // for getchar
#include <ftxui/dom/elements.hpp> // for filler, hbox, vbox
#include <ftxui/screen/screen.hpp> // for Screen, Dimension
#include <memory> // for allocator
#include "ftxui/dom/node.hpp"
#include "ftxui/screen/box.hpp"
#include "ftxui/dom/deprecated.hpp" // for text
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
int main(int argc, const char* argv[]) {
using namespace ftxui;