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)
242 FMT_THROW(format_error(
"can't OR a terminal 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)
251 FMT_THROW(format_error(
"can't OR a terminal 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;
306 bool set_foreground_color;
307 bool set_background_color;
329 const char* esc)
noexcept {
332 if (!text_color.is_rgb) {
333 bool is_background = esc ==
string_view(
"\x1b[48;2;");
337 if (is_background)
value += 10u;
355 for (
int i = 0; i < 7; i++) {
356 buffer[i] =
static_cast<Char
>(esc[i]);
358 rgb color(text_color.value.rgb_color);
362 buffer[19] =
static_cast<Char
>(0);
365 uint8_t em_codes[num_emphases] = {};
376 for (
size_t i = 0; i < num_emphases; ++i) {
377 if (!em_codes[i])
continue;
380 buffer[
index++] =
static_cast<Char
>(
'0' + em_codes[i]);
393 static constexpr size_t num_emphases = 8;
394 Char
buffer[7u + 3u * num_emphases + 1u];
397 char delimiter)
noexcept {
398 out[0] =
static_cast<Char
>(
'0' +
c / 100);
399 out[1] =
static_cast<Char
>(
'0' +
c / 10 % 10);
400 out[2] =
static_cast<Char
>(
'0' +
c % 10);
401 out[3] =
static_cast<Char
>(delimiter);
404 return static_cast<uint8_t
>(em) &
static_cast<uint8_t
>(mask);
408template <
typename Char>
414template <
typename Char>
420template <
typename Char>
435template <
typename Char>
439 bool has_style =
false;
447 auto foreground = detail::make_foreground_color<Char>(ts.
get_foreground());
448 buf.
append(foreground.begin(), foreground.end());
452 auto background = detail::make_background_color<Char>(ts.
get_background());
453 buf.
append(background.begin(), background.end());
456 if (has_style) detail::reset_color<Char>(buf);
471 int result = std::fputs(buf.data(), f);
487template <
typename S,
typename... Args,
490 const Args&... args) {
506template <
typename S,
typename... Args,
509 return print(stdout, ts, format_str, args...);
512template <
typename S,
typename Char =
char_t<S>>
533template <
typename S,
typename... Args,
typename Char =
char_t<S>>
535 const Args&... args) {
543template <
typename OutputIt,
typename Char,
548 auto&& buf = detail::get_buffer<Char>(out);
565template <
typename OutputIt,
typename S,
typename... Args,
575template <
typename T,
typename Char>
577 template <
typename FormatContext>
579 ->
decltype(ctx.out()) {
580 const auto& ts =
arg.style;
581 const auto& value =
arg.value;
582 auto out = ctx.out();
584 bool has_style =
false;
585 if (ts.has_emphasis()) {
587 auto emphasis = detail::make_emphasis<Char>(ts.get_emphasis());
590 if (ts.has_foreground()) {
593 detail::make_foreground_color<Char>(ts.get_foreground());
594 out =
std::copy(foreground.begin(), foreground.end(), out);
596 if (ts.has_background()) {
599 detail::make_background_color<Char>(ts.get_background());
600 out =
std::copy(background.begin(), background.end(), out);
\rst A dynamically growing memory buffer for trivially copyable/constructible types with the first SI...
Definition: format.h:918
An implementation of std::basic_string_view for pre-C++17.
Definition: core.h:398
\rst A contiguous memory buffer with an optional growing ability.
Definition: core.h:798
void append(const U *begin, const U *end)
Appends data to the end of the buffer.
constexpr FMT_INLINE value()
Definition: core.h:1261
A text style consisting of foreground and background colors and emphasis.
Definition: color.h:231
FMT_CONSTEXPR bool has_emphasis() const noexcept
Definition: color.h:271
friend FMT_CONSTEXPR text_style fg(detail::color_type foreground) noexcept
Creates a text style from the foreground (text) color.
Definition: color.h:312
friend FMT_CONSTEXPR text_style operator|(text_style lhs, const text_style &rhs)
Definition: color.h:260
FMT_CONSTEXPR emphasis get_emphasis() const noexcept
Definition: color.h:282
FMT_CONSTEXPR text_style(emphasis em=emphasis()) noexcept
Definition: color.h:233
FMT_CONSTEXPR text_style & operator|=(const text_style &rhs)
Definition: color.h:236
FMT_CONSTEXPR detail::color_type get_foreground() const noexcept
Definition: color.h:274
FMT_CONSTEXPR bool has_foreground() const noexcept
Definition: color.h:265
friend FMT_CONSTEXPR text_style bg(detail::color_type background) noexcept
Creates a text style from the background color.
Definition: color.h:317
FMT_CONSTEXPR detail::color_type get_background() const noexcept
Definition: color.h:278
FMT_CONSTEXPR bool has_background() const noexcept
Definition: color.h:268
#define FMT_ASSERT(condition, message)
Definition: core.h:336
#define FMT_END_EXPORT
Definition: core.h:185
basic_string_view< char > string_view
Definition: core.h:501
auto arg(const Char *name, const T &arg) -> detail::named_arg< Char, T >
\rst Returns a named argument to be used in a formatting function.
Definition: core.h:1841
typename detail::char_t_impl< S >::type char_t
String's character type.
Definition: core.h:646
#define FMT_CONSTEXPR
Definition: core.h:105
#define FMT_BEGIN_NAMESPACE
Definition: core.h:174
constexpr auto make_format_args(T &... args) -> format_arg_store< Context, remove_cvref_t< T >... >
\rst Constructs a ~fmtformat_arg_store object that contains references to arguments and can be implic...
Definition: core.h:1824
#define FMT_ENABLE_IF(...)
Definition: core.h:286
#define FMT_BEGIN_EXPORT
Definition: core.h:184
#define FMT_CONSTEXPR_CHAR_TRAITS
Definition: core.h:129
typename type_identity< T >::type type_identity_t
Definition: core.h:267
#define FMT_END_NAMESPACE
Definition: core.h:177
detail namespace with internal helper functions
Definition: xchar.h:20
FMT_CONSTEXPR ansi_color_escape< Char > make_emphasis(emphasis em) noexcept
Definition: color.h:421
auto copy(const Range &range, OutputIt out) -> OutputIt
Definition: ranges.h:26
FMT_INLINE auto to_string_view(const Char *s) -> basic_string_view< Char >
Definition: core.h:517
FMT_FUNC void print(std::FILE *f, string_view text)
Definition: format-inl.h:1452
FMT_CONSTEXPR auto is_utf8() -> bool
Definition: core.h:380
FMT_CONSTEXPR ansi_color_escape< Char > make_background_color(detail::color_type background) noexcept
Definition: color.h:415
FMT_INLINE auto get_iterator(Buf &buf, OutputIt) -> decltype(buf.out())
Definition: core.h:1127
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:436
FMT_CONSTEXPR ansi_color_escape< Char > make_foreground_color(detail::color_type foreground) noexcept
Definition: color.h:409
type
Definition: core.h:556
void reset_color(buffer< Char > &buffer)
Definition: color.h:425
static constexpr const velocity::meters_per_second_t c(299792458.0)
Speed of light in vacuum.
std::string to_string(const T &t)
Definition: base.h:92
FMT_CONSTEXPR_CHAR_TRAITS const Char * end() const noexcept
Definition: color.h:388
FMT_CONSTEXPR ansi_color_escape(emphasis em) noexcept
Definition: color.h:364
FMT_CONSTEXPR ansi_color_escape(detail::color_type text_color, const char *esc) noexcept
Definition: color.h:328
FMT_CONSTEXPR const Char * begin() const noexcept
Definition: color.h:387
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:432
const T & value
Definition: color.h:431
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 S(label, offset, message)
Definition: Errors.h:119
FMT_CONSTEXPR auto styled(const T &value, text_style ts) -> detail::styled_arg< remove_cvref_t< T > >
\rst Returns an argument that will be formatted using ANSI escape sequences, to be used in a formatti...
Definition: color.h:624
FMT_CONSTEXPR text_style operator|(emphasis lhs, emphasis rhs) noexcept
Definition: color.h:321
void print(std::FILE *f, const text_style &ts, const S &format_str, const Args &... args)
\rst Formats a string and prints it to the specified file stream using ANSI escape sequences to speci...
Definition: color.h:489
FMT_CONSTEXPR text_style fg(detail::color_type foreground) noexcept
Creates a text style from the foreground (text) color.
Definition: color.h:312
OutputIt vformat_to(OutputIt out, const text_style &ts, basic_string_view< Char > format_str, basic_format_args< buffer_context< type_identity_t< Char > > > args)
Formats a string with the given text_style and writes the output to out.
Definition: color.h:545
auto format_to(OutputIt out, const text_style &ts, const S &format_str, Args &&... args) -> typename std::enable_if< enable, OutputIt >::type
\rst Formats arguments with the given text_style, writes the result to the output iterator out and re...
Definition: color.h:568
emphasis
Definition: color.h:179
void vprint(std::FILE *f, const text_style &ts, string_view fmt, format_args args)
Definition: color.h:461
terminal_color
Definition: color.h:160
color
Definition: color.h:16
@ light_golden_rod_yellow
std::basic_string< Char > format(const text_style &ts, const S &format_str, const Args &... args)
\rst Formats arguments and returns the result as a string using ANSI escape sequences to specify text...
Definition: color.h:534
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:513
FMT_CONSTEXPR text_style bg(detail::color_type background) noexcept
Creates a text style from the background color.
Definition: color.h:317