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);
234 : set_foreground_color(), set_background_color(), ems(em) {}
237 if (!set_foreground_color) {
238 set_foreground_color = rhs.set_foreground_color;
239 foreground_color = rhs.foreground_color;
240 }
else if (rhs.set_foreground_color) {
241 if (!foreground_color.
is_rgb || !rhs.foreground_color.is_rgb)
243 foreground_color.
value.
rgb_color |= rhs.foreground_color.value.rgb_color;
246 if (!set_background_color) {
247 set_background_color = rhs.set_background_color;
248 background_color = rhs.background_color;
249 }
else if (rhs.set_background_color) {
250 if (!background_color.
is_rgb || !rhs.background_color.is_rgb)
252 background_color.
value.
rgb_color |= rhs.background_color.value.rgb_color;
255 ems =
static_cast<emphasis>(
static_cast<uint8_t
>(ems) |
256 static_cast<uint8_t
>(rhs.ems));
266 return set_foreground_color;
269 return set_background_color;
272 return static_cast<uint8_t
>(ems) != 0;
276 return foreground_color;
280 return background_color;
290 : set_foreground_color(), set_background_color(), ems() {
292 foreground_color = text_color;
293 set_foreground_color =
true;
295 background_color = text_color;
296 set_background_color =
true;
308 bool set_foreground_color;
309 bool set_background_color;
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;
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);
370 uint8_t em_codes[num_emphases] = {};
381 for (
size_t i = 0; i < num_emphases; ++i) {
382 if (!em_codes[i])
continue;
385 buffer[
index++] =
static_cast<Char
>(
'0' + em_codes[i]);
398 static constexpr size_t num_emphases = 8;
399 Char
buffer[7u + 3u * num_emphases + 1u];
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);
414template <
typename Char>
420template <
typename Char>
426template <
typename Char>
443template <
typename Char>
447 bool has_style =
false;
456 buf.
append(foreground.begin(), foreground.end());
461 buf.
append(background.begin(), background.end());
484template <
typename... T>
499template <
typename... T>
501 return print(stdout, ts, fmt, std::forward<T>(args)...);
508 return fmt::to_string(buf);
523template <
typename... T>
526 return fmt::vformat(ts, fmt.str,
vargs<T...>{{args...}});
530template <
typename OutputIt,
549template <
typename OutputIt,
typename... T,
556template <
typename T,
typename Char>
558 template <
typename FormatContext>
560 ->
decltype(ctx.out()) {
561 const auto& ts =
arg.style;
562 auto out = ctx.out();
564 bool has_style =
false;
565 if (ts.has_emphasis()) {
570 if (ts.has_foreground()) {
576 if (ts.has_background()) {
An implementation of std::basic_string_view for pre-C++17.
Definition base.h:504
constexpr auto size() const noexcept -> size_t
Returns the string size.
Definition base.h:549
A contiguous memory buffer with an optional growing ability.
Definition base.h:1698
FMT_CONSTEXPR20 void append(const U *begin, const U *end)
Appends data to the end of the buffer.
Definition base.h:1780
constexpr FMT_INLINE value()
Definition base.h:2104
A text style consisting of foreground and background colors and emphasis.
Definition color.h:231
FMT_CONSTEXPR auto operator|=(const text_style &rhs) -> text_style &
Definition color.h:236
FMT_CONSTEXPR auto has_background() const noexcept -> bool
Definition color.h:268
FMT_CONSTEXPR auto get_emphasis() const noexcept -> emphasis
Definition color.h:282
FMT_CONSTEXPR text_style(emphasis em=emphasis()) noexcept
Definition color.h:233
friend FMT_CONSTEXPR auto fg(detail::color_type foreground) noexcept -> text_style
Creates a text style from the foreground (text) color.
Definition color.h:314
FMT_CONSTEXPR auto has_foreground() const noexcept -> bool
Definition color.h:265
friend FMT_CONSTEXPR auto operator|(text_style lhs, const text_style &rhs) -> text_style
Definition color.h:260
FMT_CONSTEXPR auto get_foreground() const noexcept -> detail::color_type
Definition color.h:274
FMT_CONSTEXPR auto has_emphasis() const noexcept -> bool
Definition color.h:271
friend FMT_CONSTEXPR auto bg(detail::color_type background) noexcept -> text_style
Creates a text style from the background color.
Definition color.h:320
FMT_CONSTEXPR auto get_background() const noexcept -> detail::color_type
Definition color.h:278
detail namespace with internal helper functions
Definition input_adapters.h:32
FMT_CONSTEXPR auto make_emphasis(emphasis em) noexcept -> ansi_color_escape< Char >
Definition color.h:427
auto get_iterator(Buf &buf, OutputIt) -> decltype(buf.out())
Definition base.h:2044
FMT_CONSTEXPR auto make_background_color(color_type background) noexcept -> ansi_color_escape< Char >
Definition color.h:421
FMT_CONSTEXPR auto make_foreground_color(color_type foreground) noexcept -> ansi_color_escape< Char >
Definition color.h:415
FMT_CONSTEXPR20 auto copy(InputIt begin, InputIt end, OutputIt out) -> OutputIt
Definition base.h:1992
auto get_buffer(OutputIt out) -> iterator_buffer< OutputIt, T >
Definition base.h:2034
void vformat_to(buffer< Char > &buf, basic_string_view< Char > fmt, typename vformat_args< Char >::type args, locale_ref loc={})
Definition format.h:3665
void reset_color(buffer< Char > &buffer)
Definition color.h:432
FMT_CONSTEXPR ansi_color_escape(color_type text_color, const char *esc) noexcept
Definition color.h:333
FMT_CONSTEXPR ansi_color_escape(emphasis em) noexcept
Definition color.h:369
FMT_CONSTEXPR20 auto end() const noexcept -> const Char *
Definition color.h:393
FMT_CONSTEXPR auto begin() const noexcept -> const Char *
Definition color.h:392
FMT_CONSTEXPR color_type(rgb rgb_color) noexcept
Definition color.h:214
FMT_CONSTEXPR color_type() noexcept
Definition color.h:210
FMT_CONSTEXPR color_type(color rgb_color) noexcept
Definition color.h:211
bool is_rgb
Definition color.h:222
union detail::color_type::color_union value
FMT_CONSTEXPR color_type(terminal_color term_color) noexcept
Definition color.h:218
text_style style
Definition color.h:439
styled_arg(const T &v, text_style s)
Definition color.h:440
const T & value
Definition color.h:438
FMT_CONSTEXPR rgb(uint32_t hex)
Definition color.h:195
FMT_CONSTEXPR rgb()
Definition color.h:193
FMT_CONSTEXPR rgb(uint8_t r_, uint8_t g_, uint8_t b_)
Definition color.h:194
FMT_CONSTEXPR rgb(color hex)
Definition color.h:197
uint8_t b
Definition color.h:203
uint8_t g
Definition color.h:202
uint8_t r
Definition color.h:201
uint8_t term_color
Definition color.h:224
uint32_t rgb_color
Definition color.h:225
#define FMT_ASSERT(condition, message)
Definition base.h:381
#define FMT_END_EXPORT
Definition base.h:250
basic_string_view< char > string_view
Definition base.h:603
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:2775
typename fstring< T... >::t format_string
Definition base.h:2720
#define FMT_CONSTEXPR
Definition base.h:113
#define FMT_BEGIN_NAMESPACE
Definition base.h:239
#define FMT_ENABLE_IF(...)
Definition base.h:334
#define FMT_BEGIN_EXPORT
Definition base.h:249
#define FMT_CONSTEXPR20
Definition base.h:141
#define FMT_END_NAMESPACE
Definition base.h:242
conditional_t< std::is_same< Char, char >::value, context, generic_context< basic_appender< Char >, Char > > buffered_context
Definition base.h:638
void vprint(FILE *f, const text_style &ts, string_view fmt, format_args args)
Definition color.h:468
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:602
auto format(const 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:524
void print(FILE *f, const 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:485
auto format_to(OutputIt out, const 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:551
emphasis
Definition color.h:179
FMT_CONSTEXPR auto operator|(emphasis lhs, emphasis rhs) noexcept -> text_style
Definition color.h:325
terminal_color
Definition color.h:160
color
Definition color.h:16
@ light_golden_rod_yellow
FMT_CONSTEXPR auto fg(detail::color_type foreground) noexcept -> text_style
Creates a text style from the foreground (text) color.
Definition color.h:314
auto vformat_to(OutputIt out, const 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:532
auto vformat(const text_style &ts, string_view fmt, format_args args) -> std::string
Definition color.h:504
FMT_CONSTEXPR auto bg(detail::color_type background) noexcept -> text_style
Creates a text style from the background color.
Definition color.h:320