Go to the documentation of this file.
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) {}
212 value.rgb_color =
static_cast<uint32_t
>(rgb_color);
215 value.rgb_color = (
static_cast<uint32_t
>(rgb_color.r) << 16) |
216 (
static_cast<uint32_t
>(rgb_color.g) << 8) | rgb_color.b;
220 value.term_color =
static_cast<uint8_t
>(term_color);
240 }
else if (rhs.set_foreground_color) {
242 FMT_THROW(format_error(
"can't OR a terminal color"));
249 }
else if (rhs.set_background_color) {
251 FMT_THROW(format_error(
"can't OR a terminal color"));
256 static_cast<uint8_t
>(rhs.ems));
272 return static_cast<uint8_t
>(
ems) != 0;
334 const char* esc) noexcept {
337 if (!text_color.is_rgb) {
338 bool is_background = esc ==
string_view(
"\x1b[48;2;");
342 if (is_background)
value += 10u;
345 buffer[index++] =
static_cast<Char
>(
'\x1b');
346 buffer[index++] =
static_cast<Char
>(
'[');
349 buffer[index++] =
static_cast<Char
>(
'1');
352 buffer[index++] =
static_cast<Char
>(
'0' +
value / 10u);
353 buffer[index++] =
static_cast<Char
>(
'0' +
value % 10u);
355 buffer[index++] =
static_cast<Char
>(
'm');
356 buffer[index++] =
static_cast<Char
>(
'\0');
360 for (
int i = 0; i < 7; i++) {
361 buffer[i] =
static_cast<Char
>(esc[i]);
363 rgb color(text_color.value.rgb_color);
367 buffer[19] =
static_cast<Char
>(0);
382 if (!em_codes[i])
continue;
383 buffer[index++] =
static_cast<Char
>(
'\x1b');
384 buffer[index++] =
static_cast<Char
>(
'[');
385 buffer[index++] =
static_cast<Char
>(
'0' + em_codes[i]);
386 buffer[index++] =
static_cast<Char
>(
'm');
388 buffer[index++] =
static_cast<Char
>(0);
402 char delimiter) noexcept {
403 out[0] =
static_cast<Char
>(
'0' + c / 100);
404 out[1] =
static_cast<Char
>(
'0' + c / 10 % 10);
405 out[2] =
static_cast<Char
>(
'0' + c % 10);
406 out[3] =
static_cast<Char
>(delimiter);
410 return static_cast<uint8_t
>(em) &
static_cast<uint8_t
>(mask);
414 template <
typename Char>
420 template <
typename Char>
426 template <
typename Char>
443 template <
typename Char>
447 bool has_style =
false;
455 auto foreground = detail::make_foreground_color<Char>(ts.
get_foreground());
456 buf.
append(foreground.begin(), foreground.end());
460 auto background = detail::make_background_color<Char>(ts.
get_background());
461 buf.
append(background.begin(), background.end());
464 if (has_style) detail::reset_color<Char>(buf);
479 int result = std::fputs(buf.data(),
f);
495 template <
typename S,
typename... Args,
498 const Args&...
args) {
514 template <
typename S,
typename... Args,
517 return print(stdout, ts, format_str,
args...);
520 template <
typename S,
typename Char =
char_t<S>>
524 -> std::basic_string<Char> {
542 template <
typename S,
typename... Args,
typename Char =
char_t<S>>
544 const Args&...
args) -> std::basic_string<Char> {
552 template <
typename OutputIt,
typename Char,
558 auto&& buf = detail::get_buffer<Char>(out);
576 typename OutputIt,
typename S,
typename... Args,
586 template <
typename T,
typename Char>
588 template <
typename FormatContext>
590 -> decltype(ctx.out()) {
591 const auto& ts =
arg.style;
592 const auto& value =
arg.value;
593 auto out = ctx.out();
595 bool has_style =
false;
596 if (ts.has_emphasis()) {
598 auto emphasis = detail::make_emphasis<Char>(ts.get_emphasis());
601 if (ts.has_foreground()) {
604 detail::make_foreground_color<Char>(ts.get_foreground());
605 out =
std::copy(foreground.begin(), foreground.end(), out);
607 if (ts.has_background()) {
610 detail::make_background_color<Char>(ts.get_background());
611 out =
std::copy(background.begin(), background.end(), out);
634 template <
typename T>
643 #endif // FMT_COLOR_H_
friend FMT_CONSTEXPR auto fg(detail::color_type foreground) noexcept -> text_style
friend FMT_CONSTEXPR auto bg(detail::color_type background) noexcept -> text_style
FMT_INLINE auto to_string_view(const Char *s) -> basic_string_view< Char >
FMT_CONSTEXPR color_type() noexcept
auto copy(const Range &range, OutputIt out) -> OutputIt
FMT_CONSTEXPR auto has_foreground() const noexcept -> bool
FMT_CONSTEXPR text_style(emphasis em=emphasis()) noexcept
static constexpr size_t num_emphases
FMT_CONSTEXPR auto bg(detail::color_type background) noexcept -> text_style
FMT_CONSTEXPR color_type(terminal_color term_color) noexcept
FMT_CONSTEXPR ansi_color_escape(emphasis em) noexcept
auto arg(const Char *name, const T &arg) -> detail::named_arg< Char, T >
FMT_FUNC void print(std::FILE *f, string_view text)
static FMT_CONSTEXPR void to_esc(uint8_t c, Char *out, char delimiter) noexcept
FMT_CONSTEXPR text_style(bool is_foreground, detail::color_type text_color) noexcept
FMT_CONSTEXPR rgb(color hex)
auto vformat_to(OutputIt out, const text_style &ts, basic_string_view< Char > format_str, basic_format_args< buffer_context< type_identity_t< Char >>> args) -> OutputIt
FMT_INLINE auto get_iterator(Buf &buf, OutputIt) -> decltype(buf.out())
void append(const U *begin, const U *end)
friend FMT_CONSTEXPR auto operator|(text_style lhs, const text_style &rhs) -> text_style
#define FMT_ENABLE_IF(...)
FMT_CONSTEXPR color_type(color rgb_color) noexcept
FMT_CONSTEXPR auto get_background() const noexcept -> detail::color_type
FMT_CONSTEXPR_CHAR_TRAITS auto end() const noexcept -> const Char *
#define FMT_END_NAMESPACE
bool set_foreground_color
detail::color_type background_color
constexpr auto make_format_args(T &... args) -> format_arg_store< Context, remove_cvref_t< T >... >
FMT_CONSTEXPR auto get_foreground() const noexcept -> detail::color_type
typename type_identity< T >::type type_identity_t
FMT_CONSTEXPR auto has_background() const noexcept -> bool
FMT_CONSTEXPR auto operator|=(const text_style &rhs) -> text_style &
#define FMT_CONSTEXPR_CHAR_TRAITS
detail::color_type foreground_color
auto format(const text_style &ts, const S &format_str, const Args &... args) -> std::basic_string< Char >
FMT_CONSTEXPR rgb(uint32_t hex)
basic_string_view< char > string_view
void reset_color(buffer< Char > &buffer)
auto format_to(OutputIt out, const text_style &ts, const S &format_str, Args &&... args) -> typename std::enable_if< enable, OutputIt >::type
styled_arg(const T &v, text_style s)
FMT_CONSTEXPR auto make_emphasis(emphasis em) noexcept -> ansi_color_escape< Char >
FMT_CONSTEXPR auto make_background_color(detail::color_type background) noexcept -> ansi_color_escape< Char >
#define FMT_ASSERT(condition, message)
FMT_CONSTEXPR auto begin() const noexcept -> const Char *
constexpr FMT_INLINE value()
bool set_background_color
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)
std::string to_string(const std::string &arg)
void print(std::FILE *f, const text_style &ts, const S &format_str, const Args &... args)
#define FMT_BEGIN_NAMESPACE
@ light_golden_rod_yellow
union detail::color_type::color_union value
FMT_CONSTEXPR auto fg(detail::color_type foreground) noexcept -> text_style
FMT_CONSTEXPR auto operator|(emphasis lhs, emphasis rhs) noexcept -> text_style
static FMT_CONSTEXPR auto has_emphasis(emphasis em, emphasis mask) noexcept -> bool
FMT_CONSTEXPR auto get_emphasis() const noexcept -> emphasis
FMT_CONSTEXPR auto is_utf8() -> bool
Char buffer[7u+3u *num_emphases+1u]
FMT_CONSTEXPR auto has_emphasis() const noexcept -> bool
typename detail::char_t_impl< S >::type char_t
auto vformat(const text_style &ts, const S &format_str, basic_format_args< buffer_context< type_identity_t< Char >>> args) -> std::basic_string< Char >
FMT_CONSTEXPR rgb(uint8_t r_, uint8_t g_, uint8_t b_)
FMT_CONSTEXPR ansi_color_escape(detail::color_type text_color, const char *esc) noexcept
FMT_CONSTEXPR color_type(rgb rgb_color) noexcept
FMT_CONSTEXPR auto make_foreground_color(detail::color_type foreground) noexcept -> ansi_color_escape< Char >
FMT_CONSTEXPR auto styled(const T &value, text_style ts) -> detail::styled_arg< remove_cvref_t< T >>
void vprint(std::FILE *f, const text_style &ts, string_view fmt, format_args args)
plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Nov 11 2024 03:23:43