src: Support strikethrough faces

This commit is contained in:
Jason Felice 2020-11-02 14:55:15 -05:00 committed by Maxime Coste
parent cbd0dc571b
commit 5d497dc46e
5 changed files with 18 additions and 13 deletions

View File

@ -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

View File

@ -16,9 +16,10 @@ enum class Attribute : int
Bold = 1 << 4,
Dim = 1 << 5,
Italic = 1 << 6,
FinalFg = 1 << 7,
FinalBg = 1 << 8,
FinalAttr = 1 << 9,
Strikethrough = 1 << 7,
FinalFg = 1 << 8,
FinalBg = 1 << 9,
FinalAttr = 1 << 10,
Final = FinalFg | FinalBg | FinalAttr
};

View File

@ -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;

View File

@ -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 |

View File

@ -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]);