13 #pragma GCC system_header
17 #pragma clang system_header
23 FMT_MODULE_EXPORT_BEGIN
25 enum class color : uint32_t {
26 alice_blue = 0xF0F8FF,
27 antique_white = 0xFAEBD7,
29 aquamarine = 0x7FFFD4,
34 blanched_almond = 0xFFEBCD,
36 blue_violet = 0x8A2BE2,
38 burly_wood = 0xDEB887,
39 cadet_blue = 0x5F9EA0,
40 chartreuse = 0x7FFF00,
43 cornflower_blue = 0x6495ED,
49 dark_golden_rod = 0xB8860B,
51 dark_green = 0x006400,
52 dark_khaki = 0xBDB76B,
53 dark_magenta = 0x8B008B,
54 dark_olive_green = 0x556B2F,
55 dark_orange = 0xFF8C00,
56 dark_orchid = 0x9932CC,
58 dark_salmon = 0xE9967A,
59 dark_sea_green = 0x8FBC8F,
60 dark_slate_blue = 0x483D8B,
61 dark_slate_gray = 0x2F4F4F,
62 dark_turquoise = 0x00CED1,
63 dark_violet = 0x9400D3,
65 deep_sky_blue = 0x00BFFF,
67 dodger_blue = 0x1E90FF,
68 fire_brick = 0xB22222,
69 floral_white = 0xFFFAF0,
70 forest_green = 0x228B22,
73 ghost_white = 0xF8F8FF,
75 golden_rod = 0xDAA520,
78 green_yellow = 0xADFF2F,
81 indian_red = 0xCD5C5C,
86 lavender_blush = 0xFFF0F5,
87 lawn_green = 0x7CFC00,
88 lemon_chiffon = 0xFFFACD,
89 light_blue = 0xADD8E6,
90 light_coral = 0xF08080,
91 light_cyan = 0xE0FFFF,
92 light_golden_rod_yellow = 0xFAFAD2,
93 light_gray = 0xD3D3D3,
94 light_green = 0x90EE90,
95 light_pink = 0xFFB6C1,
96 light_salmon = 0xFFA07A,
97 light_sea_green = 0x20B2AA,
98 light_sky_blue = 0x87CEFA,
99 light_slate_gray = 0x778899,
100 light_steel_blue = 0xB0C4DE,
101 light_yellow = 0xFFFFE0,
103 lime_green = 0x32CD32,
107 medium_aquamarine = 0x66CDAA,
108 medium_blue = 0x0000CD,
109 medium_orchid = 0xBA55D3,
110 medium_purple = 0x9370DB,
111 medium_sea_green = 0x3CB371,
112 medium_slate_blue = 0x7B68EE,
113 medium_spring_green = 0x00FA9A,
114 medium_turquoise = 0x48D1CC,
115 medium_violet_red = 0xC71585,
116 midnight_blue = 0x191970,
117 mint_cream = 0xF5FFFA,
118 misty_rose = 0xFFE4E1,
120 navajo_white = 0xFFDEAD,
124 olive_drab = 0x6B8E23,
126 orange_red = 0xFF4500,
128 pale_golden_rod = 0xEEE8AA,
129 pale_green = 0x98FB98,
130 pale_turquoise = 0xAFEEEE,
131 pale_violet_red = 0xDB7093,
132 papaya_whip = 0xFFEFD5,
133 peach_puff = 0xFFDAB9,
137 powder_blue = 0xB0E0E6,
139 rebecca_purple = 0x663399,
141 rosy_brown = 0xBC8F8F,
142 royal_blue = 0x4169E1,
143 saddle_brown = 0x8B4513,
145 sandy_brown = 0xF4A460,
146 sea_green = 0x2E8B57,
147 sea_shell = 0xFFF5EE,
151 slate_blue = 0x6A5ACD,
152 slate_gray = 0x708090,
154 spring_green = 0x00FF7F,
155 steel_blue = 0x4682B4,
160 turquoise = 0x40E0D0,
164 white_smoke = 0xF5F5F5,
166 yellow_green = 0x9ACD32
169 enum class terminal_color : uint8_t {
188 enum class emphasis : uint8_t {
196 strikethrough = 1 << 7,
202 FMT_CONSTEXPR rgb() : r(0),
g(0), b(0) {}
203 FMT_CONSTEXPR rgb(uint8_t r_, uint8_t g_, uint8_t b_) : r(r_),
g(g_), b(b_) {}
204 FMT_CONSTEXPR rgb(uint32_t hex)
205 : r((hex >> 16) & 0xFF),
g((hex >> 8) & 0xFF), b(hex & 0xFF) {}
206 FMT_CONSTEXPR rgb(color hex)
207 : r((uint32_t(hex) >> 16) & 0xFF),
208 g((uint32_t(hex) >> 8) & 0xFF),
209 b(uint32_t(hex) & 0xFF) {}
215 FMT_BEGIN_DETAIL_NAMESPACE
219 FMT_CONSTEXPR color_type() noexcept : is_rgb(), value{} {}
220 FMT_CONSTEXPR color_type(color rgb_color) noexcept : is_rgb(
true), value{} {
221 value.rgb_color =
static_cast<uint32_t
>(rgb_color);
223 FMT_CONSTEXPR color_type(rgb rgb_color) noexcept : is_rgb(
true), value{} {
224 value.rgb_color = (
static_cast<uint32_t
>(rgb_color.r) << 16) |
225 (
static_cast<uint32_t
>(rgb_color.g) << 8) | rgb_color.b;
227 FMT_CONSTEXPR color_type(terminal_color term_color) noexcept
228 : is_rgb(), value{} {
229 value.term_color =
static_cast<uint8_t
>(term_color);
238 FMT_END_DETAIL_NAMESPACE
243 FMT_CONSTEXPR
text_style(emphasis em = emphasis()) noexcept
244 : set_foreground_color(), set_background_color(), ems(em) {}
247 if (!set_foreground_color) {
248 set_foreground_color = rhs.set_foreground_color;
249 foreground_color = rhs.foreground_color;
250 }
else if (rhs.set_foreground_color) {
251 if (!foreground_color.is_rgb || !rhs.foreground_color.is_rgb)
253 foreground_color.value.rgb_color |= rhs.foreground_color.value.rgb_color;
256 if (!set_background_color) {
257 set_background_color = rhs.set_background_color;
258 background_color = rhs.background_color;
259 }
else if (rhs.set_background_color) {
260 if (!background_color.is_rgb || !rhs.background_color.is_rgb)
262 background_color.value.rgb_color |= rhs.background_color.value.rgb_color;
265 ems =
static_cast<emphasis
>(
static_cast<uint8_t
>(ems) |
266 static_cast<uint8_t
>(rhs.ems));
275 FMT_CONSTEXPR
bool has_foreground()
const noexcept {
276 return set_foreground_color;
278 FMT_CONSTEXPR
bool has_background()
const noexcept {
279 return set_background_color;
281 FMT_CONSTEXPR
bool has_emphasis()
const noexcept {
282 return static_cast<uint8_t
>(ems) != 0;
284 FMT_CONSTEXPR detail::color_type get_foreground()
const noexcept {
285 FMT_ASSERT(has_foreground(),
"no foreground specified for this style");
286 return foreground_color;
288 FMT_CONSTEXPR detail::color_type get_background()
const noexcept {
289 FMT_ASSERT(has_background(),
"no background specified for this style");
290 return background_color;
292 FMT_CONSTEXPR emphasis get_emphasis()
const noexcept {
293 FMT_ASSERT(has_emphasis(),
"no emphasis specified for this style");
299 detail::color_type text_color) noexcept
300 : set_foreground_color(), set_background_color(), ems() {
302 foreground_color = text_color;
303 set_foreground_color =
true;
305 background_color = text_color;
306 set_background_color =
true;
310 friend FMT_CONSTEXPR
text_style fg(detail::color_type foreground) noexcept;
312 friend FMT_CONSTEXPR
text_style bg(detail::color_type background) noexcept;
314 detail::color_type foreground_color;
315 detail::color_type background_color;
316 bool set_foreground_color;
317 bool set_background_color;
322 FMT_CONSTEXPR
inline text_style fg(detail::color_type foreground) noexcept {
327 FMT_CONSTEXPR
inline text_style bg(detail::color_type background) noexcept {
331 FMT_CONSTEXPR
inline text_style operator|(emphasis lhs, emphasis rhs) noexcept {
335 FMT_BEGIN_DETAIL_NAMESPACE
337 template <
typename Char>
struct ansi_color_escape {
338 FMT_CONSTEXPR ansi_color_escape(detail::color_type text_color,
339 const char *esc) noexcept {
342 if (!text_color.is_rgb) {
343 bool is_background = esc ==
string_view(
"\x1b[48;2;");
344 uint32_t value = text_color.value.term_color;
351 buffer[index++] =
static_cast<Char
>(
'\x1b');
352 buffer[index++] =
static_cast<Char
>(
'[');
355 buffer[index++] =
static_cast<Char
>(
'1');
358 buffer[index++] =
static_cast<Char
>(
'0' + value / 10u);
359 buffer[index++] =
static_cast<Char
>(
'0' + value % 10u);
361 buffer[index++] =
static_cast<Char
>(
'm');
362 buffer[index++] =
static_cast<Char
>(
'\0');
366 for (
int i = 0; i < 7; i++) {
367 buffer[i] =
static_cast<Char
>(esc[i]);
369 rgb color(text_color.value.rgb_color);
370 to_esc(color.r,
buffer + 7,
';');
371 to_esc(color.g,
buffer + 11,
';');
372 to_esc(color.b,
buffer + 15,
'm');
373 buffer[19] =
static_cast<Char
>(0);
375 FMT_CONSTEXPR ansi_color_escape(emphasis em) noexcept {
376 uint8_t em_codes[num_emphases] = {};
377 if (has_emphasis(em, emphasis::bold))
379 if (has_emphasis(em, emphasis::faint))
381 if (has_emphasis(em, emphasis::italic))
383 if (has_emphasis(em, emphasis::underline))
385 if (has_emphasis(em, emphasis::blink))
387 if (has_emphasis(em, emphasis::reverse))
389 if (has_emphasis(em, emphasis::conceal))
391 if (has_emphasis(em, emphasis::strikethrough))
395 for (
size_t i = 0; i < num_emphases; ++i) {
398 buffer[index++] =
static_cast<Char
>(
'\x1b');
399 buffer[index++] =
static_cast<Char
>(
'[');
400 buffer[index++] =
static_cast<Char
>(
'0' + em_codes[i]);
401 buffer[index++] =
static_cast<Char
>(
'm');
403 buffer[index++] =
static_cast<Char
>(0);
405 FMT_CONSTEXPR
operator const Char *()
const noexcept {
return buffer; }
407 FMT_CONSTEXPR
const Char *begin() const noexcept {
return buffer; }
408 FMT_CONSTEXPR_CHAR_TRAITS
const Char *end() const noexcept {
413 static constexpr
size_t num_emphases = 8;
414 Char
buffer[7u + 3u * num_emphases + 1u];
416 static FMT_CONSTEXPR
void to_esc(uint8_t c, Char *out,
417 char delimiter) noexcept {
418 out[0] =
static_cast<Char
>(
'0' +
c / 100);
419 out[1] =
static_cast<Char
>(
'0' +
c / 10 % 10);
420 out[2] =
static_cast<Char
>(
'0' +
c % 10);
421 out[3] =
static_cast<Char
>(delimiter);
423 static FMT_CONSTEXPR
bool has_emphasis(emphasis em, emphasis mask) noexcept {
424 return static_cast<uint8_t
>(em) &
static_cast<uint8_t
>(mask);
428 template <
typename Char>
429 FMT_CONSTEXPR ansi_color_escape<Char>
430 make_foreground_color(detail::color_type foreground) noexcept {
431 return ansi_color_escape<Char>(foreground,
"\x1b[38;2;");
434 template <
typename Char>
435 FMT_CONSTEXPR ansi_color_escape<Char>
436 make_background_color(detail::color_type background) noexcept {
437 return ansi_color_escape<Char>(background,
"\x1b[48;2;");
440 template <
typename Char>
441 FMT_CONSTEXPR ansi_color_escape<Char> make_emphasis(emphasis em) noexcept {
442 return ansi_color_escape<Char>(em);
445 template <
typename Char>
inline void fputs(
const Char *chars, FILE *stream) {
446 int result = std::fputs(chars, stream);
448 FMT_THROW(system_error(errno, FMT_STRING(
"cannot write to file")));
451 template <>
inline void fputs<wchar_t>(
const wchar_t *chars, FILE *stream) {
452 int result = std::fputws(chars, stream);
454 FMT_THROW(system_error(errno, FMT_STRING(
"cannot write to file")));
457 template <
typename Char>
inline void reset_color(FILE *stream) {
458 fputs(
"\x1b[0m", stream);
461 template <>
inline void reset_color<wchar_t>(FILE *stream) {
462 fputs(L
"\x1b[0m", stream);
470 template <
typename T>
struct styled_arg {
475 template <
typename Char>
479 bool has_style =
false;
480 if (ts.has_emphasis()) {
482 auto emphasis = detail::make_emphasis<Char>(ts.get_emphasis());
483 buf.
append(emphasis.begin(), emphasis.end());
485 if (ts.has_foreground()) {
487 auto foreground = detail::make_foreground_color<Char>(ts.get_foreground());
488 buf.
append(foreground.begin(), foreground.end());
490 if (ts.has_background()) {
492 auto background = detail::make_background_color<Char>(ts.get_background());
493 buf.
append(background.begin(), background.end());
495 detail::vformat_to(buf, format_str, args, {});
497 detail::reset_color<Char>(buf);
500 FMT_END_DETAIL_NAMESPACE
502 template <
typename S,
typename Char =
char_t<S>>
503 void vprint(std::FILE *f,
const text_style &ts,
const S &format,
506 detail::vformat_to(buf, ts, detail::to_string_view(format), args);
507 if (detail::is_utf8()) {
510 buf.push_back(Char(0));
511 detail::fputs(buf.data(), f);
526 template <
typename S,
typename... Args,
527 FMT_ENABLE_IF(detail::is_string<S>::value)>
528 void print(std::FILE *f,
const text_style &ts,
const S &format_str,
529 const Args &...args) {
530 vprint(f, ts, format_str,
531 fmt::make_format_args<buffer_context<char_t<S>>>(args...));
545 template <
typename S,
typename... Args,
546 FMT_ENABLE_IF(detail::is_string<S>::value)>
547 void print(
const text_style &ts,
const S &format_str,
const Args &...args) {
548 return print(stdout, ts, format_str, args...);
551 template <
typename S,
typename Char =
char_t<S>>
552 inline std::basic_string<Char>
553 vformat(
const text_style &ts,
const S &format_str,
556 detail::vformat_to(buf, ts, detail::to_string_view(format_str), args);
557 return fmt::to_string(buf);
572 template <
typename S,
typename... Args,
typename Char = char_t<S>>
573 inline std::basic_string<Char> format(
const text_style &ts,
const S &format_str,
574 const Args &...args) {
575 return fmt::vformat(ts, detail::to_string_view(format_str),
576 fmt::make_format_args<buffer_context<Char>>(args...));
582 template <
typename OutputIt,
typename Char,
583 FMT_ENABLE_IF(detail::is_output_iterator<OutputIt, Char>::value)>
585 vformat_to(OutputIt out,
const text_style &ts,
588 auto &&buf = detail::get_buffer<Char>(out);
589 detail::vformat_to(buf, ts, format_str, args);
590 return detail::get_iterator(buf, out);
605 template <
typename OutputIt,
typename S,
typename... Args,
606 bool enable = detail::is_output_iterator<OutputIt, char_t<S>>::value
607 &&detail::is_string<S>::value>
608 inline auto format_to(OutputIt out,
const text_style &ts,
const S &format_str,
610 typename std::enable_if<enable, OutputIt>::type {
611 return vformat_to(out, ts, detail::to_string_view(format_str),
612 fmt::make_format_args<buffer_context<char_t<S>>>(args...));
615 template <
typename T,
typename Char>
616 struct formatter<detail::styled_arg<T>, Char> : formatter<T, Char> {
617 template <
typename FormatContext>
618 auto format(
const detail::styled_arg<T> &arg, FormatContext &ctx)
const
619 -> decltype(ctx.out()) {
620 const auto &ts = arg.style;
621 const auto &value = arg.value;
622 auto out = ctx.out();
624 bool has_style =
false;
625 if (ts.has_emphasis()) {
627 auto emphasis = detail::make_emphasis<Char>(ts.get_emphasis());
628 out = std::copy(emphasis.begin(), emphasis.end(), out);
630 if (ts.has_foreground()) {
633 detail::make_foreground_color<Char>(ts.get_foreground());
634 out = std::copy(foreground.begin(), foreground.end(), out);
636 if (ts.has_background()) {
639 detail::make_background_color<Char>(ts.get_background());
640 out = std::copy(background.begin(), background.end(), out);
642 out = formatter<T, Char>::format(value, ctx);
645 out = std::copy(reset_color.begin(), reset_color.end(), out);
663 template <
typename T>
664 FMT_CONSTEXPR
auto styled(
const T &value,
text_style ts)
665 -> detail::styled_arg<remove_cvref_t<T>> {
666 return detail::styled_arg<remove_cvref_t<T>>{value, ts};
669 FMT_MODULE_EXPORT_END
void append(const U *begin, const U *end)
friend FMT_CONSTEXPR text_style fg(detail::color_type foreground) noexcept
Definition: color.h:322
friend FMT_CONSTEXPR text_style bg(detail::color_type background) noexcept
Definition: color.h:327
double g(RaB r, PrincipalQN n, DiracQN k, Zeff z, AlphaFS a)
Lower (small) radial component.
Definition: DiracHydrogen.cpp:83
constexpr double c
speed of light in a.u. (=1/alpha)
Definition: PhysConst_constants.hpp:17
std::vector< T > reverse(std::vector< T > in)
Reverses a list.
Definition: Vector.hpp:397