1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-28 05:46:38 +02:00

irc: add support of strikethrough color attribute (using half bright) (closes #2248)

As ncurses doesn't support strikethrough, the text is rendered as half
bright (WeeChat color: "dim").
This commit is contained in:
Sébastien Helleu
2025-04-26 12:44:35 +02:00
parent a008e8a423
commit 683fa2f585
12 changed files with 121 additions and 20 deletions
+34 -1
View File
@@ -215,7 +215,8 @@ irc_color_decode (const char *string, int keep_colors)
char str_fg[16], str_bg[16], str_color[128], str_key[128], str_to_add[128];
const char *remapped_color;
unsigned char *ptr_string;
int length, fg, bg, fg_term, bg_term, bold, reverse, italic, underline;
int length, fg, bg, fg_term, bg_term;
int bold, reverse, italic, strikethrough, underline;
long fg_rgb, bg_rgb;
if (!string)
@@ -230,6 +231,7 @@ irc_color_decode (const char *string, int keep_colors)
bold = 0;
reverse = 0;
italic = 0;
strikethrough = 0;
underline = 0;
ptr_string = (unsigned char *)string;
@@ -256,6 +258,7 @@ irc_color_decode (const char *string, int keep_colors)
bold = 0;
reverse = 0;
italic = 0;
strikethrough = 0;
underline = 0;
ptr_string++;
break;
@@ -277,6 +280,15 @@ irc_color_decode (const char *string, int keep_colors)
italic ^= 1;
ptr_string++;
break;
case IRC_COLOR_STRIKETHROUGH_CHAR:
if (keep_colors)
{
snprintf (str_to_add, sizeof (str_to_add), "%s",
weechat_color ((strikethrough) ? "-dim" : "dim"));
}
strikethrough ^= 1;
ptr_string++;
break;
case IRC_COLOR_UNDERLINE_CHAR:
if (keep_colors)
{
@@ -660,6 +672,11 @@ irc_color_encode (const char *string, int keep_colors)
weechat_string_dyn_concat (out, IRC_COLOR_ITALIC_STR, -1);
ptr_string++;
break;
case 0x1E: /* ^^ */
if (keep_colors)
weechat_string_dyn_concat (out, IRC_COLOR_STRIKETHROUGH_STR, -1);
ptr_string++;
break;
case 0x1F: /* ^_ */
if (keep_colors)
weechat_string_dyn_concat (out, IRC_COLOR_UNDERLINE_STR, -1);
@@ -740,6 +757,7 @@ irc_color_decode_ansi_cb (void *data, const char *text)
ansi_state->bold = 0;
ansi_state->underline = 0;
ansi_state->italic = 0;
ansi_state->strikethrough = 0;
break;
case 1: /* bold */
if (!ansi_state->bold)
@@ -771,6 +789,13 @@ irc_color_decode_ansi_cb (void *data, const char *text)
ansi_state->underline = 1;
}
break;
case 9: /* strikethrough */
if (!ansi_state->strikethrough)
{
strcat (output, IRC_COLOR_STRIKETHROUGH_STR);
ansi_state->strikethrough = 1;
}
break;
case 23: /* remove italic */
if (ansi_state->italic)
{
@@ -785,6 +810,13 @@ irc_color_decode_ansi_cb (void *data, const char *text)
ansi_state->underline = 0;
}
break;
case 29: /* remove strikethrough */
if (ansi_state->strikethrough)
{
strcat (output, IRC_COLOR_STRIKETHROUGH_STR);
ansi_state->strikethrough = 0;
}
break;
case 30: /* text color */
case 31:
case 32:
@@ -987,6 +1019,7 @@ irc_color_decode_ansi (const char *string, int keep_colors)
ansi_state.bold = 0;
ansi_state.underline = 0;
ansi_state.italic = 0;
ansi_state.strikethrough = 0;
return weechat_string_replace_regex (string, irc_color_regex_ansi,
"$0", '$',
+18 -14
View File
@@ -40,26 +40,29 @@
/* attributes in IRC messages for color & style (bold, ..) */
#define IRC_COLOR_BOLD_CHAR '\x02' /* bold text */
#define IRC_COLOR_BOLD_STR "\x02" /* [02]...[02] */
#define IRC_COLOR_BOLD_CHAR '\x02' /* bold text */
#define IRC_COLOR_BOLD_STR "\x02" /* [02]...[02] */
#define IRC_COLOR_COLOR_CHAR '\x03' /* text color: fg/fg,bg/,bg */
#define IRC_COLOR_COLOR_STR "\x03" /* [03]15,05...[03] */
#define IRC_COLOR_COLOR_CHAR '\x03' /* text color: fg/fg,bg/,bg */
#define IRC_COLOR_COLOR_STR "\x03" /* [03]15,05...[03] */
#define IRC_COLOR_HEX_COLOR_CHAR '\x04' /* text color (hex): fg/fg,bg/,bg */
#define IRC_COLOR_HEX_COLOR_STR "\x04" /* [04]FFFF00,8B008B...[04] */
#define IRC_COLOR_HEX_COLOR_CHAR '\x04' /* hex text col.: fg/fg,bg/,bg */
#define IRC_COLOR_HEX_COLOR_STR "\x04" /* [04]FFFF00,8B008B...[04] */
#define IRC_COLOR_RESET_CHAR '\x0F' /* reset color/attributes */
#define IRC_COLOR_RESET_STR "\x0F" /* [0F]... */
#define IRC_COLOR_RESET_CHAR '\x0F' /* reset color/attributes */
#define IRC_COLOR_RESET_STR "\x0F" /* [0F]... */
#define IRC_COLOR_REVERSE_CHAR '\x16' /* reverse video (fg <--> bg) */
#define IRC_COLOR_REVERSE_STR "\x16" /* [16]...[16] */
#define IRC_COLOR_REVERSE_CHAR '\x16' /* reverse video (fg <--> bg) */
#define IRC_COLOR_REVERSE_STR "\x16" /* [16]...[16] */
#define IRC_COLOR_ITALIC_CHAR '\x1D' /* italic text */
#define IRC_COLOR_ITALIC_STR "\x1D" /* [1D]...[1D] */
#define IRC_COLOR_ITALIC_CHAR '\x1D' /* italic text */
#define IRC_COLOR_ITALIC_STR "\x1D" /* [1D]...[1D] */
#define IRC_COLOR_UNDERLINE_CHAR '\x1F' /* underlined text */
#define IRC_COLOR_UNDERLINE_STR "\x1F" /* [1F]...[1F] */
#define IRC_COLOR_STRIKETHROUGH_CHAR '\x1E' /* strikethrough text */
#define IRC_COLOR_STRIKETHROUGH_STR "\x1E" /* [1E]...[1E] */
#define IRC_COLOR_UNDERLINE_CHAR '\x1F' /* underlined text */
#define IRC_COLOR_UNDERLINE_STR "\x1F" /* [1F]...[1F] */
#define IRC_COLOR_TERM2IRC_NUM_COLORS 16
@@ -117,6 +120,7 @@ struct t_irc_color_ansi_state
char bold;
char underline;
char italic;
char strikethrough;
};
extern char *irc_color_decode (const char *string, int keep_colors);