FTXUI/src/ftxui/dom/spinner.cpp

303 lines
6.2 KiB
C++
Raw Normal View History

2022-03-31 08:17:43 +08:00
#include <cstddef> // for size_t
#include <memory> // for allocator, allocator_traits<>::value_type
#include <string> // for basic_string, string
#include <utility> // for move
#include <vector> // for vector, __alloc_traits<>::value_type
2021-05-02 02:40:35 +08:00
2021-05-10 02:32:27 +08:00
#include "ftxui/dom/elements.hpp" // for Element, gauge, text, vbox, spinner
2019-01-07 05:28:15 +08:00
namespace ftxui {
2019-01-07 05:28:15 +08:00
2022-03-31 08:17:43 +08:00
namespace {
// NOLINTNEXTLINE
const std::vector<std::vector<std::vector<std::string>>> elements = {
2019-01-07 05:28:15 +08:00
{
{"Replaced by the gauge"},
2020-03-23 05:32:44 +08:00
},
{
{". "},
{".. "},
{"..."},
2019-01-07 05:28:15 +08:00
},
{
{"|"},
{"/"},
{"-"},
{"\\"},
2019-01-07 05:28:15 +08:00
},
{
{"+"},
{"x"},
2019-01-07 05:28:15 +08:00
},
{
{"| "},
{"|| "},
{"|||"},
2019-01-07 05:28:15 +08:00
},
{
{""},
{""},
{""},
{""},
{""},
{""},
{""},
{""},
2019-01-07 05:28:15 +08:00
},
{
{""},
{""},
{""},
{""},
{""},
{""},
{""},
{""},
{""},
{""},
{""},
{""},
{""},
{""},
2019-01-07 05:28:15 +08:00
},
{
{""},
{""},
{""},
{""},
{""},
{""},
{""},
{""},
{""},
{""},
{""},
{""},
2019-01-07 05:28:15 +08:00
},
{
{""},
{""},
{""},
{""},
2020-03-23 05:32:44 +08:00
},
2019-01-07 05:28:15 +08:00
{
{""},
{""},
{""},
{""},
2019-01-07 05:28:15 +08:00
},
{
{""},
{""},
{""},
{""},
2019-01-07 05:28:15 +08:00
},
{
{""},
{""},
{""},
{""},
2020-03-23 05:32:44 +08:00
},
{
{""},
{""},
{""},
{""},
2020-03-23 05:32:44 +08:00
},
{
{""},
{""},
{""},
2020-03-23 05:32:44 +08:00
},
{
{""},
{""},
{""},
{""},
{""},
{""},
{""},
{""},
2020-03-23 05:32:44 +08:00
},
{
{""},
{""},
{""},
{""},
{""},
{""},
{""},
{""},
{""},
{""},
2020-03-23 05:32:44 +08:00
},
{
{"(*----------)"}, {"(-*---------)"}, {"(--*--------)"},
{"(---*-------)"}, {"(----*------)"}, {"(-----*-----)"},
{"(------*----)"}, {"(-------*---)"}, {"(--------*--)"},
{"(---------*-)"}, {"(----------*)"}, {"(---------*-)"},
{"(--------*--)"}, {"(-------*---)"}, {"(------*----)"},
{"(-----*-----)"}, {"(----*------)"}, {"(---*-------)"},
{"(--*--------)"}, {"(-*---------)"},
2020-03-23 05:32:44 +08:00
},
{
{"[ ]"},
{"[= ]"},
{"[== ]"},
{"[=== ]"},
{"[==== ]"},
{"[===== ]"},
{"[======]"},
{"[===== ]"},
{"[==== ]"},
{"[=== ]"},
{"[== ]"},
{"[= ]"},
2020-03-23 05:32:44 +08:00
},
{
{"[ ]"},
{"[= ]"},
{"[== ]"},
{"[=== ]"},
{"[==== ]"},
{"[===== ]"},
{"[======]"},
{"[ =====]"},
{"[ ====]"},
{"[ ===]"},
{"[ ==]"},
{"[ =]"},
2020-03-23 05:32:44 +08:00
},
{
{"[== ]"},
{"[== ]"},
{"[== ]"},
{"[== ]"},
{"[== ]"},
{" [== ]"},
{"[ == ]"},
{"[ == ]"},
{"[ ==]"},
{"[ ==]"},
{"[ ==]"},
{"[ ==]"},
{"[ ==]"},
{"[ ==] "},
{"[ == ]"},
{"[ == ]"},
2020-03-23 05:32:44 +08:00
},
{
{
" ─╮",
"",
" ",
},
{
"",
"",
"",
},
{
" ",
"",
" ─╯",
},
{
" ",
" ",
"╰─╯",
},
{
" ",
"",
"╰─ ",
},
{
"",
"",
"",
},
{
"╭─ ",
"",
" ",
},
{
"╭─╮",
" ",
" ",
},
},
{
{
" /\\O ",
" /\\/",
" /\\ ",
" / \\ ",
"LOL LOL",
},
{
" _O ",
" //|_ ",
" | ",
" /| ",
" LLOL ",
},
{
" O ",
" /_ ",
" |\\ ",
" / | ",
" LOLLOL ",
},
},
{
{" ", "_______", " "},
{" ", "______/", " "},
{" _", "_____/ ", " "},
{" _ ", "____/ \\", " "},
{" _ ", "___/ \\ ", " \\"},
{" _ ", "__/ \\ ", " \\_"},
{" _ ", "_/ \\ ", " \\_/"},
{" _ ", "/ \\ _", " \\_/ "},
{"_ ", " \\ __", " \\_/ "},
{" ", "\\ ___", " \\_/ "},
{" ", " ___", "\\_/ "},
{" ", " _____", "_/ "},
{" ", " ______", "/ "},
{" ", "_______", " "},
},
};
2019-01-07 05:28:15 +08:00
2022-03-31 08:17:43 +08:00
} // namespace
2020-08-16 08:24:50 +08:00
/// @brief Useful to represent the effect of time and/or events. This display an
/// ASCII art "video".
/// @param charset_index The type of "video".
/// @param image_index The "frame" of the video. You need to increase this for
2020-09-06 19:46:56 +08:00
/// every "step".
2020-08-16 08:24:50 +08:00
/// @ingroup dom
Element spinner(int charset_index, size_t image_index) {
if (charset_index == 0) {
2022-03-31 08:17:43 +08:00
const int progress_size = 40;
image_index %= progress_size;
if (image_index > progress_size / 2) {
image_index = progress_size - image_index;
}
return gauge(float(image_index) * 0.05F); // NOLINT
2019-01-07 05:28:15 +08:00
}
2022-03-31 08:17:43 +08:00
charset_index %= (int)elements.size();
image_index %= (int)elements[charset_index].size();
2019-01-07 05:28:15 +08:00
std::vector<Element> lines;
2022-03-31 08:17:43 +08:00
for (const auto& it : elements[charset_index][image_index]) {
2019-01-07 05:28:15 +08:00
lines.push_back(text(it));
2022-03-31 08:17:43 +08:00
}
2019-01-07 05:28:15 +08:00
return vbox(std::move(lines));
}
2020-02-12 04:44:55 +08:00
} // namespace ftxui
// Copyright 2020 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in
// the LICENSE file.