mirror of
https://github.com/p-ranav/indicators.git
synced 2025-12-12 01:18:52 +08:00
Clang format
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
#include <gauge/termcolor.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <gauge/termcolor.hpp>
|
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
class ProgressBar {
|
class ProgressBar {
|
||||||
@@ -45,12 +45,12 @@ public:
|
|||||||
_end = end;
|
_end = end;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_prefix_text(const std::string& text) {
|
void set_prefix_text(const std::string &text) {
|
||||||
std::unique_lock<std::mutex> lock{_mutex};
|
std::unique_lock<std::mutex> lock{_mutex};
|
||||||
_prefix_text = text;
|
_prefix_text = text;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_postfix_text(const std::string& text) {
|
void set_postfix_text(const std::string &text) {
|
||||||
std::unique_lock<std::mutex> lock{_mutex};
|
std::unique_lock<std::mutex> lock{_mutex};
|
||||||
_postfix_text = text;
|
_postfix_text = text;
|
||||||
if (_postfix_text.length() > _max_postfix_text_length)
|
if (_postfix_text.length() > _max_postfix_text_length)
|
||||||
@@ -84,7 +84,7 @@ public:
|
|||||||
|
|
||||||
bool is_completed() const { return _completed; }
|
bool is_completed() const { return _completed; }
|
||||||
|
|
||||||
void mark_as_completed() {
|
void mark_as_completed() {
|
||||||
_completed = true;
|
_completed = true;
|
||||||
_print_progress();
|
_print_progress();
|
||||||
}
|
}
|
||||||
@@ -108,7 +108,7 @@ private:
|
|||||||
void _print_progress() {
|
void _print_progress() {
|
||||||
std::unique_lock<std::mutex> lock{_mutex};
|
std::unique_lock<std::mutex> lock{_mutex};
|
||||||
std::cout << termcolor::bold;
|
std::cout << termcolor::bold;
|
||||||
switch(_foreground_color) {
|
switch (_foreground_color) {
|
||||||
case Color::GREY:
|
case Color::GREY:
|
||||||
std::cout << termcolor::grey;
|
std::cout << termcolor::grey;
|
||||||
break;
|
break;
|
||||||
@@ -132,7 +132,7 @@ private:
|
|||||||
break;
|
break;
|
||||||
case Color::WHITE:
|
case Color::WHITE:
|
||||||
std::cout << termcolor::white;
|
std::cout << termcolor::white;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
std::cout << _prefix_text;
|
std::cout << _prefix_text;
|
||||||
std::cout << _start;
|
std::cout << _start;
|
||||||
@@ -149,13 +149,14 @@ private:
|
|||||||
if (_show_percentage) {
|
if (_show_percentage) {
|
||||||
std::cout << " " << std::min(static_cast<size_t>(_progress), size_t(100)) << "%";
|
std::cout << " " << std::min(static_cast<size_t>(_progress), size_t(100)) << "%";
|
||||||
}
|
}
|
||||||
if (_max_postfix_text_length == 0) _max_postfix_text_length = 10;
|
if (_max_postfix_text_length == 0)
|
||||||
|
_max_postfix_text_length = 10;
|
||||||
std::cout << " " << _postfix_text << std::string(_max_postfix_text_length, ' ') << "\r";
|
std::cout << " " << _postfix_text << std::string(_max_postfix_text_length, ' ') << "\r";
|
||||||
std::cout.flush();
|
std::cout.flush();
|
||||||
if (_progress > 100.0) {
|
if (_progress > 100.0) {
|
||||||
_completed = true;
|
_completed = true;
|
||||||
}
|
}
|
||||||
if (_completed)
|
if (_completed)
|
||||||
std::cout << termcolor::reset << std::endl;
|
std::cout << termcolor::reset << std::endl;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -42,9 +42,7 @@ int main() {
|
|||||||
// Hide cursor
|
// Hide cursor
|
||||||
std::cout << "\e[?25l";
|
std::cout << "\e[?25l";
|
||||||
|
|
||||||
{
|
{}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// PROGRESS BAR 1
|
// PROGRESS BAR 1
|
||||||
@@ -97,8 +95,7 @@ int main() {
|
|||||||
p3.hide_percentage();
|
p3.hide_percentage();
|
||||||
auto job3 = [&p3]() {
|
auto job3 = [&p3]() {
|
||||||
while (true) {
|
while (true) {
|
||||||
p3.set_prefix_text("Reading package list... " + std::to_string(p3.current()) +
|
p3.set_prefix_text("Reading package list... " + std::to_string(p3.current()) + "% ");
|
||||||
"% ");
|
|
||||||
if (p3.current() + 2 >= 100)
|
if (p3.current() + 2 >= 100)
|
||||||
p3.set_prefix_text("Reading package list... Done");
|
p3.set_prefix_text("Reading package list... Done");
|
||||||
p3.tick();
|
p3.tick();
|
||||||
@@ -146,8 +143,7 @@ int main() {
|
|||||||
//
|
//
|
||||||
// PROGRESS BAR 4
|
// PROGRESS BAR 4
|
||||||
//
|
//
|
||||||
std::vector<std::string> lead_spinner{"⠋", "⠙", "⠹", "⠸", "⠼",
|
std::vector<std::string> lead_spinner{"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"};
|
||||||
"⠴", "⠦", "⠧", "⠇", "⠏"};
|
|
||||||
ProgressBar p4;
|
ProgressBar p4;
|
||||||
p4.set_bar_width(50);
|
p4.set_bar_width(50);
|
||||||
p4.start_bar_with("");
|
p4.start_bar_with("");
|
||||||
|
|||||||
@@ -21,25 +21,22 @@ int main() {
|
|||||||
//
|
//
|
||||||
|
|
||||||
std::atomic<size_t> index{0};
|
std::atomic<size_t> index{0};
|
||||||
std::vector<std::string> status_text =
|
std::vector<std::string> status_text = {"Rocket.exe is not responding",
|
||||||
{
|
"Finding a replacement engineer",
|
||||||
"Rocket.exe is not responding",
|
"Buying more snacks",
|
||||||
"Finding a replacement engineer",
|
"Assimilating the modding community",
|
||||||
"Buying more snacks",
|
"Crossing fingers",
|
||||||
"Assimilating the modding community",
|
"Porting KSP to a Nokia 3310"
|
||||||
"Crossing fingers",
|
"Flexing struts",
|
||||||
"Porting KSP to a Nokia 3310"
|
"Releasing space whales",
|
||||||
"Flexing struts",
|
"Watching paint dry"};
|
||||||
"Releasing space whales",
|
|
||||||
"Watching paint dry"
|
|
||||||
};
|
|
||||||
|
|
||||||
// Let's say you want to append some status text to the right of the progress bar
|
// Let's say you want to append some status text to the right of the progress bar
|
||||||
// You can use bar.append_text(...) to append text to the right
|
// You can use bar.append_text(...) to append text to the right
|
||||||
//
|
//
|
||||||
// [■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■-------------] 70% Finding a replacement engineer
|
// [■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■-------------] 70% Finding a replacement engineer
|
||||||
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
//
|
//
|
||||||
|
|
||||||
auto job = [&bar, &index, &status_text]() {
|
auto job = [&bar, &index, &status_text]() {
|
||||||
while (true) {
|
while (true) {
|
||||||
@@ -64,6 +61,6 @@ int main() {
|
|||||||
last_job.join();
|
last_job.join();
|
||||||
|
|
||||||
std::cout << "Done\n";
|
std::cout << "Done\n";
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user