mirror of
https://github.com/p-ranav/indicators.git
synced 2025-12-16 04:18:51 +08:00
Minor updates to support FontStyles
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <indicators/color.hpp>
|
#include <indicators/color.hpp>
|
||||||
|
#include <indicators/font_style.hpp>
|
||||||
#include <indicators/termcolor.hpp>
|
#include <indicators/termcolor.hpp>
|
||||||
|
|
||||||
#include <algorithm>
|
#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) {
|
inline std::ostream &write_duration(std::ostream &os, std::chrono::nanoseconds ns) {
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace std::chrono;
|
using namespace std::chrono;
|
||||||
|
|||||||
33
include/indicators/font_style.hpp
Normal file
33
include/indicators/font_style.hpp
Normal 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 };
|
||||||
|
|
||||||
|
}
|
||||||
@@ -50,7 +50,7 @@ class ProgressBar {
|
|||||||
option::End, option::Fill, option::Lead, option::Remainder,
|
option::End, option::Fill, option::Lead, option::Remainder,
|
||||||
option::MaxPostfixTextLen, option::Completed, option::ShowPercentage,
|
option::MaxPostfixTextLen, option::Completed, option::ShowPercentage,
|
||||||
option::ShowElapsedTime, option::ShowRemainingTime, option::SavedStartTime,
|
option::ShowElapsedTime, option::ShowRemainingTime, option::SavedStartTime,
|
||||||
option::ForegroundColor>;
|
option::ForegroundColor, option::FontStyles>;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
template <typename... Args,
|
template <typename... Args,
|
||||||
@@ -203,6 +203,10 @@ private:
|
|||||||
|
|
||||||
std::cout << termcolor::bold;
|
std::cout << termcolor::bold;
|
||||||
details::set_stream_color(std::cout, get_value<details::ProgressBarOption::foreground_color>());
|
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::prefix_text>();
|
||||||
|
|
||||||
std::cout << get_value<details::ProgressBarOption::start>();
|
std::cout << get_value<details::ProgressBarOption::start>();
|
||||||
|
|||||||
@@ -28,9 +28,11 @@ SOFTWARE.
|
|||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <indicators/color.hpp>
|
#include <indicators/color.hpp>
|
||||||
|
#include <indicators/font_style.hpp>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace indicators {
|
namespace indicators {
|
||||||
|
|
||||||
@@ -86,6 +88,7 @@ enum class ProgressBarOption {
|
|||||||
foreground_color,
|
foreground_color,
|
||||||
spinner_show,
|
spinner_show,
|
||||||
spinner_states,
|
spinner_states,
|
||||||
|
font_styles,
|
||||||
hide_bar_when_complete
|
hide_bar_when_complete
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -199,5 +202,7 @@ using SpinnerStates =
|
|||||||
details::Setting<std::vector<std::string>, details::ProgressBarOption::spinner_states>;
|
details::Setting<std::vector<std::string>, details::ProgressBarOption::spinner_states>;
|
||||||
using HideBarWhenComplete =
|
using HideBarWhenComplete =
|
||||||
details::BooleanSetting<details::ProgressBarOption::hide_bar_when_complete>;
|
details::BooleanSetting<details::ProgressBarOption::hide_bar_when_complete>;
|
||||||
|
using FontStyles =
|
||||||
|
details::Setting<std::vector<FontStyle>, details::ProgressBarOption::font_styles>;
|
||||||
} // namespace option
|
} // namespace option
|
||||||
} // namespace indicators
|
} // namespace indicators
|
||||||
Reference in New Issue
Block a user