FTXUI 6.1.9
C++ functional terminal UI.
Chargement...
Recherche...
Aucune correspondance
hyperlink.cpp
Aller à la documentation de ce fichier.
1// Copyright 2023 Arthur Sonzogni. Tous droits réservés.
2// L'utilisation de ce code source est régie par la licence MIT que l'on peut trouver dans
3// le fichier LICENSE.
4#include <cstdint> // for uint8_t
5#include <memory> // for make_shared
6#include <string> // for string
7#include <utility> // for move
8
9#include "ftxui/dom/elements.hpp" // for Element, Decorator, hyperlink
10#include "ftxui/dom/node_decorator.hpp" // for NodeDecorator
11#include "ftxui/screen/box.hpp" // for Box
12#include "ftxui/screen/screen.hpp" // for Screen, Pixel
13
14namespace ftxui {
15
16namespace {
17class Hyperlink : public NodeDecorator {
18 public:
19 Hyperlink(Element child, std::string link)
20 : NodeDecorator(std::move(child)), link_(std::move(link)) {}
21
22 void Render(Screen& screen) override {
23 const uint8_t hyperlink_id = screen.RegisterHyperlink(link_);
24 for (int y = box_.y_min; y <= box_.y_max; ++y) {
25 for (int x = box_.x_min; x <= box_.x_max; ++x) {
26 screen.PixelAt(x, y).hyperlink = hyperlink_id;
27 }
28 }
29 NodeDecorator::Render(screen);
30 }
31
32 std::string link_;
33};
34/// @brief Rend la zone affichée cliquable à l'aide d'un navigateur web.
35/// Le lien sera ouvert lorsque l'utilisateur cliquera dessus.
36/// Ceci n'est pris en charge que par un ensemble limité d'émulateurs de terminal.
37/// Liste: https://github.com/Alhadis/OSC8-Adoption/
38/// @param link Le lien
39/// @param child L'élément d'entrée.
40/// @return L'élément de sortie avec le lien.
41/// @ingroup dom
42///
43/// ### Exemple
44///
45/// ```cpp
46/// Element document =
47/// hyperlink("https://github.com/ArthurSonzogni/FTXUI", "link");
48/// ```
49Element hyperlink(std::string link, Element child) {
50 return std::make_shared<Hyperlink>(std::move(child), std::move(link));
51}
52
53/// @brief Décore avec un hyperlien.
54/// Le lien sera ouvert lorsque l'utilisateur cliquera dessus.
55/// Ceci n'est pris en charge que par un ensemble limité d'émulateurs de terminal.
56/// Liste: https://github.com/Alhadis/OSC8-Adoption/
57/// @param link Le lien vers lequel rediriger les utilisateurs.
58/// @return Le Décorateur appliquant l'hyperlien.
59/// @ingroup dom
60///
61/// ### Exemple
62///
63/// ```cpp
64/// Element document =
65/// text("red") | hyperlink("https://github.com/Arthursonzogni/FTXUI");
66/// ```
67// NOLINTNEXTLINE
68Decorator hyperlink(std::string link) {
69 return [link](Element child) { return hyperlink(link, std::move(child)); };
70}
71
72} // namespace ftxui
auto screen
void Render(Screen &screen, const Element &element)
Affiche un élément sur un ftxui::Screen.
Definition node.cpp:83
L'espace de noms FTXUI ftxui::
Definition animation.hpp:10
std::function< Element(Element)> Decorator
Definition elements.hpp:24
std::shared_ptr< Node > Element
Definition elements.hpp:22
Decorator hyperlink(std::string link)