A very simple, easy-to-use, and single-header-only C++ library for console based indicators (loading spinners)
Type | Preview |
---|---|
0 | ![]() |
1 | ![]() |
2 | ![]() |
3 | ![]() |
4 | ![]() |
5 | ![]() |
6 | ![]() |
#include <iostream>
#include <chrono>
#include "indicators.hpp"
using namespace std::chrono;
int main()
{
auto spin = std::make_unique<indicator::indicator>(200ms, 0);
spin->start();
std::this_thread::sleep_for(std::chrono::milliseconds(5000));
spin->stop();
return 0;
}
#include <iostream>
#include <chrono>
#include "indicators.hpp"
using namespace std::chrono;
int main()
{
auto spin = std::make_unique<indicator::indicator>(200ms, 0, "Finished loading some data", "Process info: ", " Loading data...");
spin->start();
std::this_thread::sleep_for(std::chrono::milliseconds(5000));
spin->stop();
return 0;
}
You can decide if you want to hide the loading line after process or keep it
by setting hide_on_end
parameter to true
or false
in indicator
constructor. Example:
// this hides loading line after process
auto spin = std::make_unique<indicator::indicator>(200ms, 0, "Finished loading some data", "Process info: ", " Loading data...", true);
// this keeps the loading line
auto spin = std::make_unique<indicator::indicator>(200ms, 0, "Finished loading some data", "Process info: ", " Loading data...", false);
std::vector<std::string> custom_indicator =
{"aaaaa", "aaaa ", "aaa ", "aa ", "a ", " ", "aa ", "aaa ", "aaaa ", "aaaaa", " aaaa", " aaa", " aa", " a", " ", " aa", " aaa", " aaaa"};
auto spin = std::make_unique<indicator::indicator>(100ms, 0, "Final msg", "prefix", "suffix", false, custom_indicator);
You can change prefix, suffix, and final message during the indicator process as well, not just on initialization. Or even changing the timer interval (delay value). Example: (it can be useful for stuff like downloading files or something that needs updating messages like pecent or speed)
auto spin = std::make_unique<indicator::indicator>(200ms, 0);
spin->start();
spin->set_suffix(" Downloading files...");
spin->set_prefix("Download info: ");
spin->set_end_msg("Okay seems like we're done");
spin->set_delay(500ms);