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. All rights reserved.
2// このソースコードの使用は、LICENSEファイルにあるMITライセンスに準拠しています。
3#include <cstdint> // for uint8_t
4#include <memory> // for make_shared
5#include <string> // for string
6#include <utility> // for move
7
8#include "ftxui/dom/elements.hpp" // for Element, Decorator, hyperlink
9#include "ftxui/dom/node_decorator.hpp" // for NodeDecorator
10#include "ftxui/screen/box.hpp" // for Box
11#include "ftxui/screen/screen.hpp" // for Screen, Pixel
12
13namespace ftxui {
14
15namespace {
16class Hyperlink : public NodeDecorator {
17 public:
18 Hyperlink(Element child, std::string link)
19 : NodeDecorator(std::move(child)), link_(std::move(link)) {}
20
21 void Render(Screen& screen) override {
22 const uint8_t hyperlink_id = screen.RegisterHyperlink(link_);
23 for (int y = box_.y_min; y <= box_.y_max; ++y) {
24 for (int x = box_.x_min; x <= box_.x_max; ++x) {
25 screen.PixelAt(x, y).hyperlink = hyperlink_id;
26 }
27 }
29 }
30
31 std::string link_;
32};
33} // namespace
34
35/// @brief ウェブブラウザを使用してレンダリングされた領域をクリック可能にします。
36/// ユーザーがクリックするとリンクが開きます。
37/// これは、限られたターミナルエミュレータでのみサポートされています。
38/// リスト: https://github.com/Alhadis/OSC8-Adoption/
39/// @param link リンク
40/// @param child 入力要素。
41/// @return リンクを持つ出力要素。
42/// @ingroup dom
43///
44/// ### 例
45///
46/// ```cpp
47/// Element document =
48/// hyperlink("https://github.com/ArthurSonzogni/FTXUI", "link");
49/// ```
50Element hyperlink(std::string link, Element child) {
51 return std::make_shared<Hyperlink>(std::move(child), std::move(link));
52}
53
54/// @brief ハイパーリンクを使用して装飾します。
55/// ユーザーがクリックするとリンクが開きます。
56/// これは、限られたターミナルエミュレータでのみサポートされています。
57/// リスト: https://github.com/Alhadis/OSC8-Adoption/
58/// @param link ユーザーをリダイレクトするリンク。
59/// @return ハイパーリンクを適用するデコレータ。
60/// @ingroup dom
61///
62/// ### 例
63///
64/// ```cpp
65/// Element document =
66/// text("red") | hyperlink("https://github.com/Arthursonzogni/FTXUI");
67/// ```
68// NOLINTNEXTLINE
69Decorator hyperlink(std::string link) {
70 return [link](Element child) { return hyperlink(link, std::move(child)); };
71}
72
73} // namespace ftxui
friend void Render(Screen &screen, Node *node, Selection &selection)
Definition node.cpp:96
Decorator hyperlink(std::string link)
ハイパーリンクを使用して装飾します。 ユーザーがクリックするとリンクが開きます。 これは、限られたターミナルエミュレータでのみサポートされています。 リスト: https://github....
Definition hyperlink.cpp:69
void Render(Screen &screen, const Element &element)
要素をftxui::Screenに表示します。
Definition node.cpp:84
FTXUI ftxui:: 名前空間
Definition animation.hpp:9
std::function< Element(Element)> Decorator
Definition elements.hpp:23
std::shared_ptr< Node > Element
Definition elements.hpp:21