194 constexpr rgb(uint8_t r_, uint8_t g_, uint8_t b_) :
r(r_),
g(g_),
b(b_) {}
196 :
r((
hex >> 16) & 0xFF),
g((
hex >> 8) & 0xFF),
b(
hex & 0xFF) {}
198 :
r((uint32_t(
hex) >> 16) & 0xFF),
199 g((uint32_t(
hex) >> 8) & 0xFF),
200 b(uint32_t(
hex) & 0xFF) {}
213 :
value_(static_cast<uint32_t>(rgb_color) | (1 << 24)) {}
216 (
static_cast<uint32_t
>(rgb_color.r) << 16) |
217 (
static_cast<uint32_t
>(rgb_color.g) << 8) | rgb_color.b)) {}
219 :
value_(
static_cast<uint32_t
>(term_color) | (3 << 24)) {}
222 return (
value_ & (1 << 25)) != 0;
225 constexpr auto value() const noexcept -> uint32_t {
291 : style_(static_cast<uint64_t>(em) << 54) {}
294 if (((style_ + rhs.style_) & ((1ULL << 26) | (1ULL << 53))) != 0)
296 style_ |= rhs.style_;
306 return style_ == rhs.style_;
310 return !(*
this == rhs);
314 return (style_ & (1 << 24)) != 0;
317 return (style_ & (1ULL << 51)) != 0;
320 return (style_ >> 54) != 0;
324 return style_ & 0x3FFFFFF;
328 return (style_ >> 27) & 0x3FFFFFF;
332 return static_cast<emphasis>(style_ >> 54);
350 return foreground.value_;
356 return static_cast<uint64_t
>(background.value_) << 27;
368 const char* esc)
noexcept {
371 if (text_color.is_terminal_color()) {
372 bool is_background = esc ==
string_view(
"\x1b[48;2;");
376 if (is_background)
value += 10u;
378 buffer[size++] =
static_cast<Char
>(
'\x1b');
379 buffer[size++] =
static_cast<Char
>(
'[');
382 buffer[size++] =
static_cast<Char
>(
'1');
385 buffer[size++] =
static_cast<Char
>(
'0' +
value / 10u);
386 buffer[size++] =
static_cast<Char
>(
'0' +
value % 10u);
388 buffer[size++] =
static_cast<Char
>(
'm');
392 for (
int i = 0; i < 7; i++) {
393 buffer[i] =
static_cast<Char
>(esc[i]);
396 to_esc(
color.r, buffer + 7,
';');
397 to_esc(
color.g, buffer + 11,
';');
398 to_esc(
color.b, buffer + 15,
'm');
402 uint8_t em_codes[num_emphases] = {};
412 buffer[size++] =
static_cast<Char
>(
'\x1b');
413 buffer[size++] =
static_cast<Char
>(
'[');
415 for (
size_t i = 0; i < num_emphases; ++i) {
416 if (!em_codes[i])
continue;
417 buffer[size++] =
static_cast<Char
>(
'0' + em_codes[i]);
418 buffer[size++] =
static_cast<Char
>(
';');
421 buffer[size - 1] =
static_cast<Char
>(
'm');
427 return buffer + size;
431 static constexpr size_t num_emphases = 8;
432 Char
buffer[7u + 4u * num_emphases] = {};
436 char delimiter)
noexcept {
437 out[0] =
static_cast<Char
>(
'0' + c / 100);
438 out[1] =
static_cast<Char
>(
'0' + c / 10 % 10);
439 out[2] =
static_cast<Char
>(
'0' + c % 10);
440 out[3] =
static_cast<Char
>(delimiter);
444 return static_cast<uint8_t
>(em) &
static_cast<uint8_t
>(mask);
448template <
typename Char>
454template <
typename Char>
460template <
typename Char>
477template <
typename Char>
486 buf.
append(foreground.begin(), foreground.end());
490 buf.
append(background.begin(), background.end());
512template <
typename... T>
526template <
typename... T>
528 return print(stdout, ts, fmt, std::forward<T>(args)...);
535 return fmt::to_string(buf);
550template <
typename... T>
553 return fmt::vformat(ts, fmt.str,
vargs<T...>{{args...}});
557template <
typename OutputIt,
576template <
typename OutputIt,
typename... T,
579 T&&... args) -> OutputIt {
583template <
typename T,
typename Char>
585 template <
typename FormatContext>
587 ->
decltype(ctx.out()) {
588 const auto& ts =
arg.style;
589 auto out = ctx.out();
591 bool has_style =
false;
592 if (ts.has_emphasis()) {
597 if (ts.has_foreground()) {
603 if (ts.has_background()) {
#define FMT_ASSERT(condition, message)
Definition base.h:394
#define FMT_END_EXPORT
Definition base.h:267
basic_string_view< char > string_view
Definition base.h:620
auto arg(const Char *name, const T &arg) -> detail::named_arg< Char, T >
Returns a named argument to be used in a formatting function.
Definition base.h:2846
detail::format_arg_store< context, sizeof...(T), detail::count_named_args< T... >(), detail::make_descriptor< context, T... >()> vargs
Definition base.h:2832
typename fstring< T... >::t format_string
Definition base.h:2794
#define FMT_CONSTEXPR
Definition base.h:113
#define FMT_BEGIN_NAMESPACE
Definition base.h:256
#define FMT_ENABLE_IF(...)
Definition base.h:344
#define FMT_BEGIN_EXPORT
Definition base.h:266
basic_format_args< context > format_args
Definition base.h:651
@ hex
Definition base.h:673
#define FMT_END_NAMESPACE
Definition base.h:259
conditional_t< std::is_same< Char, char >::value, context, generic_context< basic_appender< Char >, Char > > buffered_context
Definition base.h:642
An implementation of std::basic_string_view for pre-C++17.
Definition base.h:522
A contiguous memory buffer with an optional growing ability.
Definition base.h:1773
FMT_CONSTEXPR20 void append(const U *begin, const U *end)
Appends data to the end of the buffer.
Definition base.h:1855
constexpr FMT_INLINE value()
Definition base.h:2201
A text style consisting of foreground and background colors and emphasis.
Definition color.h:236
FMT_CONSTEXPR auto has_background() const noexcept -> bool
Definition color.h:316
FMT_CONSTEXPR auto get_emphasis() const noexcept -> emphasis
Definition color.h:330
FMT_CONSTEXPR auto operator|=(text_style rhs) -> text_style &
Definition color.h:293
FMT_CONSTEXPR text_style(emphasis em=emphasis()) noexcept
Definition color.h:290
friend FMT_CONSTEXPR auto operator|(text_style lhs, text_style rhs) -> text_style
Definition color.h:300
friend FMT_CONSTEXPR auto fg(detail::color_type foreground) noexcept -> text_style
Creates a text style from the foreground (text) color.
Definition color.h:348
friend FMT_CONSTEXPR auto bg(detail::color_type background) noexcept -> text_style
Creates a text style from the background color.
Definition color.h:354
FMT_CONSTEXPR auto operator!=(text_style rhs) const noexcept -> bool
Definition color.h:309
FMT_CONSTEXPR auto has_foreground() const noexcept -> bool
Definition color.h:313
FMT_CONSTEXPR auto get_foreground() const noexcept -> detail::color_type
Definition color.h:322
FMT_CONSTEXPR auto has_emphasis() const noexcept -> bool
Definition color.h:319
FMT_CONSTEXPR auto get_background() const noexcept -> detail::color_type
Definition color.h:326
FMT_CONSTEXPR auto operator==(text_style rhs) const noexcept -> bool
Definition color.h:305
auto vformat_to(OutputIt out, text_style ts, string_view fmt, format_args args) -> OutputIt
Formats a string with the given text_style and writes the output to out.
Definition color.h:559
auto format_to(OutputIt out, text_style ts, format_string< T... > fmt, T &&... args) -> OutputIt
Formats arguments with the given text style, writes the result to the output iterator out and returns...
Definition color.h:578
FMT_CONSTEXPR auto styled(const T &value, text_style ts) -> detail::styled_arg< remove_cvref_t< T > >
Returns an argument that will be formatted using ANSI escape sequences, to be used in a formatting fu...
Definition color.h:629
emphasis
Definition color.h:179
@ italic
Definition color.h:182
@ blink
Definition color.h:184
@ reverse
Definition color.h:185
@ bold
Definition color.h:180
@ underline
Definition color.h:183
@ conceal
Definition color.h:186
@ faint
Definition color.h:181
@ strikethrough
Definition color.h:187
auto format(text_style ts, format_string< T... > fmt, T &&... args) -> std::string
Formats arguments and returns the result as a string using ANSI escape sequences to specify text form...
Definition color.h:551
FMT_CONSTEXPR auto operator|(emphasis lhs, emphasis rhs) noexcept -> text_style
Definition color.h:359
terminal_color
Definition color.h:160
@ bright_magenta
Definition color.h:174
@ bright_black
Definition color.h:169
@ bright_yellow
Definition color.h:172
@ bright_red
Definition color.h:170
@ bright_green
Definition color.h:171
@ bright_blue
Definition color.h:173
@ bright_cyan
Definition color.h:175
@ bright_white
Definition color.h:176
FMT_CONSTEXPR auto fg(detail::color_type foreground) noexcept -> text_style
Creates a text style from the foreground (text) color.
Definition color.h:348
FMT_CONSTEXPR auto bg(detail::color_type background) noexcept -> text_style
Creates a text style from the background color.
Definition color.h:354
color
Definition color.h:16
@ tomato
Definition color.h:150
@ steel_blue
Definition color.h:146
@ maroon
Definition color.h:97
@ misty_rose
Definition color.h:109
@ cadet_blue
Definition color.h:30
@ saddle_brown
Definition color.h:134
@ papaya_whip
Definition color.h:123
@ khaki
Definition color.h:75
@ lavender
Definition color.h:76
@ salmon
Definition color.h:135
@ black
Definition color.h:24
@ blue_violet
Definition color.h:27
@ dark_blue
Definition color.h:38
@ mint_cream
Definition color.h:108
@ medium_purple
Definition color.h:101
@ snow
Definition color.h:144
@ gainsboro
Definition color.h:63
@ sea_green
Definition color.h:137
@ olive_drab
Definition color.h:115
@ fire_brick
Definition color.h:59
@ peru
Definition color.h:125
@ deep_pink
Definition color.h:55
@ white_smoke
Definition color.h:155
@ deep_sky_blue
Definition color.h:56
@ ghost_white
Definition color.h:64
@ medium_aquamarine
Definition color.h:98
@ aquamarine
Definition color.h:20
@ teal
Definition color.h:148
@ plum
Definition color.h:127
@ chartreuse
Definition color.h:31
@ royal_blue
Definition color.h:133
@ lawn_green
Definition color.h:78
@ dark_slate_blue
Definition color.h:51
@ blue
Definition color.h:26
@ dark_gray
Definition color.h:41
@ pink
Definition color.h:126
@ dark_violet
Definition color.h:54
@ magenta
Definition color.h:96
@ medium_turquoise
Definition color.h:105
@ light_cyan
Definition color.h:82
@ medium_spring_green
Definition color.h:104
@ dark_salmon
Definition color.h:49
@ antique_white
Definition color.h:18
@ dark_sea_green
Definition color.h:50
@ pale_green
Definition color.h:120
@ pale_golden_rod
Definition color.h:119
@ light_coral
Definition color.h:81
@ dark_orchid
Definition color.h:47
@ tan
Definition color.h:147
@ dodger_blue
Definition color.h:58
@ old_lace
Definition color.h:113
@ crimson
Definition color.h:36
@ dark_green
Definition color.h:42
@ light_pink
Definition color.h:86
@ light_blue
Definition color.h:80
@ light_salmon
Definition color.h:87
@ cyan
Definition color.h:37
@ aqua
Definition color.h:19
@ navajo_white
Definition color.h:111
@ spring_green
Definition color.h:145
@ lime
Definition color.h:93
@ light_sky_blue
Definition color.h:89
@ lime_green
Definition color.h:94
@ alice_blue
Definition color.h:17
@ rosy_brown
Definition color.h:132
@ brown
Definition color.h:28
@ pale_turquoise
Definition color.h:121
@ rebecca_purple
Definition color.h:130
@ medium_blue
Definition color.h:99
@ light_yellow
Definition color.h:92
@ dim_gray
Definition color.h:57
@ powder_blue
Definition color.h:128
@ light_gray
Definition color.h:84
@ blanched_almond
Definition color.h:25
@ midnight_blue
Definition color.h:107
@ indigo
Definition color.h:73
@ lemon_chiffon
Definition color.h:79
@ indian_red
Definition color.h:72
@ golden_rod
Definition color.h:66
@ slate_blue
Definition color.h:142
@ dark_golden_rod
Definition color.h:40
@ sienna
Definition color.h:139
@ orchid
Definition color.h:118
@ thistle
Definition color.h:149
@ forest_green
Definition color.h:61
@ silver
Definition color.h:140
@ light_sea_green
Definition color.h:88
@ floral_white
Definition color.h:60
@ medium_slate_blue
Definition color.h:103
@ sandy_brown
Definition color.h:136
@ dark_red
Definition color.h:48
@ hot_pink
Definition color.h:71
@ green
Definition color.h:68
@ fuchsia
Definition color.h:62
@ dark_magenta
Definition color.h:44
@ linen
Definition color.h:95
@ yellow_green
Definition color.h:157
@ dark_orange
Definition color.h:46
@ light_steel_blue
Definition color.h:91
@ pale_violet_red
Definition color.h:122
@ dark_olive_green
Definition color.h:45
@ purple
Definition color.h:129
@ cornflower_blue
Definition color.h:34
@ light_slate_gray
Definition color.h:90
@ red
Definition color.h:131
@ dark_cyan
Definition color.h:39
@ light_green
Definition color.h:85
@ chocolate
Definition color.h:32
@ ivory
Definition color.h:74
@ medium_sea_green
Definition color.h:102
@ bisque
Definition color.h:23
@ gray
Definition color.h:67
@ azure
Definition color.h:21
@ sky_blue
Definition color.h:141
@ violet
Definition color.h:152
@ burly_wood
Definition color.h:29
@ wheat
Definition color.h:153
@ coral
Definition color.h:33
@ honey_dew
Definition color.h:70
@ green_yellow
Definition color.h:69
@ light_golden_rod_yellow
Definition color.h:83
@ yellow
Definition color.h:156
@ white
Definition color.h:154
@ lavender_blush
Definition color.h:77
@ moccasin
Definition color.h:110
@ turquoise
Definition color.h:151
@ medium_orchid
Definition color.h:100
@ gold
Definition color.h:65
@ dark_khaki
Definition color.h:43
@ dark_slate_gray
Definition color.h:52
@ peach_puff
Definition color.h:124
@ medium_violet_red
Definition color.h:106
@ orange_red
Definition color.h:117
@ cornsilk
Definition color.h:35
@ beige
Definition color.h:22
@ sea_shell
Definition color.h:138
@ navy
Definition color.h:112
@ olive
Definition color.h:114
@ slate_gray
Definition color.h:143
@ dark_turquoise
Definition color.h:53
@ orange
Definition color.h:116
void print(FILE *f, text_style ts, format_string< T... > fmt, T &&... args)
Formats a string and prints it to the specified file stream using ANSI escape sequences to specify te...
Definition color.h:513
void vprint(FILE *f, text_style ts, string_view fmt, format_args args)
Definition color.h:497
auto vformat(text_style ts, string_view fmt, format_args args) -> std::string
Definition color.h:531
Converts a string literal into a format string that will be parsed at compile time and converted into...
Definition printf.h:50
FMT_CONSTEXPR auto make_emphasis(emphasis em) noexcept -> ansi_color_escape< Char >
Definition color.h:461
auto get_iterator(Buf &buf, OutputIt) -> decltype(buf.out())
Definition base.h:2141
FMT_CONSTEXPR auto make_background_color(color_type background) noexcept -> ansi_color_escape< Char >
Definition color.h:455
FMT_CONSTEXPR auto make_foreground_color(color_type foreground) noexcept -> ansi_color_escape< Char >
Definition color.h:449
FMT_CONSTEXPR20 auto copy(InputIt begin, InputIt end, OutputIt out) -> OutputIt
Definition base.h:2083
FMT_FUNC void vformat_to(buffer< char > &buf, string_view fmt, format_args args, locale_ref loc)
Definition format-inl.h:1451
auto get_buffer(OutputIt out) -> iterator_buffer< OutputIt, T >
Definition base.h:2131
void reset_color(buffer< Char > &buffer)
Definition color.h:466
FMT_CONSTEXPR ansi_color_escape(color_type text_color, const char *esc) noexcept
Definition color.h:367
FMT_CONSTEXPR ansi_color_escape(emphasis em) noexcept
Definition color.h:401
FMT_CONSTEXPR auto begin() const noexcept -> const Char *
Definition color.h:425
FMT_CONSTEXPR auto end() const noexcept -> const Char *
Definition color.h:426
constexpr color_type(rgb rgb_color) noexcept
Definition color.h:214
constexpr color_type(uint32_t value) noexcept
Definition color.h:229
constexpr color_type() noexcept=default
uint32_t value_
Definition color.h:231
constexpr color_type(terminal_color term_color) noexcept
Definition color.h:218
constexpr auto value() const noexcept -> uint32_t
Definition color.h:225
constexpr auto is_terminal_color() const noexcept -> bool
Definition color.h:221
text_style style
Definition color.h:473
styled_arg(const T &v, text_style s)
Definition color.h:474
const T & value
Definition color.h:472
constexpr rgb(color hex)
Definition color.h:197
constexpr rgb(uint8_t r_, uint8_t g_, uint8_t b_)
Definition color.h:194
uint8_t b
Definition color.h:203
uint8_t g
Definition color.h:202
constexpr rgb(uint32_t hex)
Definition color.h:195
constexpr rgb()
Definition color.h:193
uint8_t r
Definition color.h:201