From 5d497dc46e7986f2f215a6d96f62c929dccc83c2 Mon Sep 17 00:00:00 2001 From: Jason Felice Date: Mon, 2 Nov 2020 14:55:15 -0500 Subject: [PATCH] src: Support strikethrough faces --- doc/pages/faces.asciidoc | 2 ++ src/face.hh | 23 ++++++++++++----------- src/face_registry.cc | 1 + src/json_ui.cc | 1 + src/terminal_ui.cc | 4 ++-- 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/doc/pages/faces.asciidoc b/doc/pages/faces.asciidoc index 50472637..22f4ef2f 100644 --- a/doc/pages/faces.asciidoc +++ b/doc/pages/faces.asciidoc @@ -40,6 +40,8 @@ following format: dim *i*::: italic + *s*::: + strikethrough *F*::: final, override the previous face instead of merging with it, and this face will only be replaced if another face with diff --git a/src/face.hh b/src/face.hh index ecb31dc3..798cd3f3 100644 --- a/src/face.hh +++ b/src/face.hh @@ -9,17 +9,18 @@ namespace Kakoune enum class Attribute : int { - Normal = 0, - Underline = 1 << 1, - Reverse = 1 << 2, - Blink = 1 << 3, - Bold = 1 << 4, - Dim = 1 << 5, - Italic = 1 << 6, - FinalFg = 1 << 7, - FinalBg = 1 << 8, - FinalAttr = 1 << 9, - Final = FinalFg | FinalBg | FinalAttr + Normal = 0, + Underline = 1 << 1, + Reverse = 1 << 2, + Blink = 1 << 3, + Bold = 1 << 4, + Dim = 1 << 5, + Italic = 1 << 6, + Strikethrough = 1 << 7, + FinalFg = 1 << 8, + FinalBg = 1 << 9, + FinalAttr = 1 << 10, + Final = FinalFg | FinalBg | FinalAttr }; constexpr bool with_bit_ops(Meta::Type) { return true; } diff --git a/src/face_registry.cc b/src/face_registry.cc index 9a70f936..8bf43bcb 100644 --- a/src/face_registry.cc +++ b/src/face_registry.cc @@ -43,6 +43,7 @@ static FaceRegistry::FaceSpec parse_face(StringView facedesc) case 'B': face.attributes |= Attribute::Blink; break; case 'd': face.attributes |= Attribute::Dim; break; case 'i': face.attributes |= Attribute::Italic; break; + case 's': face.attributes |= Attribute::Strikethrough; break; case 'f': face.attributes |= Attribute::FinalFg; break; case 'g': face.attributes |= Attribute::FinalBg; break; case 'a': face.attributes |= Attribute::FinalAttr; break; diff --git a/src/json_ui.cc b/src/json_ui.cc index 111438c4..36c547ef 100644 --- a/src/json_ui.cc +++ b/src/json_ui.cc @@ -46,6 +46,7 @@ String to_json(Attribute attributes) { Attribute::FinalFg, "final_fg" }, { Attribute::FinalBg, "final_bg" }, { Attribute::FinalAttr, "final_attr" }, + { Attribute::Strikethrough, "strikethrough" }, }; return "[" + join(attrs | diff --git a/src/terminal_ui.cc b/src/terminal_ui.cc index 34d8eee3..8767079b 100644 --- a/src/terminal_ui.cc +++ b/src/terminal_ui.cc @@ -183,7 +183,7 @@ void TerminalUI::Screen::set_face(const Face& face) { static constexpr int fg_table[]{ 39, 30, 31, 32, 33, 34, 35, 36, 37, 90, 91, 92, 93, 94, 95, 96, 97 }; static constexpr int bg_table[]{ 49, 40, 41, 42, 43, 44, 45, 46, 47, 100, 101, 102, 103, 104, 105, 106, 107 }; - static constexpr int attr_table[]{ 0, 4, 7, 5, 1, 2, 3 }; + static constexpr int attr_table[]{ 0, 4, 7, 5, 1, 2, 3, 9 }; auto set_color = [](bool fg, const Color& color, bool join) { if (join) @@ -201,7 +201,7 @@ void TerminalUI::Screen::set_face(const Face& face) bool join = false; if (face.attributes != m_active_face.attributes) { - for (int i = 0; i < sizeof(attr_table) / sizeof(int); ++i) + for (int i = 0; i < std::size(attr_table); ++i) { if (face.attributes & (Attribute)(1 << i)) printf(";%d", attr_table[i]);