FTXUI/examples/dom/html_like.cpp
Arthur Sonzogni 3b4ab618a3
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>
2021-08-08 23:25:20 +02:00

63 lines
2.9 KiB
C++

#include <chrono> // for operator""s, chrono_literals
#include <ftxui/screen/screen.hpp> // for Screen, Dimension
#include <iostream> // for cout, ostream
#include <memory> // for allocator, shared_ptr
#include <string> // for operator<<, string
#include <thread> // for sleep_for
#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
int main(int argc, const char* argv[]) {
using namespace ftxui;
using namespace std::chrono_literals;
auto img1 = []() { return text(L"img") | border; };
auto img2 = []() { return vbox({text(L"big"), text(L"image")}) | border; };
std::string reset_position;
for (int i = 0;; ++i) {
auto document = //
hflow(
paragraph(L"Hello world! Here is an image:"), img1(),
paragraph(L" Here is a text "), text(L"underlined ") | underlined,
paragraph(L" Here is a text "), text(L"bold ") | bold,
paragraph(L"Hello world! Here is an image:"), img2(),
paragraph(
L"Le Lorem Ipsum est simplement du faux texte employé dans la "
L"composition et la mise en page avant impression. Le Lorem "
L"Ipsum est le faux texte standard de l'imprimerie depuis les "
L"années 1500, quand un imprimeur anonyme assembla ensemble "
L"des morceaux de texte pour réaliser un livre spécimen de "
L"polices de texte. Il n'a pas fait que survivre cinq siècles, "
L"mais s'est aussi adapté à la bureautique informatique, sans "
L"que son contenu n'en soit modifié. Il a été popularisé dans "
L"les années 1960 grâce à la vente de feuilles Letraset "
L"contenant des passages du Lorem Ipsum, et, plus récemment, "
L"par son inclusion dans des applications de mise en page de "
L"texte, comme Aldus PageMaker."),
paragraph(L" Here is a text "), text(L"dim ") | dim,
paragraph(L"Hello world! Here is an image:"), img1(),
paragraph(L" Here is a text "), text(L"red ") | color(Color::Red),
paragraph(L" A spinner "), spinner(6, i / 10)) |
border;
auto screen = Screen::Create(Dimension::Full());
Render(screen, document);
std::cout << reset_position;
screen.Print();
reset_position = screen.ResetPosition();
std::this_thread::sleep_for(0.01s);
}
return 0;
}
// Copyright 2020 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in
// the LICENSE file.