Minor updates to support FontStyles

This commit is contained in:
Pranav Srinivas Kumar
2020-04-06 11:05:44 -07:00
parent 37b3fc395e
commit 07b9eede8a
4 changed files with 75 additions and 1 deletions

View File

@@ -1,6 +1,7 @@
#pragma once
#include <indicators/color.hpp>
#include <indicators/font_style.hpp>
#include <indicators/termcolor.hpp>
#include <algorithm>
@@ -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;

View File

@@ -0,0 +1,33 @@
/*
Activity Indicators for Modern C++
https://github.com/p-ranav/indica
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
Copyright (c) 2019 Pranav Srinivas Kumar <pranav.srinivas.kumar@gmail.com>.
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 };
}

View File

@@ -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 <typename... Args,
@@ -203,6 +203,10 @@ private:
std::cout << termcolor::bold;
details::set_stream_color(std::cout, get_value<details::ProgressBarOption::foreground_color>());
for (auto &style : get_value<details::ProgressBarOption::font_styles>())
details::set_font_style(std::cout, style);
std::cout << get_value<details::ProgressBarOption::prefix_text>();
std::cout << get_value<details::ProgressBarOption::start>();

View File

@@ -28,9 +28,11 @@ SOFTWARE.
#include <cstddef>
#include <indicators/color.hpp>
#include <indicators/font_style.hpp>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>
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<std::vector<std::string>, details::ProgressBarOption::spinner_states>;
using HideBarWhenComplete =
details::BooleanSetting<details::ProgressBarOption::hide_bar_when_complete>;
using FontStyles =
details::Setting<std::vector<FontStyle>, details::ProgressBarOption::font_styles>;
} // namespace option
} // namespace indicators