Add more emphases
This commit is contained in:
parent
18af1dc460
commit
353be8519f
@ -185,9 +185,17 @@ enum class terminal_color : uint8_t {
|
|||||||
|
|
||||||
enum class emphasis : uint8_t {
|
enum class emphasis : uint8_t {
|
||||||
bold = 1,
|
bold = 1,
|
||||||
italic = 1 << 1,
|
faint = 1 << 1,
|
||||||
underline = 1 << 2,
|
dim = faint,
|
||||||
strikethrough = 1 << 3
|
italic = 1 << 2,
|
||||||
|
underline = 1 << 3,
|
||||||
|
blink = 1 << 4,
|
||||||
|
slow_blink = blink,
|
||||||
|
reverse = 1 << 5,
|
||||||
|
invert = reverse,
|
||||||
|
conceal = 1 << 6,
|
||||||
|
hide = conceal,
|
||||||
|
strikethrough = 1 << 7,
|
||||||
};
|
};
|
||||||
|
|
||||||
// rgb is a struct for red, green and blue colors.
|
// rgb is a struct for red, green and blue colors.
|
||||||
@ -399,7 +407,7 @@ template <typename Char> struct ansi_color_escape {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < 7; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
buffer[i] = static_cast<Char>(esc[i]);
|
buffer[i] = static_cast<Char>(esc[i]);
|
||||||
}
|
}
|
||||||
rgb color(text_color.value.rgb_color);
|
rgb color(text_color.value.rgb_color);
|
||||||
@ -409,16 +417,19 @@ template <typename Char> struct ansi_color_escape {
|
|||||||
buffer[19] = static_cast<Char>(0);
|
buffer[19] = static_cast<Char>(0);
|
||||||
}
|
}
|
||||||
FMT_CONSTEXPR ansi_color_escape(emphasis em) FMT_NOEXCEPT {
|
FMT_CONSTEXPR ansi_color_escape(emphasis em) FMT_NOEXCEPT {
|
||||||
uint8_t em_codes[4] = {};
|
uint8_t em_codes[8] = {};
|
||||||
uint8_t em_bits = static_cast<uint8_t>(em);
|
uint8_t em_bits = static_cast<uint8_t>(em);
|
||||||
if (em_bits & static_cast<uint8_t>(emphasis::bold)) em_codes[0] = 1;
|
if (em_bits & static_cast<uint8_t>(emphasis::bold)) em_codes[0] = 1;
|
||||||
if (em_bits & static_cast<uint8_t>(emphasis::italic)) em_codes[1] = 3;
|
if (em_bits & static_cast<uint8_t>(emphasis::faint)) em_codes[1] = 2;
|
||||||
if (em_bits & static_cast<uint8_t>(emphasis::underline)) em_codes[2] = 4;
|
if (em_bits & static_cast<uint8_t>(emphasis::italic)) em_codes[2] = 3;
|
||||||
if (em_bits & static_cast<uint8_t>(emphasis::strikethrough))
|
if (em_bits & static_cast<uint8_t>(emphasis::underline)) em_codes[3] = 4;
|
||||||
em_codes[3] = 9;
|
if (em_bits & static_cast<uint8_t>(emphasis::blink)) em_codes[4] = 5;
|
||||||
|
if (em_bits & static_cast<uint8_t>(emphasis::reverse)) em_codes[5] = 7;
|
||||||
|
if (em_bits & static_cast<uint8_t>(emphasis::conceal)) em_codes[6] = 8;
|
||||||
|
if (em_bits & static_cast<uint8_t>(emphasis::strikethrough)) em_codes[7] = 9;
|
||||||
|
|
||||||
size_t index = 0;
|
size_t index = 0;
|
||||||
for (int i = 0; i < 4; ++i) {
|
for (int i = 0; i < 7; ++i) {
|
||||||
if (!em_codes[i]) continue;
|
if (!em_codes[i]) continue;
|
||||||
buffer[index++] = static_cast<Char>('\x1b');
|
buffer[index++] = static_cast<Char>('\x1b');
|
||||||
buffer[index++] = static_cast<Char>('[');
|
buffer[index++] = static_cast<Char>('[');
|
||||||
@ -435,7 +446,7 @@ template <typename Char> struct ansi_color_escape {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Char buffer[7u + 3u * 4u + 1u];
|
Char buffer[7u + 3u * 8u + 1u];
|
||||||
|
|
||||||
static FMT_CONSTEXPR void to_esc(uint8_t c, Char* out,
|
static FMT_CONSTEXPR void to_esc(uint8_t c, Char* out,
|
||||||
char delimiter) FMT_NOEXCEPT {
|
char delimiter) FMT_NOEXCEPT {
|
||||||
|
|||||||
@ -22,10 +22,17 @@ TEST(color_test, format) {
|
|||||||
fmt::format(fg(fmt::color::blue) | bg(fmt::color::red), "two color"),
|
fmt::format(fg(fmt::color::blue) | bg(fmt::color::red), "two color"),
|
||||||
"\x1b[38;2;000;000;255m\x1b[48;2;255;000;000mtwo color\x1b[0m");
|
"\x1b[38;2;000;000;255m\x1b[48;2;255;000;000mtwo color\x1b[0m");
|
||||||
EXPECT_EQ(fmt::format(fmt::emphasis::bold, "bold"), "\x1b[1mbold\x1b[0m");
|
EXPECT_EQ(fmt::format(fmt::emphasis::bold, "bold"), "\x1b[1mbold\x1b[0m");
|
||||||
|
EXPECT_EQ(fmt::format(fmt::emphasis::faint, "faint"), "\x1b[2mfaint\x1b[0m");
|
||||||
EXPECT_EQ(fmt::format(fmt::emphasis::italic, "italic"),
|
EXPECT_EQ(fmt::format(fmt::emphasis::italic, "italic"),
|
||||||
"\x1b[3mitalic\x1b[0m");
|
"\x1b[3mitalic\x1b[0m");
|
||||||
EXPECT_EQ(fmt::format(fmt::emphasis::underline, "underline"),
|
EXPECT_EQ(fmt::format(fmt::emphasis::underline, "underline"),
|
||||||
"\x1b[4munderline\x1b[0m");
|
"\x1b[4munderline\x1b[0m");
|
||||||
|
EXPECT_EQ(fmt::format(fmt::emphasis::blink, "blink"),
|
||||||
|
"\x1b[5mblink\x1b[0m");
|
||||||
|
EXPECT_EQ(fmt::format(fmt::emphasis::reverse, "reverse"),
|
||||||
|
"\x1b[7mreverse\x1b[0m");
|
||||||
|
EXPECT_EQ(fmt::format(fmt::emphasis::conceal, "conceal"),
|
||||||
|
"\x1b[8mconceal\x1b[0m");
|
||||||
EXPECT_EQ(fmt::format(fmt::emphasis::strikethrough, "strikethrough"),
|
EXPECT_EQ(fmt::format(fmt::emphasis::strikethrough, "strikethrough"),
|
||||||
"\x1b[9mstrikethrough\x1b[0m");
|
"\x1b[9mstrikethrough\x1b[0m");
|
||||||
EXPECT_EQ(
|
EXPECT_EQ(
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user