diff --git a/lib/utility/progress_bar.cpp b/lib/utility/progress_bar.cpp index 2b583ea..01c8cf5 100644 --- a/lib/utility/progress_bar.cpp +++ b/lib/utility/progress_bar.cpp @@ -63,10 +63,11 @@ void gctl::progress_bar::set_frequency_update(unsigned long frequency_update_) 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_space = unit_space_; + color = c; return; } @@ -130,9 +131,15 @@ void gctl::progress_bar::progressed(unsigned long idx_) // display progress bar *out << " " << description << " |"; - for(int bar_length=0;bar_length<=bar_size-1;++bar_length){ - if(bar_length*percent_per_unit_bar #include -#include "../core/exceptions.h" +#include "stream_t.h" //进度条宏定义 #define TOTAL_PERCENTAGE 100.0 ///< 设置总的百分比为100%。 @@ -48,6 +48,14 @@ namespace gctl { + enum bar_color_e + { + Green, + Red, + Blue, + Yellow, + }; + /** * @brief 终端显示进度条的类。 * @warning 这个类是一个在终端显示进度的通用类型。 @@ -84,8 +92,9 @@ namespace gctl * * @param[in] unit_bar_ 字符串,已达到进度的符号。 * @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 更新当前已达到的进度值。 * @@ -100,6 +109,7 @@ namespace gctl void progressed_simple(unsigned long idx_); protected: + bar_color_e color; unsigned long n; unsigned int desc_width; unsigned long frequency_update; @@ -113,6 +123,6 @@ namespace gctl int get_console_width(); int get_bar_length(); }; -} +}; #endif // _GCTL_PROGRESS_BAR_H \ No newline at end of file diff --git a/lib/utility/stream_t.h b/lib/utility/stream_t.h index 4d8d8c5..4e5afd9 100644 --- a/lib/utility/stream_t.h +++ b/lib/utility/stream_t.h @@ -51,6 +51,7 @@ #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_MOVETO(os, r, c) do {os << "\033[" << c << ";" << r << "H";} while (0); ///< 终端光标移动至r行c列位置 + namespace gctl { template