Skip to content

Commit

Permalink
color: Support ANSI 2x clear sequences
Browse files Browse the repository at this point in the history
Add support for ANSI clear sequences.

Sequences like `<esc>[1m` (bold), have matching sequences to unset them,
without affecting the colour or other attributes.

- bold:      Set 1m, Clear 22m
- italic:    Set 3m, Clear 23m
- underline: Set 4m, Clear 24m
- blink:     Set 5m, Clear 25m
- reverse:   Set 7m, Clear 27m
  • Loading branch information
flatcap committed Oct 28, 2023
1 parent 6a63a51 commit f5a14b1
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions color/parse_ansi.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,31 @@ int ansi_color_parse_single(const char *buf, struct AnsiColor *ansi, bool dry_ru
ansi->attrs |= A_BOLD;
pos += 2;
}
else if ((buf[pos] == '2') && isdigit(buf[pos + 1]) && ansi_is_end_char(buf[pos + 2]))
{
char digit = buf[pos + 1];
pos += 3;
if (digit == '2')
{
ansi->attrs &= ~A_BOLD; // Clear the flag
}
else if (digit == '3')
{
ansi->attrs &= ~A_ITALIC; // Clear the flag
}
else if (digit == '4')
{
ansi->attrs &= ~A_UNDERLINE; // Clear the flag
}
else if (digit == '5')
{
ansi->attrs &= ~A_BLINK; // Clear the flag
}
else if (digit == '7')
{
ansi->attrs &= ~A_REVERSE; // Clear the flag
}
}
else if ((buf[pos] == '3') && ansi_is_end_char(buf[pos + 1]))
{
ansi->attrs |= A_ITALIC;
Expand Down

0 comments on commit f5a14b1

Please sign in to comment.