15 #ifdef FMT_DEPRECATED_COLORS 21 template <
typename... Args>
23 const Args & ... args) {
26 template <
typename... Args>
28 const Args & ... args) {
29 vprint_colored(c, format_str, make_format_args<wformat_context>(args...));
33 char escape[] =
"\x1b[30m";
34 escape[3] =
static_cast<char>(
'0' + c);
37 std::fputs(internal::data::RESET_COLOR, stdout);
41 wchar_t escape[] = L
"\x1b[30m";
42 escape[3] =
static_cast<wchar_t>(
'0' + c);
43 std::fputws(escape, stdout);
45 std::fputws(internal::data::WRESET_COLOR, stdout);
226 : r(r_), g(g_), b(b_) {}
228 : r((hex >> 16) & 0xFF), g((hex >> 8) & 0xFF), b((hex) & 0xFF) {}
230 : r((uint32_t(hex) >> 16) & 0xFF), g((uint32_t(hex) >> 8) & 0xFF),
231 b(uint32_t(hex) & 0xFF) {}
242 : is_rgb(),
value{} {}
244 : is_rgb(
true),
value{} {
245 value.rgb_color =
static_cast<uint32_t
>(rgb_color);
248 : is_rgb(
true),
value{} {
249 value.rgb_color = (
static_cast<uint32_t
>(rgb_color.r) << 16)
250 | (
static_cast<uint32_t
>(rgb_color.g) << 8) | rgb_color.b;
253 : is_rgb(),
value{} {
254 value.term_color =
static_cast<uint8_t
>(term_color);
268 : set_foreground_color(), set_background_color(), ems(em) {}
271 if (!set_foreground_color) {
272 set_foreground_color = rhs.set_foreground_color;
273 foreground_color = rhs.foreground_color;
274 }
else if (rhs.set_foreground_color) {
275 if (!foreground_color.is_rgb || !rhs.foreground_color.
is_rgb)
277 foreground_color.value.rgb_color |= rhs.foreground_color.
value.
rgb_color;
280 if (!set_background_color) {
281 set_background_color = rhs.set_background_color;
282 background_color = rhs.background_color;
283 }
else if (rhs.set_background_color) {
284 if (!background_color.is_rgb || !rhs.background_color.
is_rgb)
286 background_color.value.rgb_color |= rhs.background_color.
value.
rgb_color;
289 ems =
static_cast<emphasis>(
static_cast<uint8_t
>(ems) |
290 static_cast<uint8_t>(rhs.ems));
300 if (!set_foreground_color) {
301 set_foreground_color = rhs.set_foreground_color;
302 foreground_color = rhs.foreground_color;
303 }
else if (rhs.set_foreground_color) {
304 if (!foreground_color.is_rgb || !rhs.foreground_color.
is_rgb)
306 foreground_color.value.rgb_color &= rhs.foreground_color.
value.
rgb_color;
309 if (!set_background_color) {
310 set_background_color = rhs.set_background_color;
311 background_color = rhs.background_color;
312 }
else if (rhs.set_background_color) {
313 if (!background_color.is_rgb || !rhs.background_color.
is_rgb)
315 background_color.value.rgb_color &= rhs.background_color.
value.
rgb_color;
318 ems =
static_cast<emphasis>(
static_cast<uint8_t
>(ems) &
319 static_cast<uint8_t>(rhs.ems));
329 return set_foreground_color;
332 return set_background_color;
335 return static_cast<uint8_t
>(ems) != 0;
338 assert(has_foreground() &&
"no foreground specified for this style");
339 return foreground_color;
342 assert(has_background() &&
"no background specified for this style");
343 return background_color;
346 assert(has_emphasis() &&
"no emphasis specified for this style");
353 : set_foreground_color(),
354 set_background_color(),
357 foreground_color = text_color;
358 set_foreground_color =
true;
360 background_color = text_color;
361 set_background_color =
true;
372 bool set_foreground_color;
373 bool set_background_color;
391 template <
typename Char>
397 if (!text_color.is_rgb) {
398 bool is_background = esc == internal::data::BACKGROUND_COLOR;
405 std::size_t index = 0;
406 buffer[index++] =
static_cast<Char
>(
'\x1b');
407 buffer[index++] =
static_cast<Char
>(
'[');
410 buffer[index++] =
static_cast<Char
>(
'1');
413 buffer[index++] =
static_cast<Char
>(
'0' + value / 10u);
414 buffer[index++] =
static_cast<Char
>(
'0' + value % 10u);
416 buffer[index++] =
static_cast<Char
>(
'm');
417 buffer[index++] =
static_cast<Char
>(
'\0');
421 for (
int i = 0; i < 7; i++) {
422 buffer[i] =
static_cast<Char
>(esc[i]);
424 rgb color(text_color.value.rgb_color);
425 to_esc(color.
r,
buffer + 7,
';');
426 to_esc(color.
g,
buffer + 11,
';');
427 to_esc(color.
b,
buffer + 15,
'm');
428 buffer[19] =
static_cast<Char
>(0);
431 uint8_t em_codes[4] = {};
432 uint8_t em_bits =
static_cast<uint8_t
>(em);
433 if (em_bits & static_cast<uint8_t>(emphasis::bold))
435 if (em_bits & static_cast<uint8_t>(emphasis::italic))
437 if (em_bits & static_cast<uint8_t>(emphasis::underline))
439 if (em_bits & static_cast<uint8_t>(emphasis::strikethrough))
442 std::size_t index = 0;
443 for (
int i = 0; i < 4; ++i) {
446 buffer[index++] =
static_cast<Char
>(
'\x1b');
447 buffer[index++] =
static_cast<Char
>(
'[');
448 buffer[index++] =
static_cast<Char
>(
'0' + em_codes[i]);
449 buffer[index++] =
static_cast<Char
>(
'm');
451 buffer[index++] =
static_cast<Char
>(0);
456 Char
buffer[7u + 3u * 4u + 1u];
460 out[0] =
static_cast<Char
>(
'0' + c / 100);
461 out[1] =
static_cast<Char
>(
'0' + c / 10 % 10);
462 out[2] =
static_cast<Char
>(
'0' + c % 10);
463 out[3] =
static_cast<Char
>(delimiter);
467 template <
typename Char>
473 template <
typename Char>
479 template <
typename Char>
485 template <
typename Char>
492 std::fputws(chars, stream);
495 template <
typename Char>
497 fputs(internal::data::RESET_COLOR, stream);
502 fputs(internal::data::WRESET_COLOR, stream);
512 struct is_string<const std::FILE *> : std::false_type {};
519 bool has_style =
false;
522 internal::fputs<Char>(
527 internal::fputs<Char>(
532 internal::fputs<Char>(
537 internal::reset_color<Char>(f);
548 template <
typename String,
typename... Args>
549 typename std::enable_if<internal::is_string<String>::value>
::type print(
550 std::FILE *f,
const text_style &ts,
const String &format_str,
551 const Args &... args) {
566 template <
typename String,
typename... Args>
567 typename std::enable_if<internal::is_string<String>::value>
::type print(
568 const text_style &ts,
const String &format_str,
569 const Args &... args) {
570 return print(stdout, ts, format_str, args...);
577 #endif // FMT_COLOR_H_
text_style & operator&=(const text_style &rhs)
color_type(rgb rgb_color)
text_style operator|(emphasis lhs, emphasis rhs)
std::enable_if< internal::is_string< String >::value >::type print(const text_style &ts, const String &format_str, const Args &...args)
friend text_style operator|(text_style lhs, const text_style &rhs)
color_type(color rgb_color)
friend text_style operator&(text_style lhs, const text_style &rhs)
void vprint(std::FILE *f, const text_style &ts, const S &format, basic_format_args< typename buffer_context< Char >::type > args)
rgb(uint8_t r_, uint8_t g_, uint8_t b_)
#define FMT_CONSTEXPR_DECL
bool has_foreground() const
void reset_color< wchar_t >(FILE *stream)
ansi_color_escape(emphasis em)
color_type(terminal_color term_color)
#define FMT_END_NAMESPACE
ansi_color_escape< Char > make_emphasis(emphasis em)
void reset_color(FILE *stream)
ansi_color_escape< Char > make_background_color(internal::color_type background)
basic_string_view< wchar_t > wstring_view
void fputs(const Char *chars, FILE *stream)
union fmt::v5::internal::color_type::color_union value
emphasis get_emphasis() const
basic_buffer< char > buffer
ansi_color_escape(internal::color_type text_color, const char *esc)
format_arg_store< Context, Args... > make_format_args(const Args &...args)
internal::color_type get_background() const
text_style fg(internal::color_type foreground)
std::basic_string< typename char_t< S >::type > format(const S &format_str, const Args &...args)
text_style(emphasis em=emphasis())
ansi_color_escape< Char > make_foreground_color(internal::color_type foreground)
bool has_background() const
void fputs< wchar_t >(const wchar_t *chars, FILE *stream)
#define FMT_BEGIN_NAMESPACE
internal::color_type get_foreground() const
text_style bg(internal::color_type background)
std::enable_if<!is_compile_string< S >::value >::type check_format_string(const S &)
text_style & operator|=(const text_style &rhs)
basic_string_view< char > string_view
bool has_emphasis() const