Public Member Functions | Static Private Member Functions | Private Attributes | List of all members
internal::ansi_color_escape< Char > Struct Template Reference

#include <color.h>

Public Member Functions

FMT_CONSTEXPR ansi_color_escape (internal::color_type text_color, const char *esc) FMT_NOEXCEPT
 
FMT_CONSTEXPR ansi_color_escape (emphasis em) FMT_NOEXCEPT
 
FMT_CONSTEXPR operator const Char * () const FMT_NOEXCEPT
 

Static Private Member Functions

static FMT_CONSTEXPR void to_esc (uint8_t c, Char *out, char delimiter) FMT_NOEXCEPT
 

Private Attributes

Char buffer [7u+3u *4u+1u]
 

Detailed Description

template<typename Char>
struct internal::ansi_color_escape< Char >

Definition at line 392 of file color.h.

Constructor & Destructor Documentation

template<typename Char>
FMT_CONSTEXPR internal::ansi_color_escape< Char >::ansi_color_escape ( internal::color_type  text_color,
const char *  esc 
)
inline

Definition at line 393 of file color.h.

394  {
395  // If we have a terminal color, we need to output another escape code
396  // sequence.
397  if (!text_color.is_rgb) {
398  bool is_background = esc == internal::data::BACKGROUND_COLOR;
399  uint32_t value = text_color.value.term_color;
400  // Background ASCII codes are the same as the foreground ones but with
401  // 10 more.
402  if (is_background)
403  value += 10u;
404 
405  std::size_t index = 0;
406  buffer[index++] = static_cast<Char>('\x1b');
407  buffer[index++] = static_cast<Char>('[');
408 
409  if (value >= 100u) {
410  buffer[index++] = static_cast<Char>('1');
411  value %= 100u;
412  }
413  buffer[index++] = static_cast<Char>('0' + value / 10u);
414  buffer[index++] = static_cast<Char>('0' + value % 10u);
415 
416  buffer[index++] = static_cast<Char>('m');
417  buffer[index++] = static_cast<Char>('\0');
418  return;
419  }
420 
421  for (int i = 0; i < 7; i++) {
422  buffer[i] = static_cast<Char>(esc[i]);
423  }
424  rgb color(text_color.value.rgb_color);
425  to_esc(color.r, buffer + 7, ';');
426  to_esc(color.g, buffer + 11, ';');
427  to_esc(color.b, buffer + 15, 'm');
428  buffer[19] = static_cast<Char>(0);
429  }
static const char BACKGROUND_COLOR[]
Definition: format.h:755
unsigned int uint32_t
Definition: stdint.h:126
static FMT_CONSTEXPR void to_esc(uint8_t c, Char *out, char delimiter) FMT_NOEXCEPT
Definition: color.h:458
color
Definition: color.h:50
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1225
union internal::color_type::color_union value
Definition: color.h:223
template<typename Char>
FMT_CONSTEXPR internal::ansi_color_escape< Char >::ansi_color_escape ( emphasis  em)
inline

Definition at line 430 of file color.h.

430  {
431  uint8_t em_codes[4] = {};
432  uint8_t em_bits = static_cast<uint8_t>(em);
433  if (em_bits & static_cast<uint8_t>(emphasis::bold))
434  em_codes[0] = 1;
435  if (em_bits & static_cast<uint8_t>(emphasis::italic))
436  em_codes[1] = 3;
437  if (em_bits & static_cast<uint8_t>(emphasis::underline))
438  em_codes[2] = 4;
439  if (em_bits & static_cast<uint8_t>(emphasis::strikethrough))
440  em_codes[3] = 9;
441 
442  std::size_t index = 0;
443  for (int i = 0; i < 4; ++i) {
444  if (!em_codes[i])
445  continue;
446  buffer[index++] = static_cast<Char>('\x1b');
447  buffer[index++] = static_cast<Char>('[');
448  buffer[index++] = static_cast<Char>('0' + em_codes[i]);
449  buffer[index++] = static_cast<Char>('m');
450  }
451  buffer[index++] = static_cast<Char>(0);
452  }
unsigned char uint8_t
Definition: stdint.h:124

Member Function Documentation

template<typename Char>
FMT_CONSTEXPR internal::ansi_color_escape< Char >::operator const Char * ( ) const
inline

Definition at line 453 of file color.h.

453 { return buffer; }
Char buffer[7u+3u *4u+1u]
Definition: color.h:456
template<typename Char>
static FMT_CONSTEXPR void internal::ansi_color_escape< Char >::to_esc ( uint8_t  c,
Char *  out,
char  delimiter 
)
inlinestaticprivate

Definition at line 458 of file color.h.

459  {
460  out[0] = static_cast<Char>('0' + c / 100);
461  out[1] = static_cast<Char>('0' + c / 10 % 10);
462  out[2] = static_cast<Char>('0' + c % 10);
463  out[3] = static_cast<Char>(delimiter);
464  }

Member Data Documentation

template<typename Char>
Char internal::ansi_color_escape< Char >::buffer[7u+3u *4u+1u]
private

Definition at line 456 of file color.h.


The documentation for this struct was generated from the following file: