196 :
r((
hex >> 16) & 0xFF),
g((
hex >> 8) & 0xFF),
b(
hex & 0xFF) {}
215 value.rgb_color = (
static_cast<uint32_t>(rgb_color.r) << 16) |
216 (
static_cast<uint32_t>(rgb_color.g) << 8) | rgb_color.b;
235 : set_foreground_color(), set_background_color(), ems(em) {}
238 if (!set_foreground_color) {
239 set_foreground_color = rhs.set_foreground_color;
240 foreground_color = rhs.foreground_color;
241 }
else if (rhs.set_foreground_color) {
242 if (!foreground_color.is_rgb || !rhs.foreground_color.is_rgb)
244 foreground_color.value.rgb_color |= rhs.foreground_color.value.rgb_color;
247 if (!set_background_color) {
248 set_background_color = rhs.set_background_color;
249 background_color = rhs.background_color;
250 }
else if (rhs.set_background_color) {
251 if (!background_color.is_rgb || !rhs.background_color.is_rgb)
253 background_color.value.rgb_color |= rhs.background_color.value.rgb_color;
257 static_cast<uint8_t>(rhs.ems));
267 return set_foreground_color;
270 return set_background_color;
273 return static_cast<uint8_t>(ems) != 0;
277 return foreground_color;
281 return background_color;
290 detail::color_type text_color) noexcept
291 : set_foreground_color(), set_background_color(), ems() {
293 foreground_color = text_color;
294 set_foreground_color =
true;
296 background_color = text_color;
297 set_background_color =
true;
305 detail::color_type foreground_color;
306 detail::color_type background_color;
307 bool set_foreground_color;
308 bool set_background_color;
330 const char* esc)
noexcept {
333 if (!text_color.is_rgb) {
334 bool is_background = esc ==
string_view(
"\x1b[48;2;");
338 if (is_background)
value += 10u;
356 for (
int i = 0; i < 7; i++) {
357 buffer[i] =
static_cast<Char
>(esc[i]);
359 rgb color(text_color.value.rgb_color);
363 buffer[19] =
static_cast<Char
>(0);
366 uint8_t em_codes[num_emphases] = {};
377 for (
size_t i = 0; i < num_emphases; ++i) {
378 if (!em_codes[i])
continue;
381 buffer[
index++] =
static_cast<Char
>(
'0' + em_codes[i]);
394 static constexpr size_t num_emphases = 8;
395 Char
buffer[7u + 3u * num_emphases + 1u];
398 char delimiter)
noexcept {
399 out[0] =
static_cast<Char
>(
'0' +
c / 100);
400 out[1] =
static_cast<Char
>(
'0' +
c / 10 % 10);
401 out[2] =
static_cast<Char
>(
'0' +
c % 10);
402 out[3] =
static_cast<Char
>(delimiter);
409template <
typename Char>
411 detail::color_type foreground)
noexcept {
415template <
typename Char>
417 detail::color_type background)
noexcept {
421template <
typename Char>
426template <
typename Char>
inline void fputs(
const Char* chars, FILE* stream) {
433 int result = std::fputws(chars, stream);
439 fputs(
"\x1b[0m", stream);
443 fputs(
L"\x1b[0m", stream);
456template <
typename Char>
460 bool has_style =
false;
468 auto foreground = detail::make_foreground_color<Char>(ts.
get_foreground());
469 buf.
append(foreground.begin(), foreground.end());
473 auto background = detail::make_background_color<Char>(ts.
get_background());
474 buf.
append(background.begin(), background.end());
477 if (has_style) detail::reset_color<Char>(buf);
482template <
typename S,
typename Char =
char_t<S>>
490 buf.push_back(Char(0));
506template <
typename S,
typename... Args,
509 const Args&... args) {
525template <
typename S,
typename... Args,
528 return print(stdout, ts, format_str, args...);
531template <
typename S,
typename Char =
char_t<S>>
552template <
typename S,
typename... Args,
typename Char =
char_t<S>>
554 const Args&... args) {
562template <
typename OutputIt,
typename Char,
563 FMT_ENABLE_IF(detail::is_output_iterator<OutputIt, Char>::value)>
567 auto&& buf = detail::get_buffer<Char>(out);
584template <
typename OutputIt,
typename S,
typename... Args,
585 bool enable = detail::is_output_iterator<OutputIt, char_t<S>>
::value&&
586 detail::is_string<S>::value>
594template <
typename T,
typename Char>
596 template <
typename FormatContext>
597 auto format(
const detail::styled_arg<T>&
arg, FormatContext& ctx)
const
598 ->
decltype(ctx.out()) {
599 const auto& ts =
arg.style;
601 auto out = ctx.out();
603 bool has_style =
false;
604 if (ts.has_emphasis()) {
606 auto emphasis = detail::make_emphasis<Char>(ts.get_emphasis());
609 if (ts.has_foreground()) {
612 detail::make_foreground_color<Char>(ts.get_foreground());
613 out =
std::copy(foreground.begin(), foreground.end(), out);
615 if (ts.has_background()) {
618 detail::make_background_color<Char>(ts.get_background());
619 out =
std::copy(background.begin(), background.end(), out);
644 -> detail::styled_arg<remove_cvref_t<T>> {
645 return detail::styled_arg<remove_cvref_t<T>>{
value, ts};
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const ArgReturnType arg() const
Definition: ArrayCwiseUnaryOps.h:66
\rst A dynamically growing memory buffer for trivially copyable/constructible types with the first SI...
Definition: format.h:819
An implementation of std::basic_string_view for pre-C++17.
Definition: core.h:430
\rst A contiguous memory buffer with an optional growing ability.
Definition: core.h:862
void append(const U *begin, const U *end)
Appends data to the end of the buffer.
A text style consisting of foreground and background colors and emphasis.
Definition: color.h:232
FMT_CONSTEXPR bool has_emphasis() const noexcept
Definition: color.h:272
friend FMT_CONSTEXPR text_style fg(detail::color_type foreground) noexcept
Creates a text style from the foreground (text) color.
Definition: color.h:313
friend FMT_CONSTEXPR text_style operator|(text_style lhs, const text_style &rhs)
Definition: color.h:261
FMT_CONSTEXPR emphasis get_emphasis() const noexcept
Definition: color.h:283
FMT_CONSTEXPR text_style(emphasis em=emphasis()) noexcept
Definition: color.h:234
FMT_CONSTEXPR text_style & operator|=(const text_style &rhs)
Definition: color.h:237
FMT_CONSTEXPR detail::color_type get_foreground() const noexcept
Definition: color.h:275
FMT_CONSTEXPR bool has_foreground() const noexcept
Definition: color.h:266
friend FMT_CONSTEXPR text_style bg(detail::color_type background) noexcept
Creates a text style from the background color.
Definition: color.h:318
FMT_CONSTEXPR detail::color_type get_background() const noexcept
Definition: color.h:279
FMT_CONSTEXPR bool has_background() const noexcept
Definition: color.h:269
constexpr FMT_INLINE value()
Definition: core.h:1263
#define FMT_ASSERT(condition, message)
Definition: core.h:369
basic_string_view< char > string_view
Definition: core.h:520
typename detail::char_t_impl< S >::type char_t
String's character type.
Definition: core.h:644
#define FMT_END_DETAIL_NAMESPACE
Definition: core.h:227
#define FMT_MODULE_EXPORT_BEGIN
Definition: core.h:224
constexpr auto make_format_args(Args &&... args) -> format_arg_store< Context, remove_cvref_t< Args >... >
\rst Constructs a ~fmtformat_arg_store object that contains references to arguments and can be implic...
Definition: core.h:1916
#define FMT_CONSTEXPR
Definition: core.h:106
type
Definition: core.h:575
#define FMT_BEGIN_NAMESPACE
Definition: core.h:214
#define FMT_BEGIN_DETAIL_NAMESPACE
Definition: core.h:226
constexpr auto is_utf8() -> bool
Definition: core.h:415
#define FMT_ENABLE_IF(...)
Definition: core.h:335
#define FMT_CONSTEXPR_CHAR_TRAITS
Definition: core.h:130
auto get_iterator(Buffer &buf) -> decltype(buf.out())
Definition: core.h:1115
FMT_INLINE auto to_string_view(const Char *s) -> basic_string_view< Char >
Definition: core.h:536
typename type_identity< T >::type type_identity_t
Definition: core.h:309
#define FMT_END_NAMESPACE
Definition: core.h:217
#define FMT_MODULE_EXPORT_END
Definition: core.h:225
::uint32_t uint32_t
Definition: Meta.h:56
::uint8_t uint8_t
Definition: Meta.h:52
FMT_FUNC void print(std::FILE *f, string_view text)
Definition: format-inl.h:1499
OutputIterator copy(const RangeT &range, OutputIterator out)
Definition: ranges.h:26
result
Definition: format.h:2556
static constexpr const velocity::meters_per_second_t c(299792458.0)
Speed of light in vacuum.
std::string to_string(const T &t)
Definition: base.h:93
cubed< length::millimeter > L
Definition: volume.h:49
FMT_CONSTEXPR_CHAR_TRAITS const Char * end() const noexcept
Definition: color.h:389
FMT_CONSTEXPR ansi_color_escape(detail::color_type text_color, const char *esc) noexcept
Definition: color.h:329
FMT_CONSTEXPR const Char * begin() const noexcept
Definition: color.h:388
FMT_CONSTEXPR ansi_color_escape(emphasis em) noexcept
Definition: color.h:365
FMT_CONSTEXPR color_type(color rgb_color) noexcept
Definition: color.h:211
union color_type::color_union value
FMT_CONSTEXPR color_type(rgb rgb_color) noexcept
Definition: color.h:214
FMT_CONSTEXPR color_type(terminal_color term_color) noexcept
Definition: color.h:218
FMT_CONSTEXPR color_type() noexcept
Definition: color.h:210
bool is_rgb
Definition: color.h:222
FMT_CONSTEXPR rgb(uint32_t hex)
Definition: color.h:195
FMT_CONSTEXPR rgb()
Definition: color.h:193
FMT_CONSTEXPR rgb(uint8_t r_, uint8_t g_, uint8_t b_)
Definition: color.h:194
FMT_CONSTEXPR rgb(color hex)
Definition: color.h:197
uint8_t b
Definition: color.h:203
uint8_t g
Definition: color.h:202
uint8_t r
Definition: color.h:201
text_style style
Definition: color.h:453
const T & value
Definition: color.h:452
uint32_t rgb_color
Definition: color.h:225
uint8_t term_color
Definition: color.h:224
#define S(label, offset, message)
Definition: Errors.h:118
void fputs(const Char *chars, FILE *stream)
Definition: color.h:426
FMT_CONSTEXPR auto styled(const T &value, text_style ts) -> detail::styled_arg< remove_cvref_t< T > >
\rst Returns an argument that will be formatted using ANSI escape sequences, to be used in a formatti...
Definition: color.h:643
FMT_CONSTEXPR text_style operator|(emphasis lhs, emphasis rhs) noexcept
Definition: color.h:322
void print(std::FILE *f, const text_style &ts, const S &format_str, const Args &... args)
\rst Formats a string and prints it to the specified file stream using ANSI escape sequences to speci...
Definition: color.h:508
FMT_CONSTEXPR text_style fg(detail::color_type foreground) noexcept
Creates a text style from the foreground (text) color.
Definition: color.h:313
auto format_to(OutputIt out, const text_style &ts, const S &format_str, Args &&... args) -> typename std::enable_if< enable, OutputIt >::type
\rst Formats arguments with the given text_style, writes the result to the output iterator out and re...
Definition: color.h:587
FMT_CONSTEXPR ansi_color_escape< Char > make_background_color(detail::color_type background) noexcept
Definition: color.h:416
emphasis
Definition: color.h:179
void vformat_to(buffer< Char > &buf, const text_style &ts, basic_string_view< Char > format_str, basic_format_args< buffer_context< type_identity_t< Char > > > args)
Definition: color.h:457
terminal_color
Definition: color.h:160
color
Definition: color.h:16
@ light_golden_rod_yellow
std::basic_string< Char > format(const text_style &ts, const S &format_str, const Args &... args)
\rst Formats arguments and returns the result as a string using ANSI escape sequences to specify text...
Definition: color.h:553
FMT_CONSTEXPR ansi_color_escape< Char > make_foreground_color(detail::color_type foreground) noexcept
Definition: color.h:410
FMT_END_DETAIL_NAMESPACE void vprint(std::FILE *f, const text_style &ts, const S &format, basic_format_args< buffer_context< type_identity_t< Char > > > args)
Definition: color.h:483
std::basic_string< Char > vformat(const text_style &ts, const S &format_str, basic_format_args< buffer_context< type_identity_t< Char > > > args)
Definition: color.h:532
FMT_CONSTEXPR text_style bg(detail::color_type background) noexcept
Creates a text style from the background color.
Definition: color.h:318
void reset_color(FILE *stream)
Definition: color.h:438
void reset_color< wchar_t >(FILE *stream)
Definition: color.h:442
FMT_CONSTEXPR ansi_color_escape< Char > make_emphasis(emphasis em) noexcept
Definition: color.h:422
void fputs< wchar_t >(const wchar_t *chars, FILE *stream)
Definition: color.h:432