mirror of
https://github.com/p-ranav/indicators.git
synced 2025-12-16 04:18:51 +08:00
Moved Color enum class out of progressbar
This commit is contained in:
6
include/indicator/color.hpp
Normal file
6
include/indicator/color.hpp
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <indicator/termcolor.hpp>
|
||||||
|
|
||||||
|
namespace indicator {
|
||||||
|
enum class Color { GREY, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE };
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <indicator/termcolor.hpp>
|
#include <indicator/color.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -10,8 +10,6 @@ namespace indicator {
|
|||||||
|
|
||||||
class ProgressBar {
|
class ProgressBar {
|
||||||
public:
|
public:
|
||||||
enum class Color { GREY, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE };
|
|
||||||
|
|
||||||
void set_foreground_color(Color color) {
|
void set_foreground_color(Color color) {
|
||||||
std::unique_lock<std::mutex> lock{_mutex};
|
std::unique_lock<std::mutex> lock{_mutex};
|
||||||
_foreground_color = color;
|
_foreground_color = color;
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ int main() {
|
|||||||
p1.lead_bar_progress_with("■");
|
p1.lead_bar_progress_with("■");
|
||||||
p1.fill_bar_remainder_with(" ");
|
p1.fill_bar_remainder_with(" ");
|
||||||
p1.end_bar_with("]");
|
p1.end_bar_with("]");
|
||||||
p1.set_foreground_color(indicator::ProgressBar::Color::YELLOW);
|
p1.set_foreground_color(indicator::Color::YELLOW);
|
||||||
|
|
||||||
std::atomic<size_t> index1{0};
|
std::atomic<size_t> index1{0};
|
||||||
std::vector<std::string> status_text1 = {"Rocket.exe is not responding",
|
std::vector<std::string> status_text1 = {"Rocket.exe is not responding",
|
||||||
@@ -91,7 +91,7 @@ int main() {
|
|||||||
p3.lead_bar_progress_with("");
|
p3.lead_bar_progress_with("");
|
||||||
p3.fill_bar_remainder_with("");
|
p3.fill_bar_remainder_with("");
|
||||||
p3.end_bar_with("");
|
p3.end_bar_with("");
|
||||||
p3.set_foreground_color(indicator::ProgressBar::Color::WHITE);
|
p3.set_foreground_color(indicator::Color::WHITE);
|
||||||
p3.hide_percentage();
|
p3.hide_percentage();
|
||||||
auto job3 = [&p3]() {
|
auto job3 = [&p3]() {
|
||||||
while (true) {
|
while (true) {
|
||||||
@@ -119,7 +119,7 @@ int main() {
|
|||||||
p2.fill_bar_remainder_with(" ");
|
p2.fill_bar_remainder_with(" ");
|
||||||
p2.end_bar_with("]");
|
p2.end_bar_with("]");
|
||||||
p2.set_postfix_text("Getting started");
|
p2.set_postfix_text("Getting started");
|
||||||
p2.set_foreground_color(indicator::ProgressBar::Color::GREEN);
|
p2.set_foreground_color(indicator::Color::GREEN);
|
||||||
auto job2 = [&p2]() {
|
auto job2 = [&p2]() {
|
||||||
while (true) {
|
while (true) {
|
||||||
auto ticks = p2.current();
|
auto ticks = p2.current();
|
||||||
@@ -151,7 +151,7 @@ int main() {
|
|||||||
p4.lead_bar_progress_with("");
|
p4.lead_bar_progress_with("");
|
||||||
p4.fill_bar_remainder_with(" ");
|
p4.fill_bar_remainder_with(" ");
|
||||||
p4.end_bar_with("");
|
p4.end_bar_with("");
|
||||||
p4.set_foreground_color(indicator::ProgressBar::Color::CYAN);
|
p4.set_foreground_color(indicator::Color::CYAN);
|
||||||
p4.set_postfix_text("Restoring system state");
|
p4.set_postfix_text("Restoring system state");
|
||||||
p4.hide_percentage();
|
p4.hide_percentage();
|
||||||
std::atomic<size_t> index4{0};
|
std::atomic<size_t> index4{0};
|
||||||
@@ -161,7 +161,7 @@ int main() {
|
|||||||
p4.lead_bar_progress_with(lead_spinner[index4 % lead_spinner.size()]);
|
p4.lead_bar_progress_with(lead_spinner[index4 % lead_spinner.size()]);
|
||||||
index4 += 1;
|
index4 += 1;
|
||||||
if (p4.current() + 2 >= 100) {
|
if (p4.current() + 2 >= 100) {
|
||||||
p4.set_foreground_color(indicator::ProgressBar::Color::RED);
|
p4.set_foreground_color(indicator::Color::RED);
|
||||||
p4.set_prefix_text("{ ERROR } ");
|
p4.set_prefix_text("{ ERROR } ");
|
||||||
p4.show_percentage();
|
p4.show_percentage();
|
||||||
p4.set_postfix_text("Failed to restore system");
|
p4.set_postfix_text("Failed to restore system");
|
||||||
@@ -189,7 +189,7 @@ int main() {
|
|||||||
p.fill_bar_remainder_with("-");
|
p.fill_bar_remainder_with("-");
|
||||||
p.end_bar_with("]");
|
p.end_bar_with("]");
|
||||||
p.set_progress(100);
|
p.set_progress(100);
|
||||||
p.set_foreground_color(indicator::ProgressBar::Color::WHITE);
|
p.set_foreground_color(indicator::Color::WHITE);
|
||||||
p.set_postfix_text("Reverting system restore");
|
p.set_postfix_text("Reverting system restore");
|
||||||
std::atomic<size_t> progress{100};
|
std::atomic<size_t> progress{100};
|
||||||
auto job = [&p, &progress]() {
|
auto job = [&p, &progress]() {
|
||||||
@@ -217,7 +217,7 @@ int main() {
|
|||||||
p.fill_bar_remainder_with("");
|
p.fill_bar_remainder_with("");
|
||||||
p.end_bar_with("");
|
p.end_bar_with("");
|
||||||
p.set_postfix_text("Checking credentials");
|
p.set_postfix_text("Checking credentials");
|
||||||
p.set_foreground_color(indicator::ProgressBar::Color::YELLOW);
|
p.set_foreground_color(indicator::Color::YELLOW);
|
||||||
std::atomic<int> spinner_index{0};
|
std::atomic<int> spinner_index{0};
|
||||||
std::vector<std::string> spinner{"⠁", "⠂", "⠄", "⡀", "⢀", "⠠", "⠐", "⠈"};
|
std::vector<std::string> spinner{"⠁", "⠂", "⠄", "⡀", "⢀", "⠠", "⠐", "⠈"};
|
||||||
auto job = [&p, &spinner_index, &spinner]() {
|
auto job = [&p, &spinner_index, &spinner]() {
|
||||||
@@ -227,7 +227,7 @@ int main() {
|
|||||||
spinner_index -= 1;
|
spinner_index -= 1;
|
||||||
if (p.current() + 2 >= 100) {
|
if (p.current() + 2 >= 100) {
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
p.set_foreground_color(indicator::ProgressBar::Color::GREEN);
|
p.set_foreground_color(indicator::Color::GREEN);
|
||||||
p.set_prefix_text("✔");
|
p.set_prefix_text("✔");
|
||||||
p.hide_percentage();
|
p.hide_percentage();
|
||||||
p.set_postfix_text("Authenticated!");
|
p.set_postfix_text("Authenticated!");
|
||||||
|
|||||||
Reference in New Issue
Block a user