15# define FMT_DEPRECATED_NONMSVC
17# define FMT_DEPRECATED_NONMSVC FMT_DEPRECATED
199 :
r((
hex >> 16) & 0xFF),
g((
hex >> 8) & 0xFF),
b(
hex & 0xFF) {}
201 :
r((uint32_t(
hex) >> 16) & 0xFF),
202 g((uint32_t(
hex) >> 8) & 0xFF),
203 b(uint32_t(
hex) & 0xFF) {}
216 value.rgb_color =
static_cast<uint32_t
>(rgb_color);
219 value.rgb_color = (
static_cast<uint32_t
>(rgb_color.r) << 16) |
220 (
static_cast<uint32_t
>(rgb_color.g) << 8) | rgb_color.b;
224 value.term_color =
static_cast<uint8_t
>(term_color);
263 static_cast<uint8_t
>(rhs.
ems));
289 return static_cast<uint8_t
>(
ems) != 0;
340 static_cast<uint8_t
>(rhs.
ems));
379 if (!text_color.is_rgb) {
380 bool is_background = esc ==
string_view(
"\x1b[48;2;");
384 if (is_background)
value += 10u;
402 for (
int i = 0; i < 7; i++) {
403 buffer[i] =
static_cast<Char
>(esc[i]);
405 rgb color(text_color.value.rgb_color);
409 buffer[19] =
static_cast<Char
>(0);
412 uint8_t em_codes[4] = {};
413 uint8_t em_bits =
static_cast<uint8_t
>(em);
414 if (em_bits &
static_cast<uint8_t
>(
emphasis::bold)) em_codes[0] = 1;
421 for (
int i = 0; i < 4; ++i) {
422 if (!em_codes[i])
continue;
425 buffer[
index++] =
static_cast<Char
>(
'0' + em_codes[i]);
442 out[0] =
static_cast<Char
>(
'0' + c / 100);
443 out[1] =
static_cast<Char
>(
'0' + c / 10 % 10);
444 out[2] =
static_cast<Char
>(
'0' + c % 10);
445 out[3] =
static_cast<Char
>(delimiter);
449template <
typename Char>
455template <
typename Char>
461template <
typename Char>
466template <
typename Char>
477 fputs(
"\x1b[0m", stream);
481 fputs(L
"\x1b[0m", stream);
484template <
typename Char>
490template <
typename Char>
494 bool has_style =
false;
502 auto foreground = detail::make_foreground_color<Char>(ts.
get_foreground());
503 buf.
append(foreground.begin(), foreground.end());
507 auto background = detail::make_background_color<Char>(ts.
get_background());
508 buf.
append(background.begin(), background.end());
510 detail::vformat_to(buf, format_str, args, {});
511 if (has_style) detail::reset_color<Char>(buf);
516template <
typename S,
typename Char =
char_t<S>>
520 detail::vformat_to(buf, ts, to_string_view(
format), args);
521 buf.push_back(Char(0));
522 detail::fputs(buf.data(), f);
536template <
typename S,
typename... Args,
539 const Args&... args) {
541 fmt::make_args_checked<Args...>(format_str, args...));
555template <
typename S,
typename... Args,
558 return print(stdout, ts, format_str, args...);
561template <
typename S,
typename Char =
char_t<S>>
566 detail::vformat_to(buf, ts, to_string_view(format_str), args);
567 return fmt::to_string(buf);
582template <
typename S,
typename... Args,
typename Char =
char_t<S>>
584 const Args&... args) {
585 return fmt::vformat(ts, to_string_view(format_str),
586 fmt::make_args_checked<Args...>(format_str, args...));
592template <
typename OutputIt,
typename Char,
593 FMT_ENABLE_IF(detail::is_output_iterator<OutputIt, Char>::value)>
597 auto&& buf = detail::get_buffer<Char>(out);
598 detail::vformat_to(buf, ts, format_str, args);
599 return detail::get_iterator(buf);
614template <
typename OutputIt,
typename S,
typename... Args,
615 bool enable = detail::is_output_iterator<OutputIt, char_t<S>>
::value&&
616 detail::is_string<S>::value>
620 return vformat_to(out, ts, to_string_view(format_str),
621 fmt::make_args_checked<Args...>(format_str, args...));
void append(const U *begin, const U *end)
friend FMT_CONSTEXPR_DECL text_style bg(detail::color_type background) FMT_NOEXCEPT
friend FMT_CONSTEXPR text_style operator|(text_style lhs, const text_style &rhs)
FMT_CONSTEXPR detail::color_type get_background() const FMT_NOEXCEPT
FMT_CONSTEXPR bool has_emphasis() const FMT_NOEXCEPT
FMT_CONSTEXPR text_style(emphasis em=emphasis()) FMT_NOEXCEPT
FMT_CONSTEXPR text_style & operator|=(const text_style &rhs)
bool set_foreground_color
friend FMT_CONSTEXPR_DECL text_style fg(detail::color_type foreground) FMT_NOEXCEPT
FMT_CONSTEXPR detail::color_type get_foreground() const FMT_NOEXCEPT
FMT_DEPRECATED_NONMSVC friend FMT_CONSTEXPR text_style operator&(text_style lhs, const text_style &rhs)
FMT_CONSTEXPR bool has_foreground() const FMT_NOEXCEPT
FMT_CONSTEXPR text_style(bool is_foreground, detail::color_type text_color) FMT_NOEXCEPT
detail::color_type background_color
FMT_CONSTEXPR text_style & and_assign(const text_style &rhs)
FMT_CONSTEXPR emphasis get_emphasis() const FMT_NOEXCEPT
detail::color_type foreground_color
FMT_DEPRECATED_NONMSVC FMT_CONSTEXPR text_style & operator&=(const text_style &rhs)
bool set_background_color
FMT_CONSTEXPR bool has_background() const FMT_NOEXCEPT
constexpr FMT_INLINE value()
void print(std::FILE *f, const text_style &ts, const S &format_str, const Args &... args)
auto format_to(OutputIt out, const text_style &ts, const S &format_str, Args &&... args) -> typename std::enable_if< enable, OutputIt >::type
FMT_CONSTEXPR ansi_color_escape< Char > make_background_color(detail::color_type background) FMT_NOEXCEPT
FMT_CONSTEXPR text_style operator|(emphasis lhs, emphasis rhs) FMT_NOEXCEPT
void reset_color(FILE *stream) FMT_NOEXCEPT
FMT_CONSTEXPR text_style fg(detail::color_type foreground) FMT_NOEXCEPT
FMT_CONSTEXPR ansi_color_escape< Char > make_emphasis(emphasis em) FMT_NOEXCEPT
#define FMT_DEPRECATED_NONMSVC
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)
FMT_CONSTEXPR ansi_color_escape< Char > make_foreground_color(detail::color_type foreground) FMT_NOEXCEPT
@ light_golden_rod_yellow
std::basic_string< Char > format(const text_style &ts, const S &format_str, const Args &... args)
void fputs< wchar_t >(const wchar_t *chars, FILE *stream) FMT_NOEXCEPT
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)
void fputs(const Char *chars, FILE *stream) FMT_NOEXCEPT
std::basic_string< Char > vformat(const text_style &ts, const S &format_str, basic_format_args< buffer_context< type_identity_t< Char > > > args)
void reset_color< wchar_t >(FILE *stream) FMT_NOEXCEPT
FMT_CONSTEXPR text_style bg(detail::color_type background) FMT_NOEXCEPT
#define FMT_ASSERT(condition, message)
typename detail::char_t_impl< S >::type char_t
#define FMT_END_DETAIL_NAMESPACE
#define FMT_MODULE_EXPORT_BEGIN
#define FMT_BEGIN_NAMESPACE
#define FMT_BEGIN_DETAIL_NAMESPACE
#define FMT_ENABLE_IF(...)
#define FMT_CONSTEXPR_CHAR_TRAITS
typename type_identity< T >::type type_identity_t
#define FMT_END_NAMESPACE
#define FMT_MODULE_EXPORT_END
#define FMT_CONSTEXPR_DECL
FMT_CONSTEXPR_CHAR_TRAITS const Char * end() const FMT_NOEXCEPT
Char buffer[7u+3u *4u+1u]
FMT_CONSTEXPR ansi_color_escape(detail::color_type text_color, const char *esc) FMT_NOEXCEPT
FMT_CONSTEXPR ansi_color_escape(emphasis em) FMT_NOEXCEPT
static FMT_CONSTEXPR void to_esc(uint8_t c, Char *out, char delimiter) FMT_NOEXCEPT
FMT_CONSTEXPR const Char * begin() const FMT_NOEXCEPT
FMT_CONSTEXPR color_type() FMT_NOEXCEPT
FMT_CONSTEXPR color_type(color rgb_color) FMT_NOEXCEPT
FMT_CONSTEXPR color_type(rgb rgb_color) FMT_NOEXCEPT
FMT_CONSTEXPR color_type(terminal_color term_color) FMT_NOEXCEPT
union color_type::color_union value
FMT_CONSTEXPR rgb(uint32_t hex)
FMT_CONSTEXPR rgb(uint8_t r_, uint8_t g_, uint8_t b_)
FMT_CONSTEXPR rgb(color hex)