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. 保留所有權利。
2// 本原始碼的使用受 MIT 授權條款約束,該條款可在
3// 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 使渲染區域可點擊並使用網路瀏覽器開啟。
37/// 當用戶點擊時,連結將被開啟。
38/// 此功能僅在有限的終端模擬器中受支援。
39/// List: https://github.com/Alhadis/OSC8-Adoption/
40/// @param link 連結
41/// @param child 輸入元素。
42/// @return 帶有連結的輸出元素。
43/// @ingroup dom
44///
45/// ### 範例
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 使用超連結裝飾。
56/// 當用戶點擊時,連結將被開啟。
57/// 此功能僅在有限的終端模擬器中受支援。
58/// List: https://github.com/Alhadis/OSC8-Adoption/
59/// @param link 用於將用戶重定向到的連結。
60/// @return 應用超連結的裝飾器。
61/// @ingroup dom
62///
63/// ### 範例
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
friend void Render(Screen &screen, Node *node, Selection &selection)
Decorator hyperlink(std::string link)
使用超連結裝飾。 當用戶點擊時,連結將被開啟。 此功能僅在有限的終端模擬器中受支援。 List: https://github.com/Alhadis/OSC8-Adoption/
Definition hyperlink.cpp:70
FTXUI 的 ftxui:: 命名空間
Definition animation.hpp:10
std::function< Element(Element)> Decorator
Definition elements.hpp:24
std::shared_ptr< Node > Element
Definition elements.hpp:22
void Render(Screen &screen, const Element &element)