FTXUI/src/ftxui/dom/spinner.cpp

270 lines
5.1 KiB
C++
Raw Normal View History

2019-01-07 05:28:15 +08:00
#include "ftxui/dom/elements.hpp"
2020-03-23 05:32:44 +08:00
#include "ftxui/dom/node.hpp"
2019-01-07 05:28:15 +08:00
namespace ftxui {
2019-01-07 05:28:15 +08:00
static const std::vector<std::vector<std::vector<std::wstring>>> elements = {
{
2020-03-23 05:32:44 +08:00
{L"Replaced by the gauge"},
},
{
{L". "},
{L".. "},
{L"..."},
2019-01-07 05:28:15 +08:00
},
{
2020-03-23 05:32:44 +08:00
{L"|"},
{L"/"},
{L"-"},
{L"\\"},
2019-01-07 05:28:15 +08:00
},
{
2020-03-23 05:32:44 +08:00
{L"+"},
{L"x"},
2019-01-07 05:28:15 +08:00
},
{
2020-03-23 05:32:44 +08:00
{L"| "},
{L"|| "},
{L"|||"},
2019-01-07 05:28:15 +08:00
},
{
2020-03-23 05:32:44 +08:00
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
2019-01-07 05:28:15 +08:00
},
{
2020-03-23 05:32:44 +08:00
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
2019-01-07 05:28:15 +08:00
},
{
2020-03-23 05:32:44 +08:00
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
2019-01-07 05:28:15 +08:00
},
{
2020-03-23 05:32:44 +08:00
{L""},
{L""},
{L""},
{L""},
},
2019-01-07 05:28:15 +08:00
{
2020-03-23 05:32:44 +08:00
{L""},
{L""},
{L""},
{L""},
2019-01-07 05:28:15 +08:00
},
{
2020-03-23 05:32:44 +08:00
{L""},
{L""},
{L""},
{L""},
2019-01-07 05:28:15 +08:00
},
{
2020-03-23 05:32:44 +08:00
{L""},
{L""},
{L""},
{L""},
},
{
{L""},
{L""},
{L""},
{L""},
},
{
{L""},
{L""},
{L""},
},
{
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
},
{
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
},
{
{L"(*----------)"}, {L"(-*---------)"}, {L"(--*--------)"},
{L"(---*-------)"}, {L"(----*------)"}, {L"(-----*-----)"},
{L"(------*----)"}, {L"(-------*---)"}, {L"(--------*--)"},
{L"(---------*-)"}, {L"(----------*)"}, {L"(---------*-)"},
{L"(--------*--)"}, {L"(-------*---)"}, {L"(------*----)"},
{L"(-----*-----)"}, {L"(----*------)"}, {L"(---*-------)"},
{L"(--*--------)"}, {L"(-*---------)"},
},
{
{L"[ ]"},
{L"[= ]"},
{L"[== ]"},
{L"[=== ]"},
{L"[==== ]"},
{L"[===== ]"},
{L"[======]"},
{L"[===== ]"},
{L"[==== ]"},
{L"[=== ]"},
{L"[== ]"},
{L"[= ]"},
},
{
{L"[ ]"},
{L"[= ]"},
{L"[== ]"},
{L"[=== ]"},
{L"[==== ]"},
{L"[===== ]"},
{L"[======]"},
{L"[ =====]"},
{L"[ ====]"},
{L"[ ===]"},
{L"[ ==]"},
{L"[ =]"},
},
{
{L"[== ]"},
{L"[== ]"},
{L"[== ]"},
{L"[== ]"},
{L"[== ]"},
{L" [== ]"},
{L"[ == ]"},
{L"[ == ]"},
{L"[ ==]"},
{L"[ ==]"},
{L"[ ==]"},
{L"[ ==]"},
{L"[ ==]"},
{L"[ ==] "},
{L"[ == ]"},
{L"[ == ]"},
},
{{
L" ─╮",
L"",
L" ",
},
{
L"",
L"",
L"",
},
{
L" ",
L"",
L" ─╯",
},
{
L" ",
L" ",
L"╰─╯",
},
{
L" ",
L"",
L"╰─ ",
},
{
L"",
L"",
L"",
},
{
L"╭─ ",
L"",
L" ",
},
{
L"╭─╮",
L" ",
L" ",
}},
{{
L" /\\O ",
L" /\\/ ",
L" /\\ ",
L" / \\ ",
L"LOL LOL",
},
{
L" _O ",
L" //|_ ",
L" | ",
L" /| ",
L" LLOL ",
},
{
L" O ",
L" /_ ",
L" |\\ ",
L" / | ",
L" LOLLOL ",
}}};
2019-01-07 05:28:15 +08:00
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
///every "step".
/// @ingroup dom
Element spinner(int charset_index, size_t image_index) {
if (charset_index == 0) {
image_index %= 40;
if (image_index > 20)
image_index = 40 - image_index;
return gauge(image_index * 0.05);
2019-01-07 05:28:15 +08:00
}
2020-08-16 08:24:50 +08:00
charset_index %= elements.size();
image_index %= elements[charset_index].size();
2019-01-07 05:28:15 +08:00
std::vector<Element> lines;
2020-08-16 08:24:50 +08:00
for (const auto& it : elements[charset_index][image_index])
2019-01-07 05:28:15 +08:00
lines.push_back(text(it));
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.