This commit is contained in:
Pranav Srinivas KumaR
2019-12-04 21:10:58 -06:00
parent 9f8cd55762
commit e1dbc1ed8a
7 changed files with 60 additions and 60 deletions

View File

@@ -3,7 +3,7 @@
</p>
<p align="center">
<a href="https://github.com/p-ranav/indica/blob/master/LICENSE">
<a href="https://github.com/p-ranav/indicators/blob/master/LICENSE">
<img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="license"/>
</a>
<img src="https://img.shields.io/badge/version-1.0-blue.svg?cacheSeconds=2592000" alt="version"/>
@@ -16,19 +16,19 @@
# Highlights
* Thread-safe `ProgressBar` and `ProgressSpinner` classes
* Header-only library. Grab a copy of `include/indica`
* Header-only library. Grab a copy of `include/indicators`
* MIT License
* Source for the above GIF can be found [here](demo/demo.cpp)
# Progress bar
To introduce a progress bar in your application, include `indica/progress_bar.hpp` and create a `ProgressBar` object.
To introduce a progress bar in your application, include `indicators/progress_bar.hpp` and create a `ProgressBar` object.
```cpp
#include <indica/progress_bar.hpp>
#include <indicators/progress_bar.hpp>
int main() {
indica::ProgressBar bar;
indicators::ProgressBar bar;
return 0;
}
```
@@ -43,10 +43,10 @@ Here's the general structure of a progress bar:
Each of these elements (and more) can be configured using the ProgressBar API. Here's an example configuration:
```cpp
#include <indica/progress_bar.hpp>
#include <indicators/progress_bar.hpp>
int main() {
indica::ProgressBar bar;
indicators::ProgressBar bar;
// Configure the bar
bar.set_bar_width(50);
@@ -56,7 +56,7 @@ int main() {
bar.fill_bar_remainder_with(" ");
bar.end_bar_with("]");
bar.set_postfix_text("Getting started");
bar.set_foreground_color(indica::Color::GREEN);
bar.set_foreground_color(indicators::Color::GREEN);
// Update bar state
@@ -73,12 +73,12 @@ From application-level code, there are two ways in which you can update this pro
You can update the progress bar using `bar.tick()` which increments progress by exactly `1%`.
```cpp
#include <indica/progress_bar.hpp>
#include <indicators/progress_bar.hpp>
#include <thread>
#include <chrono>
int main() {
indica::ProgressBar bar;
indicators::ProgressBar bar;
// Configure the bar
bar.set_bar_width(50);
@@ -88,7 +88,7 @@ int main() {
bar.fill_bar_remainder_with(" ");
bar.end_bar_with("]");
bar.set_postfix_text("Getting started");
bar.set_foreground_color(indica::Color::GREEN);
bar.set_foreground_color(indicators::Color::GREEN);
// Update bar state
while (true) {
@@ -109,12 +109,12 @@ The above code will print a progress bar that goes from 0 to 100% at the rate of
If you'd rather control progress of the bar in discrete steps, consider using `bar.set_progress(value)`. Example:
```cpp
#include <indica/progress_bar.hpp>
#include <indicators/progress_bar.hpp>
#include <thread>
#include <chrono>
int main() {
indica::ProgressBar bar;
indicators::ProgressBar bar;
// Configure the bar
bar.set_bar_width(50);
@@ -124,7 +124,7 @@ int main() {
bar.fill_bar_remainder_with(" ");
bar.end_bar_with("]");
bar.set_postfix_text("Getting started");
bar.set_foreground_color(indica::Color::GREEN);
bar.set_foreground_color(indicators::Color::GREEN);
// Update bar state
size_t i = 0;
@@ -143,19 +143,19 @@ The above code will print a progress bar that goes from 0 to 100% at the rate of
## Multi-threaded Example
```cpp
#include <indica/progress_bar.hpp>
#include <indicators/progress_bar.hpp>
#include <vector>
int main() {
indica::ProgressBar bar;
indicators::ProgressBar bar;
bar.set_bar_width(50);
bar.start_bar_with("[");
bar.fill_bar_progress_with("■");
bar.lead_bar_progress_with("■");
bar.fill_bar_remainder_with("-");
bar.end_bar_with("]");
bar.set_foreground_color(indica::Color::YELLOW);
bar.set_foreground_color(indicators::Color::YELLOW);
// As configured, the bar will look like this:
//
@@ -212,13 +212,13 @@ For more examples, checkout the examples in the `samples/` directory.
# Progress Spinner
To introduce a progress spinner in your application, include `indica/progress_spinner.hpp` and create a `ProgressSpinner` object.
To introduce a progress spinner in your application, include `indicators/progress_spinner.hpp` and create a `ProgressSpinner` object.
```cpp
#include <indica/progress_spinner.hpp>
#include <indicators/progress_spinner.hpp>
int main() {
indica::ProgressSpinner spinner;
indicators::ProgressSpinner spinner;
return 0;
}
```
@@ -232,15 +232,15 @@ Here's the general structure of a progress spinner:
Each of these elements (and more) can be configured using the ProgressSpinner API. Here's an example configuration:
```cpp
#include <indica/progress_spinner.hpp>
#include <indicators/progress_spinner.hpp>
int main() {
indica::ProgressSpinner spinner;
indicators::ProgressSpinner spinner;
// Configure the spinner
spinner.set_prefix_text(" ");
spinner.set_postfix_text("Checking credentials");
spinner.set_foreground_color(indica::Color::YELLOW);
spinner.set_foreground_color(indicators::Color::YELLOW);
spinner.set_spinner_states({"⠈", "⠐", "⠠", "⢀", "⡀", "⠄", "⠂", "⠁"});
// Update spinner state
@@ -252,21 +252,21 @@ int main() {
ProgressSpinner has a vector of strings: `spinner_states`. At each update, the spinner will pick the next string from this sequence to print to the console. The spinner state can be updated similarly to ProgressBars: Using either `tick()` or `set_progress(value)`.
```cpp
#include <indica/progress_spinner.hpp>
#include <indicators/progress_spinner.hpp>
int main() {
indica::ProgressSpinner spinner;
indicators::ProgressSpinner spinner;
// Configure the spinner
spinner.set_postfix_text("Checking credentials");
spinner.set_foreground_color(indica::Color::YELLOW);
spinner.set_foreground_color(indicators::Color::YELLOW);
spinner.set_spinner_states({"⠈", "⠐", "⠠", "⢀", "⡀", "⠄", "⠂", "⠁"});
// Update spinner state
auto job = [&spinner]() {
while (true) {
if (spinner.is_completed()) {
spinner.set_foreground_color(indica::Color::GREEN);
spinner.set_foreground_color(indicators::Color::GREEN);
spinner.set_prefix_text("✔");
spinner.hide_spinner();
spinner.hide_percentage();

View File

@@ -1,5 +1,5 @@
#include <indica/progress_bar.hpp>
#include <indica/progress_spinner.hpp>
#include <indicators/progress_bar.hpp>
#include <indicators/progress_spinner.hpp>
#include <vector>
int main() {
@@ -11,14 +11,14 @@ int main() {
//
// PROGRESS BAR 1
//
indica::ProgressBar p;
indicators::ProgressBar p;
p.set_bar_width(50);
p.start_bar_with("[");
p.fill_bar_progress_with("");
p.lead_bar_progress_with("");
p.fill_bar_remainder_with(" ");
p.end_bar_with(" ]");
p.set_foreground_color(indica::Color::YELLOW);
p.set_foreground_color(indicators::Color::YELLOW);
std::atomic<size_t> index{0};
std::vector<std::string> status_text = {"Rocket.exe is not responding",
@@ -49,7 +49,7 @@ int main() {
//
// PROGRESS BAR 2
//
indica::ProgressBar p;
indicators::ProgressBar p;
p.set_bar_width(40);
p.set_prefix_text("Reading package list... ");
p.start_bar_with("");
@@ -57,7 +57,7 @@ int main() {
p.lead_bar_progress_with("");
p.fill_bar_remainder_with("");
p.end_bar_with("");
p.set_foreground_color(indica::Color::WHITE);
p.set_foreground_color(indicators::Color::WHITE);
p.hide_percentage();
auto job = [&p]() {
while (true) {
@@ -79,7 +79,7 @@ int main() {
//
// PROGRESS BAR 3
//
indica::ProgressBar p;
indicators::ProgressBar p;
p.set_bar_width(50);
p.start_bar_with("[");
p.fill_bar_progress_with("=");
@@ -87,7 +87,7 @@ int main() {
p.fill_bar_remainder_with(" ");
p.end_bar_with("]");
p.set_postfix_text("Getting started");
p.set_foreground_color(indica::Color::GREEN);
p.set_foreground_color(indicators::Color::GREEN);
auto job = [&p]() {
while (true) {
auto ticks = p.current();
@@ -114,14 +114,14 @@ int main() {
// PROGRESS BAR 4
//
std::vector<std::string> lead_spinner{"", "", "", "", "", "", "", "", "", ""};
indica::ProgressBar p4;
indicators::ProgressBar p4;
p4.set_bar_width(40);
p4.start_bar_with("");
p4.fill_bar_progress_with("");
p4.lead_bar_progress_with("");
p4.fill_bar_remainder_with(" ");
p4.end_bar_with("");
p4.set_foreground_color(indica::Color::CYAN);
p4.set_foreground_color(indicators::Color::CYAN);
p4.set_postfix_text("Restoring system state");
p4.hide_percentage();
std::atomic<size_t> index4{0};
@@ -132,7 +132,7 @@ int main() {
index4 += 1;
if (p4.current() + 2 >= 100) {
std::cout << std::endl;
p4.set_foreground_color(indica::Color::RED);
p4.set_foreground_color(indicators::Color::RED);
p4.set_prefix_text("{ ERROR }");
p4.start_bar_with("");
p4.fill_bar_progress_with("");
@@ -157,7 +157,7 @@ int main() {
//
// GOING BACKWARDS
//
indica::ProgressBar p;
indicators::ProgressBar p;
p.set_bar_width(50);
p.start_bar_with("[");
p.fill_bar_progress_with("");
@@ -165,7 +165,7 @@ int main() {
p.fill_bar_remainder_with("-");
p.end_bar_with("]");
p.set_progress(100);
p.set_foreground_color(indica::Color::WHITE);
p.set_foreground_color(indicators::Color::WHITE);
p.set_postfix_text("Reverting system restore");
std::atomic<size_t> progress{100};
auto job = [&p, &progress]() {
@@ -189,15 +189,15 @@ int main() {
//
// PROGRESS BAR 5
//
indica::ProgressSpinner p;
indicators::ProgressSpinner p;
p.set_prefix_text("");
p.set_postfix_text("Checking credentials");
p.set_foreground_color(indica::Color::YELLOW);
p.set_foreground_color(indicators::Color::YELLOW);
p.set_spinner_states({"", "", "", "", "", "", "", ""});
auto job = [&p]() {
while (true) {
if (p.is_completed()) {
p.set_foreground_color(indica::Color::GREEN);
p.set_foreground_color(indicators::Color::GREEN);
p.set_prefix_text("");
p.hide_spinner();
p.hide_percentage();
@@ -218,10 +218,10 @@ int main() {
//
// PROGRESS BAR 6
//
indica::ProgressSpinner p;
indicators::ProgressSpinner p;
p.set_prefix_text(" - ");
p.set_postfix_text("Searching for the Moon");
p.set_foreground_color(indica::Color::WHITE);
p.set_foreground_color(indicators::Color::WHITE);
p.set_spinner_states({"", "", "", ""});
p.hide_percentage();
auto job = [&p]() {
@@ -259,7 +259,7 @@ int main() {
//
// NESTED PROGRESS BAR
//
indica::ProgressBar p2;
indicators::ProgressBar p2;
p2.set_bar_width(30);
p2.set_prefix_text(" - ");
p2.start_bar_with("🌎");
@@ -268,7 +268,7 @@ int main() {
p2.fill_bar_remainder_with(" ");
p2.end_bar_with("🌑");
p2.set_postfix_text("Achieved low-Earth orbit");
p2.set_foreground_color(indica::Color::WHITE);
p2.set_foreground_color(indicators::Color::WHITE);
std::vector<std::string> ship_trail{"", "", "", "", "", "", "", ""};
std::atomic<int> ship_trail_index{0};
auto job2 = [&p2, &ship_trail_index, &ship_trail]() {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.8 KiB

After

Width:  |  Height:  |  Size: 7.2 KiB

View File

@@ -1,5 +1,5 @@
/*
Activity Indicator for Modern C++
Activity Indicators for Modern C++
https://github.com/p-ranav/indica
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
@@ -25,8 +25,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#include <indica/termcolor.hpp>
#include <indicators/termcolor.hpp>
namespace indica {
namespace indicators {
enum class Color { GREY, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE };
}

View File

@@ -1,6 +1,6 @@
/*
Activity Indicator for Modern C++
https://github.com/p-ranav/indica
Activity Indicators for Modern C++
https://github.com/p-ranav/indicators
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
@@ -26,13 +26,13 @@ SOFTWARE.
*/
#pragma once
#include <atomic>
#include <indica/color.hpp>
#include <indicators/color.hpp>
#include <iostream>
#include <mutex>
#include <string>
#include <thread>
namespace indica {
namespace indicators {
class ProgressBar {
public:
@@ -187,4 +187,4 @@ private:
}
};
} // namespace indica
} // namespace indicators

View File

@@ -1,6 +1,6 @@
/*
Activity Indicator for Modern C++
https://github.com/p-ranav/indica
Activity Indicators for Modern C++
https://github.com/p-ranav/indicators
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
@@ -26,14 +26,14 @@ SOFTWARE.
*/
#pragma once
#include <atomic>
#include <indica/color.hpp>
#include <indicators/color.hpp>
#include <iostream>
#include <mutex>
#include <string>
#include <thread>
#include <vector>
namespace indica {
namespace indicators {
class ProgressSpinner {
public:
@@ -156,4 +156,4 @@ private:
}
};
} // namespace indica
} // namespace indicators