ArthurSonzogni / FTXUI

:computer: C++ Functional Terminal User Interface. :heart:
MIT License
6.69k stars 401 forks source link

How to highlight text inside ftxui::text() or ftxui::paragraph() #876

Open DanuulKa03 opened 3 months ago

DanuulKa03 commented 3 months ago

I know that you can colorize the font like this

ftxui::text("TEXT.") | ftxui::color(ftxui::Color::Red) | ftxui::bgcolor(ftxui::Color::Yellow)

Let's say that I made a Renderer() of this text somewhere.

int main() {
    auto document = vbox({
        ftxui::text("Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.")
    });

    auto screen = Screen::Create(Dimension::Full(), Dimension::Fit);
    Render(screen, document);
    screen.Print();

    return 0;
}

If I want to highlight the name "Ipsum is simply", is this the only way I can do it?

int main() {
    auto document = vbox({
        ftxui::text("Lorem"), ftxui::text("Ipsum is simply") | ftxui::color(ftxui::Color::Red) | ftxui::bgcolor(ftxui::Color::Yellow), ftxui::text("dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.") | ftxui::color(ftxui::Color::Red) | ftxui::bgcolor(ftxui::Color::Yellow)
    });

    auto screen = Screen::Create(Dimension::Full(), Dimension::Fit);
    Render(screen, document);
    screen.Print();

    return 0;
}

This method doesn't work for me, so I would like to know if there is a way to highlight already pasted text?

ArthurSonzogni commented 2 months ago

Unfortunately, there isn't any builtin tools for this.

You can write your own Element and directly assign colors to cells, but I understand this would be a lot of work.