FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
hyperlink.cpp
Go to the documentation of this file.
1// Copyright 2023 Arthur Sonzogni. Todos los derechos reservados.
2// El uso de este código fuente se rige por la licencia MIT que se puede encontrar en
3// el archivo 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 }
30 }
31
32 std::string link_;
33};
34} // namespace
35
36/// @brief Hace que el área renderizada sea clicable usando un navegador web.
37/// El enlace se abrirá cuando el usuario haga clic en él.
38/// Esto solo es compatible con un conjunto limitado de emuladores de terminal.
39/// Lista: https://github.com/Alhadis/OSC8-Adoption/
40/// @param link El enlace
41/// @param child El elemento de entrada.
42/// @return El elemento de salida con el enlace.
43/// @ingroup dom
44///
45/// ### Ejemplo
46///
47/// ```cpp
48/// Element document =
49/// hyperlink("https://github.com/ArthurSonzogni/FTXUI", "link");
50/// ```
51Element hyperlink(std::string link, Element child) {
52 return std::make_shared<Hyperlink>(std::move(child), std::move(link));
53}
54
55/// @brief Decora usando un hipervínculo.
56/// El enlace se abrirá cuando el usuario haga clic en él.
57/// Esto solo es compatible con un conjunto limitado de emuladores de terminal.
58/// Lista: https://github.com/Alhadis/OSC8-Adoption/
59/// @param link El enlace al que se redirigirá a los usuarios.
60/// @return El Decorator que aplica el hipervínculo.
61/// @ingroup dom
62///
63/// ### Ejemplo
64///
65/// ```cpp
66/// Element document =
67/// text("red") | hyperlink("https://github.com/Arthursonzogni/FTXUI");
68/// ```
69// NOLINTNEXTLINE
70Decorator hyperlink(std::string link) {
71 return [link](Element child) { return hyperlink(link, std::move(child)); };
72}
73
74} // namespace ftxui
auto screen
friend void Render(Screen &screen, Node *node, Selection &selection)
Definition node.cpp:96
Decorator hyperlink(std::string link)
Decora usando un hipervínculo. El enlace se abrirá cuando el usuario haga clic en él....
Definition hyperlink.cpp:70
void Render(Screen &screen, const Element &element)
Muestra un elemento en un ftxui::Screen.
Definition node.cpp:84
El espacio de nombres ftxui:: de FTXUI.
Definition animation.hpp:10
std::function< Element(Element)> Decorator
Definition elements.hpp:24
std::shared_ptr< Node > Element
Definition elements.hpp:22