FTXUI 6.1.9
C++ functional terminal UI.
载入中...
搜索中...
未找到
src/ftxui/dom/spinner.cpp
浏览该文件的文档.
1// Copyright 2020 Arthur Sonzogni. All rights reserved.
2// 本源代码的使用受 MIT 许可证的约束,该许可证可在 LICENSE 文件中找到。
3#include <cstddef> // for size_t
4#include <string> // for basic_string, string
5#include <utility> // for move
6#include <vector> // for vector, __alloc_traits<>::value_type
7
8#include "ftxui/dom/elements.hpp" // for Element, gauge, text, vbox, spinner
9
10namespace ftxui {
11
12namespace {
13// NOLINTNEXTLINE
14const std::vector<std::vector<std::vector<std::string>>> elements = {
15 {
16 {"Replaced by the gauge"},
17 },
18 {
19 {". "},
20 {".. "},
21 {"..."},
22 },
23 {
24 {"|"},
25 {"/"},
26 {"-"},
27 {"\\"},
28 },
29 {
30 {"+"},
31 {"x"},
32 },
33 {
34 {"| "},
35 {"|| "},
36 {"|||"},
37 },
38 {
39 {"←"},
40 {"↖"},
41 {"↑"},
42 {"↗"},
43 {"→"},
44 {"↘"},
45 {"↓"},
46 {"↙"},
47 },
48 {
49 {"▁"},
50 {"▂"},
51 {"▃"},
52 {"▄"},
53 {"▅"},
54 {"▆"},
55 {"▇"},
56 {"█"},
57 {"▇"},
58 {"▆"},
59 {"▅"},
60 {"▄"},
61 {"▃"},
62 {"▁"},
63 },
64 {
65 {"▉"},
66 {"▊"},
67 {"▋"},
68 {"▌"},
69 {"▍"},
70 {"▎"},
71 {"▏"},
72 {"▎"},
73 {"▍"},
74 {"▌"},
75 {"▋"},
76 {"▊"},
77 },
78 {
79 {"▖"},
80 {"▘"},
81 {"▝"},
82 {"▗"},
83 },
84 {
85 {"◢"},
86 {"◣"},
87 {"◤"},
88 {"◥"},
89 },
90 {
91 {"◰"},
92 {"◳"},
93 {"◲"},
94 {"◱"},
95 },
96 {
97 {"◴"},
98 {"◷"},
99 {"◶"},
100 {"◵"},
101 },
102 {
103 {"◐"},
104 {"◓"},
105 {"◑"},
106 {"◒"},
107 },
108 {
109 {"◡"},
110 {"⊙"},
111 {"◠"},
112 },
113 {
114 {"⠁"},
115 {"⠂"},
116 {"⠄"},
117 {"⡀"},
118 {"⢀"},
119 {"⠠"},
120 {"⠐"},
121 {"⠈"},
122 },
123 {
124 {"⠋"},
125 {"⠙"},
126 {"⠹"},
127 {"⠸"},
128 {"⠼"},
129 {"⠴"},
130 {"⠦"},
131 {"⠧"},
132 {"⠇"},
133 {"⠏"},
134 },
135 {
136 {"(*----------)"}, {"(-*---------)"}, {"(--*--------)"},
137 {"(---*-------)"}, {"(----*------)"}, {"(-----*-----)"},
138 {"(------*----)"}, {"(-------*---)"}, {"(--------*--)"},
139 {"(---------*-)"}, {"(----------*)"}, {"(---------*-)"},
140 {"(--------*--)"}, {"(-------*---)"}, {"(------*----)"},
141 {"(-----*-----)"}, {"(----*------)"}, {"(---*-------)"},
142 {"(--*--------)"}, {"(-*---------)"},
143 },
144 {
145 {"[ ]"},
146 {"[= ]"},
147 {"[== ]"},
148 {"[=== ]"},
149 {"[==== ]"},
150 {"[===== ]"},
151 {"[======]"},
152 {"[===== ]"},
153 {"[==== ]"},
154 {"[=== ]"},
155 {"[== ]"},
156 {"[= ]"},
157 },
158 {
159 {"[ ]"},
160 {"[= ]"},
161 {"[== ]"},
162 {"[=== ]"},
163 {"[==== ]"},
164 {"[===== ]"},
165 {"[======]"},
166 {"[ =====]"},
167 {"[ ====]"},
168 {"[ ===]"},
169 {"[ ==]"},
170 {"[ =]"},
171 },
172 {
173 {"[== ]"},
174 {"[== ]"},
175 {"[== ]"},
176 {"[== ]"},
177 {"[== ]"},
178 {" [== ]"},
179 {"[ == ]"},
180 {"[ == ]"},
181 {"[ ==]"},
182 {"[ ==]"},
183 {"[ ==]"},
184 {"[ ==]"},
185 {"[ ==]"},
186 {"[ ==] "},
187 {"[ == ]"},
188 {"[ == ]"},
189 },
190 {
191 {
192 " ─╮",
193 " │",
194 " ",
195 },
196 {
197 " ╮",
198 " │",
199 " ╯",
200 },
201 {
202 " ",
203 " │",
204 " ─╯",
205 },
206 {
207 " ",
208 " ",
209 "╰─╯",
210 },
211 {
212 " ",
213 "│ ",
214 "╰─ ",
215 },
216 {
217 "╭ ",
218 "│ ",
219 "╰ ",
220 },
221 {
222 "╭─ ",
223 "│ ",
224 " ",
225 },
226 {
227 "╭─╮",
228 " ",
229 " ",
230 },
231 },
232 {
233 {
234 " /\\O ",
235 " /\\/",
236 " /\\ ",
237 " / \\ ",
238 "LOL LOL",
239 },
240 {
241 " _O ",
242 " //|_ ",
243 " | ",
244 " /| ",
245 " LLOL ",
246 },
247 {
248 " O ",
249 " /_ ",
250 " |\\ ",
251 " / | ",
252 " LOLLOL ",
253 },
254 },
255 {
256 {" ", "_______", " "},
257 {" ", "______/", " "},
258 {" _", "_____/ ", " "},
259 {" _ ", "____/ \\", " "},
260 {" _ ", "___/ \\ ", " \\"},
261 {" _ ", "__/ \\ ", " \\_"},
262 {" _ ", "_/ \\ ", " \\_/"},
263 {" _ ", "/ \\ _", " \\_/ "},
264 {"_ ", " \\ __", " \\_/ "},
265 {" ", "\\ ___", " \\_/ "},
266 {" ", " ___", "\\_/ "},
267 {" ", " _____", "_/ "},
268 {" ", " ______", "/ "},
269 {" ", "_______", " "},
270 },
271};
272
273} // namespace
274
275/// @brief 用于表示时间或事件的效果。这显示了一个 ASCII 艺术“视频”。
276/// @param charset_index “视频”的类型。
277/// @param image_index “视频”的“帧”。您需要为每个“步”增加此值。
278/// @ingroup dom
279Element spinner(int charset_index, size_t image_index) {
280 if (charset_index <= 0) {
281 const int progress_size = 40;
282 image_index %= progress_size;
283 if (image_index > progress_size / 2) {
284 image_index = progress_size - image_index;
285 }
286 return gauge(float(image_index) * 0.05F); // NOLINT
287 }
288 charset_index %= int(elements.size());
289 image_index %= int(elements[charset_index].size());
290 std::vector<Element> lines;
291 for (const auto& it : elements[charset_index][image_index]) {
292 lines.push_back(text(it));
293 }
294 return vbox(std::move(lines));
295}
296
297} // namespace ftxui
Decorator size(WidthOrHeight, Constraint, int value)
对元素大小应用约束。
Element spinner(int charset_index, size_t image_index)
用于表示时间或事件的效果。这显示了一个 ASCII 艺术“视频”。
Element text(std::wstring text)
显示一段Unicode文本。
Element vbox(Elements)
垂直一个接一个显示元素的容器。
#include "ftxui/component/component_base.hpp" // 用于 ComponentBase
std::shared_ptr< Node > Element
Element gauge(float progress)
绘制一个高清进度条。