Skip to content

A very simple, easy-to-use, and single-header-only C++ library for console based indicators (loading spinners)

License

Notifications You must be signed in to change notification settings

AmyrAhmady/cpp-indicators

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cpp-indicators

A very simple, easy-to-use, and single-header-only C++ library for console based indicators (loading spinners)

Pre-made frames (indicator types)

Type Preview
0 ScreenShot
1 ScreenShot
2 ScreenShot
3 ScreenShot
4 ScreenShot
5 ScreenShot
6 ScreenShot

Examples

Basic usage:

#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;
}

Including prefix, suffix, and final message:

#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);

Indicator with custom frames

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);

Changes during the process

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);

About

A very simple, easy-to-use, and single-header-only C++ library for console based indicators (loading spinners)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages