diff --git a/include/indicators/details/stream_helper.hpp b/include/indicators/details/stream_helper.hpp index eececed..fbc4e88 100644 --- a/include/indicators/details/stream_helper.hpp +++ b/include/indicators/details/stream_helper.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include @@ -47,6 +48,37 @@ inline void set_stream_color(std::ostream &os, Color color) { } } +inline void set_font_style(std::ostream &os, FontStyle style) { + switch (style) { + case FontStyle::bold: + os << termcolor::bold; + break; + case FontStyle::dark: + os << termcolor::dark; + break; + case FontStyle::italic: + os << termcolor::italic; + break; + case FontStyle::underline: + os << termcolor::underline; + break; + case FontStyle::blink: + os << termcolor::blink; + break; + case FontStyle::reverse: + os << termcolor::reverse; + break; + case FontStyle::concealed: + os << termcolor::concealed; + break; + case FontStyle::crossed: + os << termcolor::crossed; + break; + default: + break; + } +} + inline std::ostream &write_duration(std::ostream &os, std::chrono::nanoseconds ns) { using namespace std; using namespace std::chrono; diff --git a/include/indicators/font_style.hpp b/include/indicators/font_style.hpp new file mode 100644 index 0000000..a82183c --- /dev/null +++ b/include/indicators/font_style.hpp @@ -0,0 +1,33 @@ +/* +Activity Indicators for Modern C++ +https://github.com/p-ranav/indica + +Licensed under the MIT License . +SPDX-License-Identifier: MIT +Copyright (c) 2019 Pranav Srinivas Kumar . + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ +#pragma once + +namespace indicators { + +enum class FontStyle { bold, dark, italic, underline, blink, reverse, concealed, crossed }; + +} diff --git a/include/indicators/progress_bar.hpp b/include/indicators/progress_bar.hpp index 4959755..0de4b7d 100644 --- a/include/indicators/progress_bar.hpp +++ b/include/indicators/progress_bar.hpp @@ -50,7 +50,7 @@ class ProgressBar { option::End, option::Fill, option::Lead, option::Remainder, option::MaxPostfixTextLen, option::Completed, option::ShowPercentage, option::ShowElapsedTime, option::ShowRemainingTime, option::SavedStartTime, - option::ForegroundColor>; + option::ForegroundColor, option::FontStyles>; public: template ()); + + for (auto &style : get_value()) + details::set_font_style(std::cout, style); + std::cout << get_value(); std::cout << get_value(); diff --git a/include/indicators/setting.hpp b/include/indicators/setting.hpp index 09e4e10..fb5c341 100644 --- a/include/indicators/setting.hpp +++ b/include/indicators/setting.hpp @@ -28,9 +28,11 @@ SOFTWARE. #include #include +#include #include #include #include +#include namespace indicators { @@ -86,6 +88,7 @@ enum class ProgressBarOption { foreground_color, spinner_show, spinner_states, + font_styles, hide_bar_when_complete }; @@ -199,5 +202,7 @@ using SpinnerStates = details::Setting, details::ProgressBarOption::spinner_states>; using HideBarWhenComplete = details::BooleanSetting; +using FontStyles = + details::Setting, details::ProgressBarOption::font_styles>; } // namespace option } // namespace indicators \ No newline at end of file