diff --git a/include/indicators/progress_bar.hpp b/include/indicators/progress_bar.hpp index 1ab4879..d840bb1 100644 --- a/include/indicators/progress_bar.hpp +++ b/include/indicators/progress_bar.hpp @@ -64,19 +64,19 @@ public: indicators::get(std::forward(args)...), indicators::get(std::forward(args)...), indicators::get(std::forward(args)...) - ) + ) {} template void set_option(Setting&& setting){ - static_assert(std::is_same())>::type>::value, "Setting has wrong type!"); + static_assert(!std::is_same())>::type>::value, "Setting has wrong type!"); std::lock_guard lock(_mutex); get_value() = std::move(setting).value; } template void set_option(const Setting& setting){ - static_assert(std::is_same())>::type>::value, "Setting has wrong type!"); + static_assert(!std::is_same())>::type>::value, "Setting has wrong type!"); std::lock_guard lock(_mutex); get_value() = setting.value; } diff --git a/include/indicators/setting.hpp b/include/indicators/setting.hpp index b4f9ca3..2dbb60d 100644 --- a/include/indicators/setting.hpp +++ b/include/indicators/setting.hpp @@ -57,6 +57,9 @@ template struct Setting{ template ::value>::type> explicit Setting(Args&&... args) : value(std::forward(args)...){} + Setting(const Setting&) = default; + Setting(Setting&&) = default; + static constexpr auto id = Id; using type = T; @@ -107,9 +110,9 @@ typename get_ret_type::type get(){ template auto get(T&& first, Args&&... tail) -> typename std::enable_if< (std::decay::type::id == Id), - decltype(std::forward(first).value)> + decltype(std::forward(first))> ::type{ - return std::forward(first).value; + return std::forward(first); } template @@ -156,152 +159,152 @@ namespace option{ namespace detail{ template<> struct get_ret_type{ - using type = std::size_t; + using type = ::indicators::option::BarWidth; }; template<> get_ret_type::type get(){ - return std::size_t{100}; + return indicators::option::BarWidth{100}; } template<> struct get_ret_type{ - using type = std::string; + using type = ::indicators::option::PrefixText; }; template<> get_ret_type::type get(){ - return std::string{}; + return indicators::option::PrefixText{}; } template<> struct get_ret_type{ - using type = std::string; + using type = ::indicators::option::PostfixText; }; template<> get_ret_type::type get(){ - return std::string{}; + return indicators::option::PostfixText{}; } template<> struct get_ret_type{ - using type = std::string; + using type = ::indicators::option::Start; }; template<> get_ret_type::type get(){ - return std::string{"["}; + return indicators::option::Start{"["}; } template<> struct get_ret_type{ - using type = std::string; + using type = ::indicators::option::Fill; }; template<> get_ret_type::type get(){ - return std::string{"="}; + return indicators::option::Fill{"="}; } template<> struct get_ret_type{ - using type = std::string; + using type = ::indicators::option::Lead; }; template<> get_ret_type::type get(){ - return std::string{">"}; + return indicators::option::Lead{">"}; } template<> struct get_ret_type{ - using type = std::string; + using type = ::indicators::option::Remainder; }; template<> get_ret_type::type get(){ - return std::string{" "}; + return indicators::option::Remainder{" "}; } template<> struct get_ret_type{ - using type = std::string; + using type = ::indicators::option::End; }; template<> get_ret_type::type get(){ - return std::string{"]"}; + return indicators::option::End{"]"}; } template<> struct get_ret_type{ - using type = std::size_t; + using type = ::indicators::option::MaxPostfixTextLen; }; template<> get_ret_type::type get(){ - return std::size_t{0}; + return indicators::option::MaxPostfixTextLen{0}; } template<> struct get_ret_type{ - using type = bool; + using type = ::indicators::option::Completed; }; template<> get_ret_type::type get(){ - return false; + return indicators::option::Completed{false}; } template<> struct get_ret_type{ - using type = bool; + using type = ::indicators::option::ShowPercentage; }; template<> get_ret_type::type get(){ - return true; + return indicators::option::ShowPercentage{false}; } template<> struct get_ret_type{ - using type = bool; + using type = ::indicators::option::ShowElapsedTime; }; template<> get_ret_type::type get(){ - return false; + return indicators::option::ShowElapsedTime{false}; } template<> struct get_ret_type{ - using type = bool; + using type = ::indicators::option::ShowRemainingTime; }; template<> get_ret_type::type get(){ - return false; + return indicators::option::ShowRemainingTime{false}; } template<> struct get_ret_type{ - using type = bool; + using type = ::indicators::option::SavedStartTime; }; template<> get_ret_type::type get(){ - return false; + return indicators::option::SavedStartTime{false}; } template<> struct get_ret_type{ - using type = ::indicators::Color; + using type = ::indicators::option::ForegroundColor; }; template<> get_ret_type::type get(){ - return ::indicators::Color::WHITE; + return indicators::option::ForegroundColor{::indicators::Color::WHITE}; } } diff --git a/samples/multi_progress_bar.cpp b/samples/multi_progress_bar.cpp index 78360ec..10f05d6 100644 --- a/samples/multi_progress_bar.cpp +++ b/samples/multi_progress_bar.cpp @@ -3,41 +3,44 @@ int main() { - indicators::ProgressBar bar1; - bar1.set_bar_width(50); - bar1.start_bar_with("["); - bar1.fill_bar_progress_with("■"); - bar1.lead_bar_progress_with("■"); - bar1.fill_bar_remainder_with(" "); - bar1.end_bar_with(" ]"); - bar1.set_foreground_color(indicators::Color::YELLOW); - bar1.show_elapsed_time(); - bar1.show_remaining_time(); - bar1.set_prefix_text("Progress Bar #1 "); + indicators::ProgressBar bar1{ + indicators::option::BarWidth{50}, + indicators::option::Start{"["}, + indicators::option::Fill{"■"}, + indicators::option::Lead{"■"}, + indicators::option::Remainder{" "}, + indicators::option::End{" ]"}, + indicators::option::ForegroundColor{indicators::Color::YELLOW}, + indicators::option::ShowElapsedTime{true}, + indicators::option::ShowRemainingTime{true}, + indicators::option::PrefixText{"Progress Bar #1 "} + }; - indicators::ProgressBar bar2; - bar2.set_bar_width(50); - bar2.start_bar_with("["); - bar2.fill_bar_progress_with("="); - bar2.lead_bar_progress_with(">"); - bar2.fill_bar_remainder_with(" "); - bar2.end_bar_with(" ]"); - bar2.set_foreground_color(indicators::Color::CYAN); - bar2.show_elapsed_time(); - bar2.show_remaining_time(); - bar2.set_prefix_text("Progress Bar #2 "); + indicators::ProgressBar bar2{ + indicators::option::BarWidth{50}, + indicators::option::Start{"["}, + indicators::option::Fill{"="}, + indicators::option::Lead{">"}, + indicators::option::Remainder{" "}, + indicators::option::End{" ]"}, + indicators::option::ForegroundColor{indicators::Color::CYAN}, + indicators::option::ShowElapsedTime{true}, + indicators::option::ShowRemainingTime{true}, + indicators::option::PrefixText{"Progress Bar #2 "} + }; - indicators::ProgressBar bar3; - bar3.set_bar_width(50); - bar3.start_bar_with("["); - bar3.fill_bar_progress_with("#"); - bar3.lead_bar_progress_with("#"); - bar3.fill_bar_remainder_with(" "); - bar3.end_bar_with(" ]"); - bar3.set_foreground_color(indicators::Color::RED); - bar3.show_elapsed_time(); - bar3.show_remaining_time(); - bar3.set_prefix_text("Progress Bar #3 "); + indicators::ProgressBar bar3{ + indicators::option::BarWidth{50}, + indicators::option::Start{"["}, + indicators::option::Fill{"#"}, + indicators::option::Lead{"#"}, + indicators::option::Remainder{" "}, + indicators::option::End{" ]"}, + indicators::option::ForegroundColor{indicators::Color::CYAN}, + indicators::option::ShowElapsedTime{true}, + indicators::option::ShowRemainingTime{true}, + indicators::option::PrefixText{"Progress Bar #3 "} + }; indicators::MultiProgress bars(bar1, bar2, bar3); diff --git a/samples/multi_threaded_bar.cpp b/samples/multi_threaded_bar.cpp index 457c479..ed91600 100644 --- a/samples/multi_threaded_bar.cpp +++ b/samples/multi_threaded_bar.cpp @@ -3,14 +3,15 @@ int main() { - 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(indicators::Color::YELLOW); + indicators::ProgressBar bar{ + indicators::option::BarWidth{50}, + indicators::option::Start{"["}, + indicators::option::Fill{"■"}, + indicators::option::Lead{"■"}, + indicators::option::Remainder{"-"}, + indicators::option::End{" ]"}, + indicators::option::ForegroundColor{indicators::Color::YELLOW}, + }; // As configured, the bar will look like this: // @@ -39,7 +40,7 @@ int main() { if (bar.is_completed()) { break; } - bar.set_postfix_text(status_text[index % status_text.size()]); + bar.set_option(indicators::option::PostfixText{status_text[index % status_text.size()]}); bar.tick(); index += 1; std::this_thread::sleep_for(std::chrono::milliseconds(200)); diff --git a/samples/progress_bar_set_progress.cpp b/samples/progress_bar_set_progress.cpp index ec042bc..aec9d75 100644 --- a/samples/progress_bar_set_progress.cpp +++ b/samples/progress_bar_set_progress.cpp @@ -7,17 +7,16 @@ int main() { // Hide cursor std::cout << "\e[?25l"; - indicators::ProgressBar bar; - - // Configure the 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_postfix_text("Loading dependency 1/4"); - bar.set_foreground_color(indicators::Color::CYAN); + indicators::ProgressBar bar{ + indicators::option::BarWidth{50}, + indicators::option::Start{"["}, + indicators::option::Fill{"■"}, + indicators::option::Lead{"■"}, + indicators::option::Remainder{"-"}, + indicators::option::End{" ]"}, + indicators::option::PostfixText{"Loading dependency 1/4"}, + indicators::option::ForegroundColor{indicators::Color::CYAN}, + }; // Update bar state bar.set_progress(10); // 10% done @@ -25,21 +24,21 @@ int main() { // do some work std::this_thread::sleep_for(std::chrono::milliseconds(800)); - bar.set_postfix_text("Loading dependency 2/4"); + bar.set_option(indicators::option::PostfixText{"Loading dependency 2/4"}); bar.set_progress(30); // 30% done // do some more work std::this_thread::sleep_for(std::chrono::milliseconds(700)); - bar.set_postfix_text("Loading dependency 3/4"); + bar.set_option(indicators::option::PostfixText{"Loading dependency 3/4"}); bar.set_progress(65); // 65% done // do final bit of work std::this_thread::sleep_for(std::chrono::milliseconds(900)); - bar.set_postfix_text("Loaded dependencies!"); + bar.set_option(indicators::option::PostfixText{"Loaded dependencies!"}); bar.set_progress(100); // all done diff --git a/samples/progress_bar_tick.cpp b/samples/progress_bar_tick.cpp index 5d8e594..8c845b3 100644 --- a/samples/progress_bar_tick.cpp +++ b/samples/progress_bar_tick.cpp @@ -3,17 +3,16 @@ #include int main() { - indicators::ProgressBar bar; - - // Configure the 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_postfix_text("Getting started"); - bar.set_foreground_color(indicators::Color::GREEN); + indicators::ProgressBar bar{ + indicators::option::BarWidth{50}, + indicators::option::Start{"["}, + indicators::option::Fill{"="}, + indicators::option::Lead{">"}, + indicators::option::Remainder{" "}, + indicators::option::End{" ]"}, + indicators::option::PostfixText{"Getting started"}, + indicators::option::ForegroundColor{indicators::Color::GREEN}, + }; // Update bar state while (true) { diff --git a/samples/time_meter.cpp b/samples/time_meter.cpp index 23e41cb..04542be 100644 --- a/samples/time_meter.cpp +++ b/samples/time_meter.cpp @@ -3,21 +3,18 @@ #include int main() { - indicators::ProgressBar bar; - - // Configure the 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_prefix_text("Training Gaze Network 👀"); - bar.set_foreground_color(indicators::Color::YELLOW); - - // Show time elapsed and remaining - bar.show_elapsed_time(); - bar.show_remaining_time(); + indicators::ProgressBar bar{ + indicators::option::BarWidth{50}, + indicators::option::Start{" ["}, + indicators::option::Fill{"█"}, + indicators::option::Lead{"█"}, + indicators::option::Remainder{"-"}, + indicators::option::End{"]"}, + indicators::option::PostfixText{"Training Gaze Network "}, + indicators::option::ForegroundColor{indicators::Color::YELLOW}, + indicators::option::ShowElapsedTime{true}, + indicators::option::ShowRemainingTime{true}, + }; // Update bar state while (true) {