This commit is contained in:
张壹 2025-03-05 09:19:16 +08:00
parent 3ca661f9e6
commit 5528c948e1
3 changed files with 25 additions and 7 deletions

View File

@ -63,10 +63,11 @@ void gctl::progress_bar::set_frequency_update(unsigned long frequency_update_)
return; return;
} }
void gctl::progress_bar::set_style(const char* unit_bar_, const char* unit_space_) void gctl::progress_bar::set_style(const char* unit_bar_, const char* unit_space_, bar_color_e c)
{ {
unit_bar = unit_bar_; unit_bar = unit_bar_;
unit_space = unit_space_; unit_space = unit_space_;
color = c;
return; return;
} }
@ -130,9 +131,15 @@ void gctl::progress_bar::progressed(unsigned long idx_)
// display progress bar // display progress bar
*out << " " << description << " |"; *out << " " << description << " |";
for(int bar_length=0;bar_length<=bar_size-1;++bar_length){ for(int bar_length=0;bar_length<=bar_size-1;++bar_length)
if(bar_length*percent_per_unit_bar<progress_percent){ {
*out << unit_bar; if(bar_length*percent_per_unit_bar<progress_percent)
{
if (color == Green) *out << GCTL_BOLDGREEN << unit_bar << GCTL_RESET;
else if (color == Red) *out << GCTL_BOLDRED << unit_bar << GCTL_RESET;
else if (color == Blue) *out << GCTL_BOLDBLUE << unit_bar << GCTL_RESET;
else if (color == Yellow) *out << GCTL_BOLDYELLOW << unit_bar << GCTL_RESET;
else *out << GCTL_BOLD << unit_bar << GCTL_RESET;
} }
else{ else{
*out << unit_space; *out << unit_space;

View File

@ -40,7 +40,7 @@
#include <thread> #include <thread>
#include <chrono> #include <chrono>
#include "../core/exceptions.h" #include "stream_t.h"
//进度条宏定义 //进度条宏定义
#define TOTAL_PERCENTAGE 100.0 ///< 设置总的百分比为100%。 #define TOTAL_PERCENTAGE 100.0 ///< 设置总的百分比为100%。
@ -48,6 +48,14 @@
namespace gctl namespace gctl
{ {
enum bar_color_e
{
Green,
Red,
Blue,
Yellow,
};
/** /**
* @brief * @brief
* @warning * @warning
@ -84,8 +92,9 @@ namespace gctl
* *
* @param[in] unit_bar_ * @param[in] unit_bar_
* @param[in] unit_space_ * @param[in] unit_space_
* @param[in] c Green Red Yellow Blue
*/ */
void set_style(const char* unit_bar_, const char* unit_space_); void set_style(const char* unit_bar_, const char* unit_space_, bar_color_e c = Green);
/** /**
* @brief * @brief
* *
@ -100,6 +109,7 @@ namespace gctl
void progressed_simple(unsigned long idx_); void progressed_simple(unsigned long idx_);
protected: protected:
bar_color_e color;
unsigned long n; unsigned long n;
unsigned int desc_width; unsigned int desc_width;
unsigned long frequency_update; unsigned long frequency_update;
@ -113,6 +123,6 @@ namespace gctl
int get_console_width(); int get_console_width();
int get_bar_length(); int get_bar_length();
}; };
} };
#endif // _GCTL_PROGRESS_BAR_H #endif // _GCTL_PROGRESS_BAR_H

View File

@ -51,6 +51,7 @@
#define GCTL_MOVERIGHT(os, x) do {os << "\033[" << x << "C";} while (0); ///< 终端光标右移x列 #define GCTL_MOVERIGHT(os, x) do {os << "\033[" << x << "C";} while (0); ///< 终端光标右移x列
#define GCTL_MOVELEFT(os, x) do {os << "\033[" << x << "D";} while (0); ///< 终端光标左移x列 #define GCTL_MOVELEFT(os, x) do {os << "\033[" << x << "D";} while (0); ///< 终端光标左移x列
#define GCTL_MOVETO(os, r, c) do {os << "\033[" << c << ";" << r << "H";} while (0); ///< 终端光标移动至r行c列位置 #define GCTL_MOVETO(os, r, c) do {os << "\033[" << c << ";" << r << "H";} while (0); ///< 终端光标移动至r行c列位置
namespace gctl namespace gctl
{ {
template <typename ObjValType> template <typename ObjValType>