202 :
r(r_),
g(g_),
b(b_)
206 :
r((
hex >> 16) & 0xFF),
g((
hex >> 8) & 0xFF),
b(
hex & 0xFF)
210 :
r((uint32_t(
hex) >> 16) & 0xFF),
211 g((uint32_t(
hex) >> 8) & 0xFF),
212 b(uint32_t(
hex) & 0xFF)
232 value.rgb_color =
static_cast<uint32_t
>(rgb_color);
237 value.rgb_color = (
static_cast<uint32_t
>(rgb_color.r) << 16) |
238 (
static_cast<uint32_t
>(rgb_color.g) << 8) | rgb_color.b;
243 value.term_color =
static_cast<uint8_t
>(term_color);
290 static_cast<uint8_t
>(rhs.
ems));
310 return static_cast<uint8_t
>(
ems) != 0;
330 detail::color_type text_color) noexcept
375template <
typename Char>
379 const char* esc)
noexcept
383 if (!text_color.is_rgb)
385 bool is_background = esc ==
string_view(
"\x1b[48;2;");
409 for (
int i = 0;
i < 7;
i++)
411 buffer[
i] =
static_cast<Char
>(esc[
i]);
413 rgb color(text_color.value.rgb_color);
417 buffer[19] =
static_cast<Char
>(0);
471 out[0] =
static_cast<Char
>(
'0' + c / 100);
472 out[1] =
static_cast<Char
>(
'0' + c / 10 % 10);
473 out[2] =
static_cast<Char
>(
'0' + c % 10);
474 out[3] =
static_cast<Char
>(delimiter);
478 return static_cast<uint8_t
>(
em) &
static_cast<uint8_t
>(mask);
482template <
typename Char>
484 detail::color_type foreground)
noexcept
489template <
typename Char>
491 detail::color_type background)
noexcept
496template <
typename Char>
502template <
typename Char>
503inline void fputs(
const Char* chars, FILE* stream)
505 int result = std::fputs(chars, stream);
513 int result = std::fputws(chars, stream);
518template <
typename Char>
521 fputs(
"\x1b[0m", stream);
527 fputs(L
"\x1b[0m", stream);
530template <
typename Char>
544template <
typename Char>
547 bool has_style =
false;
557 auto foreground = detail::make_foreground_color<Char>(ts.
get_foreground());
558 buf.
append(foreground.begin(), foreground.end());
563 auto background = detail::make_background_color<Char>(ts.
get_background());
564 buf.
append(background.begin(), background.end());
566 detail::vformat_to(buf, format_str, args, {});
568 detail::reset_color<Char>(buf);
573template <
typename S,
typename Char =
char_t<S>>
577 detail::vformat_to(buf, ts, detail::to_string_view(
format), args);
578 if (detail::is_utf8())
584 buf.push_back(Char(0));
585 detail::fputs(buf.data(), f);
600template <
typename S,
typename... Args,
FMT_ENABLE_IF(detail::is_string<S>::value)>
601void print(std::FILE* f,
const text_style& ts,
const S& format_str,
const Args&... args)
618template <
typename S,
typename... Args,
FMT_ENABLE_IF(detail::is_string<S>::value)>
621 return print(stdout, ts, format_str, args...);
624template <
typename S,
typename Char =
char_t<S>>
629 detail::vformat_to(buf, ts, detail::to_string_view(format_str), args);
630 return fmt::to_string(buf);
645template <
typename S,
typename... Args,
typename Char =
char_t<S>>
646inline std::basic_string<Char>
format(
const text_style& ts,
const S& format_str,
const Args&... args)
648 return fmt::vformat(ts, detail::to_string_view(format_str),
655template <
typename OutputIt,
typename Char, FMT_ENABLE_IF(detail::is_output_iterator<OutputIt, Char>::value)>
659 auto&& buf = detail::get_buffer<Char>(
out);
660 detail::vformat_to(buf, ts, format_str, args);
661 return detail::get_iterator(buf);
676template <
typename OutputIt,
typename S,
typename... Args,
bool enable = detail::is_output_iterator<OutputIt, char_t<S>>
::value && detail::is_string<S>::value>
678 typename std::enable_if<enable, OutputIt>::type
680 return vformat_to(
out, ts, detail::to_string_view(format_str),
684template <
typename T,
typename Char>
687 template <
typename FormatContext>
688 auto format(
const detail::styled_arg<T>&
arg, FormatContext& ctx)
const
689 ->
decltype(ctx.out())
691 const auto& ts =
arg.style;
693 auto out = ctx.out();
695 bool has_style =
false;
696 if (ts.has_emphasis())
699 auto emphasis = detail::make_emphasis<Char>(ts.get_emphasis());
702 if (ts.has_foreground())
706 detail::make_foreground_color<Char>(ts.get_foreground());
707 out = std::copy(foreground.begin(), foreground.end(),
out);
709 if (ts.has_background())
713 detail::make_background_color<Char>(ts.get_background());
714 out = std::copy(background.begin(), background.end(),
out);
740 -> detail::styled_arg<remove_cvref_t<T>>
742 return detail::styled_arg<remove_cvref_t<T>>{
value, ts};
void append(const U *begin, const U *end)
FMT_CONSTEXPR bool has_emphasis() const noexcept
Definition color.h:308
friend FMT_CONSTEXPR text_style fg(detail::color_type foreground) noexcept
Definition color.h:357
friend FMT_CONSTEXPR text_style operator|(text_style lhs, const text_style &rhs)
Definition color.h:294
FMT_CONSTEXPR emphasis get_emphasis() const noexcept
Definition color.h:322
emphasis ems
Definition color.h:353
FMT_CONSTEXPR text_style(emphasis em=emphasis()) noexcept
Definition color.h:258
FMT_CONSTEXPR text_style & operator|=(const text_style &rhs)
Definition color.h:263
bool set_foreground_color
Definition color.h:351
FMT_CONSTEXPR detail::color_type get_foreground() const noexcept
Definition color.h:312
FMT_CONSTEXPR text_style(bool is_foreground, detail::color_type text_color) noexcept
Definition color.h:329
detail::color_type background_color
Definition color.h:350
FMT_CONSTEXPR bool has_foreground() const noexcept
Definition color.h:300
friend FMT_CONSTEXPR text_style bg(detail::color_type background) noexcept
Definition color.h:363
detail::color_type foreground_color
Definition color.h:349
FMT_CONSTEXPR detail::color_type get_background() const noexcept
Definition color.h:317
bool set_background_color
Definition color.h:352
FMT_CONSTEXPR bool has_background() const noexcept
Definition color.h:304
constexpr FMT_INLINE value()
Definition core.h:1621
void fputs(const Char *chars, FILE *stream)
Definition color.h:503
FMT_CONSTEXPR auto styled(const T &value, text_style ts) -> detail::styled_arg< remove_cvref_t< T > >
Definition color.h:739
FMT_CONSTEXPR text_style operator|(emphasis lhs, emphasis rhs) noexcept
Definition color.h:368
void print(std::FILE *f, const text_style &ts, const S &format_str, const Args &... args)
Definition color.h:601
FMT_CONSTEXPR text_style fg(detail::color_type foreground) noexcept
Definition color.h:357
auto format_to(OutputIt out, const text_style &ts, const S &format_str, Args &&... args) -> typename std::enable_if< enable, OutputIt >::type
Definition color.h:677
FMT_CONSTEXPR ansi_color_escape< Char > make_background_color(detail::color_type background) noexcept
Definition color.h:490
emphasis
Definition color.h:182
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:545
terminal_color
Definition color.h:162
color
Definition color.h:17
@ light_golden_rod_yellow
std::basic_string< Char > format(const text_style &ts, const S &format_str, const Args &... args)
Definition color.h:646
FMT_CONSTEXPR ansi_color_escape< Char > make_foreground_color(detail::color_type foreground) noexcept
Definition color.h:483
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:574
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:625
FMT_CONSTEXPR text_style bg(detail::color_type background) noexcept
Definition color.h:363
void reset_color(FILE *stream)
Definition color.h:519
void reset_color< wchar_t >(FILE *stream)
Definition color.h:525
FMT_CONSTEXPR ansi_color_escape< Char > make_emphasis(emphasis em) noexcept
Definition color.h:497
void fputs< wchar_t >(const wchar_t *chars, FILE *stream)
Definition color.h:511
#define FMT_ASSERT(condition, message)
Definition core.h:403
basic_string_view< char > string_view
Definition core.h:604
auto arg(const Char *name, const T &arg) -> detail::named_arg< Char, T >
Definition core.h:2506
typename detail::char_t_impl< S >::type char_t
Definition core.h:759
#define FMT_END_DETAIL_NAMESPACE
Definition core.h:231
#define FMT_MODULE_EXPORT_BEGIN
Definition core.h:226
#define FMT_CONSTEXPR
Definition core.h:106
#define FMT_BEGIN_NAMESPACE
Definition core.h:214
#define FMT_BEGIN_DETAIL_NAMESPACE
Definition core.h:228
#define FMT_ENABLE_IF(...)
Definition core.h:364
#define FMT_CONSTEXPR_CHAR_TRAITS
Definition core.h:130
typename type_identity< T >::type type_identity_t
Definition core.h:319
#define FMT_END_NAMESPACE
Definition core.h:219
#define FMT_MODULE_EXPORT_END
Definition core.h:227
#define out
Definition encodings.cpp:5
FMT_FUNC void print(std::FILE *f, string_view text)
Definition format-inl.h:1620
FMT_CONSTEXPR_CHAR_TRAITS const Char * end() const noexcept
Definition color.h:460
static constexpr size_t num_emphases
Definition color.h:466
static FMT_CONSTEXPR void to_esc(uint8_t c, Char *out, char delimiter) noexcept
Definition color.h:469
FMT_CONSTEXPR ansi_color_escape(detail::color_type text_color, const char *esc) noexcept
Definition color.h:378
Char buffer[7u+3u *num_emphases+1u]
Definition color.h:467
FMT_CONSTEXPR const Char * begin() const noexcept
Definition color.h:456
FMT_CONSTEXPR ansi_color_escape(emphasis em) noexcept
Definition color.h:419
static FMT_CONSTEXPR bool has_emphasis(emphasis em, emphasis mask) noexcept
Definition color.h:476
FMT_CONSTEXPR color_type(color rgb_color) noexcept
Definition color.h:229
union color_type::color_union value
FMT_CONSTEXPR color_type(rgb rgb_color) noexcept
Definition color.h:234
FMT_CONSTEXPR color_type(terminal_color term_color) noexcept
Definition color.h:240
FMT_CONSTEXPR color_type() noexcept
Definition color.h:225
bool is_rgb
Definition color.h:245
byte b
Definition Bitmap.h:11
byte r
Definition Bitmap.h:11
byte g
Definition Bitmap.h:11
FMT_CONSTEXPR rgb(uint32_t hex)
Definition color.h:205
FMT_CONSTEXPR rgb()
Definition color.h:197
FMT_CONSTEXPR rgb(uint8_t r_, uint8_t g_, uint8_t b_)
Definition color.h:201
FMT_CONSTEXPR rgb(color hex)
Definition color.h:209
uint8_t b
Definition color.h:217
uint8_t g
Definition color.h:216
uint8_t r
Definition color.h:215
text_style style
Definition color.h:541
const T & value
Definition color.h:540
i
Definition tag_strings.h:60
em
Definition tag_strings.h:44
uint32_t rgb_color
Definition color.h:248
uint8_t term_color
Definition color.h:247