* core: display only version with command `/version`, add options `-o` and `-ol` in command `/upgrade`
* core: add number of processes in command `/sys waitpid`
* core, alias, trigger: allow wildcard in commands `/bar`, `/item`, `/proxy`, `/alias` and `/trigger` (issue #1956)
+ * irc: add support of RGB colors in messages (issue #2025)
* irc: add tags "nick_xxx" and "host_xxx" in all messages, including self and server messages
* irc: add option irc.look.ignore_tag_messages (issue #989)
* trigger: rename local variable "trigger_filter" to "filter" on monitor buffer (issue #2037)
[[v4.2.0]]
== Version 4.2.0 (under dev)
+[[4.2.0_irc_rgb_colors]]
+=== RGB colors in IRC messages
+
+Support for RGB colors in IRC messages has been added and a new key
+[Ctrl+c], kbd:[d] is available to insert this color code in command line.
+
+You can add this key with this command:
+
+----
+/key missing
+----
+
[[v4.2.0_custom_bar_items]]
=== Custom bar items
| kbd:[Ctrl+c], kbd:[c],
kbd:[xx], kbd:[,],
kbd:[yy] | Textfarbe `xx` und Hintergrundfarbe `yy` (siehe Farbtabelle).
+// TRANSLATION MISSING
+| kbd:[Ctrl+c], kbd:[d],
+ kbd:[xxxxxx] | Text color `xxxxxx` (RGB as hexadecimal, for example `FF0000` for red).
+// TRANSLATION MISSING
+| kbd:[Ctrl+c], kbd:[d],
+ kbd:[xxxxxx], kbd:[,],
+ kbd:[yyyyyy] | Text color `xxxxxx` and background `yyyyyy` (RGB as hexadecimal).
| kbd:[Ctrl+c], kbd:[i] | Text wird kursiv dargestellt.
| kbd:[Ctrl+c], kbd:[o] | deaktiviert Farben und Attribute.
| kbd:[Ctrl+c], kbd:[v] | Farben umkehren (kehrt Textfarbe und Hintergrundfarbe um).
|===
[NOTE]
-Der selbe Befehl (ohne den Wert für kbd:[Ctrl+c], kbd:[c]) sollte genutzt werden
-um die Farbkodierungen bzw. Attribute zu deaktivieren.
+// TRANSLATION MISSING
+The same code (without number for kbd:[Ctrl+c], kbd:[c] and kbd:[Ctrl+c], kbd:[d])
+can be used to stop the attribute.
Farbtabelle für kbd:[Ctrl+c], kbd:[c]:
| Taste | Beschreibung | Befehl
| kbd:[Ctrl+c], kbd:[b] | fügt Steuerzeichen für fett geschrieben Text ein. | `+/input insert \x02+`
| kbd:[Ctrl+c], kbd:[c] | fügt Steuerzeichen für Textfarbe ein. | `+/input insert \x03+`
+// TRANSLATION MISSING
+| kbd:[Ctrl+c], kbd:[d] | Insert code for colored text (RGB color, as hexadecimal). | `+/input insert \x04+`
| kbd:[Ctrl+c], kbd:[i] | fügt Steuerzeichen für kursiven Text ein. | `+/input insert \x1D+`
| kbd:[Ctrl+c], kbd:[o] | fügt Steuerzeichen für Standardfarbe ein. | `+/input insert \x0F+`
| kbd:[Ctrl+c], kbd:[v] | fügt Steuerzeichen für Hintergrundfarbe ein. | `+/input insert \x16+`
| kbd:[Ctrl+c], kbd:[c],
kbd:[xx], kbd:[,],
kbd:[yy] | Text color `xx` and background `yy` (see list of colors below).
+| kbd:[Ctrl+c], kbd:[d],
+ kbd:[xxxxxx] | Text color `xxxxxx` (RGB as hexadecimal, for example `FF0000` for red).
+| kbd:[Ctrl+c], kbd:[d],
+ kbd:[xxxxxx], kbd:[,],
+ kbd:[yyyyyy] | Text color `xxxxxx` and background `yyyyyy` (RGB as hexadecimal).
| kbd:[Ctrl+c], kbd:[i] | Italic text.
| kbd:[Ctrl+c], kbd:[o] | Disable color and attributes.
| kbd:[Ctrl+c], kbd:[v] | Reverse video (revert text color with background).
|===
[NOTE]
-The same code (without number for kbd:[Ctrl+c], kbd:[c]) can be used to stop the
-attribute.
+The same code (without number for kbd:[Ctrl+c], kbd:[c] and kbd:[Ctrl+c], kbd:[d])
+can be used to stop the attribute.
Color codes for kbd:[Ctrl+c], kbd:[c] are:
| Key | Description | Command
| kbd:[Ctrl+c], kbd:[b] | Insert code for bold text. | `+/input insert \x02+`
| kbd:[Ctrl+c], kbd:[c] | Insert code for colored text. | `+/input insert \x03+`
+| kbd:[Ctrl+c], kbd:[d] | Insert code for colored text (RGB color, as hexadecimal). | `+/input insert \x04+`
| kbd:[Ctrl+c], kbd:[i] | Insert code for italic text. | `+/input insert \x1D+`
| kbd:[Ctrl+c], kbd:[o] | Insert code for color reset. | `+/input insert \x0F+`
| kbd:[Ctrl+c], kbd:[v] | Insert code for reverse color. | `+/input insert \x16+`
| kbd:[Ctrl+c], kbd:[c],
kbd:[xx], kbd:[,],
kbd:[yy] | Couleur du texte `xx` et du fond `yy` (voir la liste des couleurs ci-dessous).
+| kbd:[Ctrl+c], kbd:[d],
+ kbd:[xxxxxx] | Couleur du texte `xxxxxx` (RGB en hexadécimal, par exemple `FF0000` pour du rouge).
+| kbd:[Ctrl+c], kbd:[d],
+ kbd:[xxxxxx], kbd:[,],
+ kbd:[yyyyyy] | Couleur du texte `xxxxxx` et du fond `yyyyyy` (RGB en hexadécimal).
| kbd:[Ctrl+c], kbd:[i] | Texte en italique.
| kbd:[Ctrl+c], kbd:[o] | Désactiver la couleur et tous les attributs.
| kbd:[Ctrl+c], kbd:[v] | Vidéo inverse (inversion de la couleur d'écriture et du fond).
|===
[NOTE]
-Le même code (sans le numéro pour kbd:[Ctrl+c], kbd:[c]) peut être utilisé pour
-stopper l'attribut défini.
+Le même code (sans le numéro pour kbd:[Ctrl+c], kbd:[c] et kbd:[Ctrl+c], kbd:[d])
+peut être utilisé pour stopper l'attribut défini.
Les codes couleur pour kbd:[Ctrl+c], kbd:[c] sont :
| Touche | Description | Commande
| kbd:[Ctrl+c], kbd:[b] | Insérer le code pour mettre le texte en gras. | `+/input insert \x02+`
| kbd:[Ctrl+c], kbd:[c] | Insérer le code pour écrire en couleur. | `+/input insert \x03+`
+| kbd:[Ctrl+c], kbd:[d] | Insérer le code pour écrire en couleur (couleur RGB, en hexadécimal). | `+/input insert \x04+`
| kbd:[Ctrl+c], kbd:[i] | Insérer le code pour mettre le texte en italique. | `+/input insert \x1D+`
| kbd:[Ctrl+c], kbd:[o] | Insérer le code pour réinitialiser la couleur. | `+/input insert \x0F+`
| kbd:[Ctrl+c], kbd:[v] | Insérer le code pour écrire en couleur inversée. | `+/input insert \x16+`
kbd:[xx], kbd:[,],
kbd:[yy] | colore del testo `xx` e di sfondo `yy` (consultare la lista di colori che segue).
// TRANSLATION MISSING
+| kbd:[Ctrl+c], kbd:[d],
+ kbd:[xxxxxx] | Text color `xxxxxx` (RGB as hexadecimal, for example `FF0000` for red).
+// TRANSLATION MISSING
+| kbd:[Ctrl+c], kbd:[d],
+ kbd:[xxxxxx], kbd:[,],
+ kbd:[yyyyyy] | Text color `xxxxxx` and background `yyyyyy` (RGB as hexadecimal).
+// TRANSLATION MISSING
| kbd:[Ctrl+c], kbd:[i] | italic text.
| kbd:[Ctrl+c], kbd:[o] | disabilita colori ed attributi.
| kbd:[Ctrl+c], kbd:[v] | video inverso (inverte il colore del testo con quello di sfondo).
|===
[NOTE]
-Lo stesso codice (senza numero per kbd:[Ctrl+c], kbd:[c]) può essere usato per
-terminare l'attributo.
+// TRANSLATION MISSING
+The same code (without number for kbd:[Ctrl+c], kbd:[c] and kbd:[Ctrl+c], kbd:[d])
+can be used to stop the attribute.
I codici colore per kbd:[Ctrl+c], kbd:[c] sono:
| Tasti | Descrizione | Comando
| kbd:[Ctrl+c], kbd:[b] | Inserisce il codice per il testo in grassetto. | `+/input insert \x02+`
| kbd:[Ctrl+c], kbd:[c] | Inserisce il codice per il testo colorato. | `+/input insert \x03+`
+// TRANSLATION MISSING
+| kbd:[Ctrl+c], kbd:[d] | Insert code for colored text (RGB color, as hexadecimal). | `+/input insert \x04+`
| kbd:[Ctrl+c], kbd:[i] | Inserisce il codice per il testo in corsivo. | `+/input insert \x1D+`
| kbd:[Ctrl+c], kbd:[o] | Inserisce il codice per il reset dei colori. | `+/input insert \x0F+`
| kbd:[Ctrl+c], kbd:[v] | Inserisce il codice per l'inversione dei colori. | `+/input insert \x16+`
| kbd:[Ctrl+c], kbd:[c],
kbd:[xx], kbd:[,],
kbd:[yy] | テキスト表示色を `xx` に、背景色を `yy` に (以下の色リストを参照)
+// TRANSLATION MISSING
+| kbd:[Ctrl+c], kbd:[d],
+ kbd:[xxxxxx] | Text color `xxxxxx` (RGB as hexadecimal, for example `FF0000` for red).
+// TRANSLATION MISSING
+| kbd:[Ctrl+c], kbd:[d],
+ kbd:[xxxxxx], kbd:[,],
+ kbd:[yyyyyy] | Text color `xxxxxx` and background `yyyyyy` (RGB as hexadecimal).
| kbd:[Ctrl+c], kbd:[i] | テキストをイタリック体に
| kbd:[Ctrl+c], kbd:[o] | テキスト表示色と属性をリセット
| kbd:[Ctrl+c], kbd:[v] | テキストを反転 (テキスト表示色と背景色の入れ替え)
|===
[NOTE]
-同じコードで (色コードを入力せずに kbd:[Ctrl+c], kbd:[c]
-を使うことで) 属性をキャンセルすることができます。
+// TRANSLATION MISSING
+The same code (without number for kbd:[Ctrl+c], kbd:[c] and kbd:[Ctrl+c], kbd:[d])
+can be used to stop the attribute.
kbd:[Ctrl+c], kbd:[c] 用の色コード:
| キー | 説明 | コマンド
| kbd:[Ctrl+c], kbd:[b] | テキストを太字化するコードの挿入 | `+/input insert \x02+`
| kbd:[Ctrl+c], kbd:[c] | テキストに色をつけるコードの挿入 | `+/input insert \x03+`
+// TRANSLATION MISSING
+| kbd:[Ctrl+c], kbd:[d] | Insert code for colored text (RGB color, as hexadecimal). | `+/input insert \x04+`
| kbd:[Ctrl+c], kbd:[i] | テキストをイタリック体にするコードの挿入 | `+/input insert \x1D+`
| kbd:[Ctrl+c], kbd:[o] | テキスト色のリセットを行うコードの挿入 | `+/input insert \x0F+`
| kbd:[Ctrl+c], kbd:[v] | テキスト色の反転を行うコードの挿入 | `+/input insert \x16+`
| kbd:[Ctrl+c], kbd:[c],
kbd:[xx], kbd:[,],
kbd:[yy] | kolor tekstu `xx` i tła `yy` (zgodnie z poniższą listą kolorów)
+// TRANSLATION MISSING
+| kbd:[Ctrl+c], kbd:[d],
+ kbd:[xxxxxx] | Text color `xxxxxx` (RGB as hexadecimal, for example `FF0000` for red).
+// TRANSLATION MISSING
+| kbd:[Ctrl+c], kbd:[d],
+ kbd:[xxxxxx], kbd:[,],
+ kbd:[yyyyyy] | Text color `xxxxxx` and background `yyyyyy` (RGB as hexadecimal).
| kbd:[Ctrl+c], kbd:[i] | pochyły tekst
| kbd:[Ctrl+c], kbd:[o] | wyłącza kolory i atrybuty
| kbd:[Ctrl+c], kbd:[v] | odwróć video (przywraca kolor tekstu i tła)
|===
[NOTE]
-Ten sam sktót (bez numeru dla kbd:[Ctrl+c], kbd:[c]) może zostać użyty do zatrzymania
-atrybutu.
+// TRANSLATION MISSING
+The same code (without number for kbd:[Ctrl+c], kbd:[c] and kbd:[Ctrl+c], kbd:[d])
+can be used to stop the attribute.
Kody kolorów dla kbd:[Ctrl+c], kbd:[c]:
| Skrót | Opis | Komenda
| kbd:[Ctrl+c], kbd:[b] | Wstaw kod dla pogrubionego tekstu. | `+/input insert \x02+`
| kbd:[Ctrl+c], kbd:[c] | Wstaw kod dla kolorowego tekstu. | `+/input insert \x03+`
+// TRANSLATION MISSING
+| kbd:[Ctrl+c], kbd:[d] | Insert code for colored text (RGB color, as hexadecimal). | `+/input insert \x04+`
| kbd:[Ctrl+c], kbd:[i] | Wstaw kod dla pochyłego tekstu. | `+/input insert \x1D+`
| kbd:[Ctrl+c], kbd:[o] | Wstaw kod dla zresetowania koloru. | `+/input insert \x0F+`
| kbd:[Ctrl+c], kbd:[v] | Wstaw kod dla odwrócenia koloru. | `+/input insert \x16+`
| kbd:[Ctrl+c], kbd:[c],
kbd:[xx], kbd:[,],
kbd:[yy] | Текст у боји `xx` и позадина у `yy` (погледајте листу боја испод).
+// TRANSLATION MISSING
+| kbd:[Ctrl+c], kbd:[d],
+ kbd:[xxxxxx] | Text color `xxxxxx` (RGB as hexadecimal, for example `FF0000` for red).
+// TRANSLATION MISSING
+| kbd:[Ctrl+c], kbd:[d],
+ kbd:[xxxxxx], kbd:[,],
+ kbd:[yyyyyy] | Text color `xxxxxx` and background `yyyyyy` (RGB as hexadecimal).
| kbd:[Ctrl+c], kbd:[i] | Текст у курзиву.
| kbd:[Ctrl+c], kbd:[o] | Искључивање боје и атрибута.
| kbd:[Ctrl+c], kbd:[v] | Обрнути видео (боје текста и позадине се замењују једна са другом).
|===
[NOTE]
-Исти кôд (без броја за kbd:[Ctrl+c], kbd:[c]) може да се употреби за заустављање атрибута.
+// TRANSLATION MISSING
+The same code (without number for kbd:[Ctrl+c], kbd:[c] and kbd:[Ctrl+c], kbd:[d])
+can be used to stop the attribute.
Кодови боја за kbd:[Ctrl+c], kbd:[c] су:
|===
| Тастер | Опис | Команда
| kbd:[Ctrl+c], kbd:[b] | Уметање кода за подебљани текст. | `+/input insert \x02+`
-| kbd:[Ctrl+c], kbd:[c] | Уметање кода за обојени текст. | `+/input insert \x03+`
+| kbd:[Ctrl+c
+// TRANSLATION MISSING
+| kbd:[Ctrl+c], kbd:[d] | Insert code for colored text (RGB color, as hexadecimal). | `+/input insert \x04+`], kbd:[c] | Уметање кода за обојени текст. | `+/input insert \x03+`
| kbd:[Ctrl+c], kbd:[i] | Уметање кода за текст у курзиву. | `+/input insert \x1D+`
| kbd:[Ctrl+c], kbd:[o] | Уметање кода за ресет боје. | `+/input insert \x0F+`
| kbd:[Ctrl+c], kbd:[v] | Уметање кода за обрнуту боју. | `+/input insert \x16+`
BIND("ctrl-s,ctrl-u", "/allbuf /buffer set unread");
BIND("ctrl-c,b", "/input insert \\x02");
BIND("ctrl-c,c", "/input insert \\x03");
+ BIND("ctrl-c,d", "/input insert \\x04");
BIND("ctrl-c,i", "/input insert \\x1D");
BIND("ctrl-c,o", "/input insert \\x0F");
BIND("ctrl-c,v", "/input insert \\x16");
regex_t *irc_color_regex_ansi = NULL;
+/*
+ * Converts a RGB color to terminal color.
+ *
+ * Returns a terminal color (between 0 and 255), -1 if error.
+ */
+
+int
+irc_color_convert_rgb2term (long rgb)
+{
+ char str_color[64], *info_color, *error;
+ long number;
+
+ if (rgb < 0)
+ return -1;
+
+ snprintf (str_color, sizeof (str_color), "%ld", rgb);
+
+ info_color = weechat_info_get ("color_rgb2term", str_color);
+ if (!info_color || !info_color[0])
+ {
+ if (info_color)
+ free (info_color);
+ return -1;
+ }
+
+ error = NULL;
+ number = strtol (info_color, &error, 10);
+ if (!error || error[0])
+ {
+ free (info_color);
+ return -1;
+ }
+
+ free (info_color);
+
+ return (int)number;
+}
+
+/*
+ * Converts a RGB color to IRC color.
+ *
+ * Returns a IRC color number (between 0 and 15), -1 if error.
+ */
+
+int
+irc_color_convert_rgb2irc (long rgb)
+{
+ char str_color[64], *error, *info_color;
+ long number;
+
+ if (rgb < 0)
+ return -1;
+
+ snprintf (str_color, sizeof (str_color),
+ "%ld,%d",
+ rgb,
+ IRC_COLOR_TERM2IRC_NUM_COLORS);
+
+ info_color = weechat_info_get ("color_rgb2term", str_color);
+ if (!info_color || !info_color[0])
+ {
+ if (info_color)
+ free (info_color);
+ return -1;
+ }
+
+ error = NULL;
+ number = strtol (info_color, &error, 10);
+ if (!error || error[0]
+ || (number < 0) || (number >= IRC_COLOR_TERM2IRC_NUM_COLORS))
+ {
+ free (info_color);
+ return -1;
+ }
+
+ free (info_color);
+
+ return irc_color_term2irc[number];
+}
+
+/*
+ * Converts a terminal color to IRC color.
+ *
+ * Returns a IRC color number (between 0 and 15), -1 if error.
+ */
+
+int
+irc_color_convert_term2irc (int color)
+{
+ char str_color[64], *error, *info_color;
+ long number;
+
+ snprintf (str_color, sizeof (str_color), "%d", color);
+
+ info_color = weechat_info_get ("color_term2rgb", str_color);
+ if (!info_color || !info_color[0])
+ {
+ if (info_color)
+ free (info_color);
+ return -1;
+ }
+
+ error = NULL;
+ number = strtol (info_color, &error, 10);
+ if (!error || error[0] || (number < 0) || (number > 0xFFFFFF))
+ {
+ free (info_color);
+ return -1;
+ }
+
+ free (info_color);
+
+ return irc_color_convert_rgb2irc (number);
+}
+
/*
* Replaces IRC colors by WeeChat colors.
*
char *
irc_color_decode (const char *string, int keep_colors)
{
- char **out;
- char str_fg[3], str_bg[3], str_color[128], str_key[128], str_to_add[128];
+ char **out, *error;
+ 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, bold, reverse, italic, underline, rc;
+ int length, fg, bg, bold, reverse, italic, underline, color_number;
+ long fg_rgb, bg_rgb;
if (!string)
return NULL;
bg = -1;
if (str_fg[0])
{
- rc = sscanf (str_fg, "%d", &fg);
- if ((rc != EOF) && (rc >= 1))
- {
+ error = NULL;
+ fg = (int)strtol (str_fg, &error, 10);
+ if (error && !error[0])
fg %= IRC_NUM_COLORS;
- }
+ else
+ fg = -1;
}
if (str_bg[0])
{
- rc = sscanf (str_bg, "%d", &bg);
- if ((rc != EOF) && (rc >= 1))
- {
+ error = NULL;
+ bg = (int)strtol (str_bg, &error, 10);
+ if (error && !error[0])
bg %= IRC_NUM_COLORS;
- }
+ else
+ bg = -1;
}
/* search "fg,bg" in hashtable of remapped colors */
snprintf (str_key, sizeof (str_key), "%d,%d", fg, bg);
}
}
break;
+ case IRC_COLOR_HEX_COLOR_CHAR:
+ ptr_string++;
+ str_fg[0] = '\0';
+ str_bg[0] = '\0';
+ if (isxdigit (ptr_string[0]))
+ {
+ /* foreground */
+ length = 1;
+ while (isxdigit (ptr_string[length]))
+ {
+ length++;
+ if (length == 6)
+ break;
+ }
+ memcpy (str_fg, ptr_string, length);
+ str_fg[length] = '\0';
+ ptr_string += length;
+ }
+ if ((ptr_string[0] == ',') && (isxdigit (ptr_string[1])))
+ {
+ /* background */
+ ptr_string++;
+ length = 1;
+ while (isxdigit (ptr_string[length]))
+ {
+ length++;
+ if (length == 6)
+ break;
+ }
+ memcpy (str_bg, ptr_string, length);
+ str_bg[length] = '\0';
+ ptr_string += length;
+ }
+ if (keep_colors)
+ {
+ if (str_fg[0] || str_bg[0])
+ {
+ fg_rgb = -1;
+ bg_rgb = -1;
+ if (str_fg[0])
+ {
+ error = NULL;
+ fg_rgb = strtol (str_fg, &error, 16);
+ if (!error || error[0])
+ fg_rgb = -1;
+ }
+ if (str_bg[0])
+ {
+ error = NULL;
+ bg_rgb = strtol (str_bg, &error, 16);
+ if (!error || error[0])
+ bg_rgb = -1;
+ }
+ str_fg[0] = '\0';
+ str_bg[0] = '\0';
+ if (fg_rgb >= 0)
+ {
+ color_number = irc_color_convert_rgb2term (fg_rgb);
+ if (color_number >= 0)
+ {
+ snprintf (str_fg, sizeof (str_fg),
+ "%d", color_number);
+ }
+ }
+ if (bg_rgb >= 0)
+ {
+ color_number = irc_color_convert_rgb2term (bg_rgb);
+ if (color_number >= 0)
+ {
+ snprintf (str_bg, sizeof (str_bg),
+ "%d", color_number);
+ }
+ }
+ snprintf (str_color, sizeof (str_color),
+ "|%s%s%s",
+ str_fg,
+ (str_bg[0]) ? "," : "",
+ str_bg);
+ snprintf (str_to_add, sizeof (str_to_add), "%s",
+ weechat_color (str_color));
+ }
+ else
+ {
+ snprintf (str_to_add, sizeof (str_to_add), "%s",
+ weechat_color ("resetcolor"));
+ }
+ }
+ break;
default:
/*
* we are not on an IRC color code, just copy the UTF-8 char
}
}
break;
+ case 0x04: /* ^D */
+ if (keep_colors)
+ weechat_string_dyn_concat (out, IRC_COLOR_HEX_COLOR_STR, -1);
+ ptr_string++;
+ if (isxdigit (ptr_string[0]))
+ {
+ /* foreground */
+ length = 1;
+ while (isxdigit (ptr_string[length]))
+ {
+ length++;
+ if (length == 6)
+ break;
+ }
+ if (keep_colors)
+ {
+ weechat_string_dyn_concat (out,
+ (const char *)ptr_string,
+ length);
+ }
+ ptr_string += length;
+ }
+ if (ptr_string[0] == ',')
+ {
+ /* background */
+ if (keep_colors)
+ weechat_string_dyn_concat (out, ",", -1);
+ ptr_string++;
+ if (isxdigit (ptr_string[0]))
+ {
+ length = 1;
+ while (isxdigit (ptr_string[length]))
+ {
+ length++;
+ if (length == 6)
+ break;
+ }
+ if (keep_colors)
+ {
+ weechat_string_dyn_concat (out,
+ (const char *)ptr_string,
+ length);
+ }
+ ptr_string += length;
+ }
+ }
+ break;
case 0x0F: /* ^O */
if (keep_colors)
weechat_string_dyn_concat (out, IRC_COLOR_RESET_STR, -1);
return weechat_string_dyn_free (out, 0);
}
-/*
- * Converts a RGB color to IRC color.
- *
- * Returns a IRC color number (between 0 and 15), -1 if error.
- */
-
-int
-irc_color_convert_rgb2irc (int rgb)
-{
- char str_color[64], *error, *info_color;
- long number;
-
- snprintf (str_color, sizeof (str_color),
- "%d,%d",
- rgb,
- IRC_COLOR_TERM2IRC_NUM_COLORS);
-
- info_color = weechat_info_get ("color_rgb2term", str_color);
- if (!info_color || !info_color[0])
- {
- if (info_color)
- free (info_color);
- return -1;
- }
-
- error = NULL;
- number = strtol (info_color, &error, 10);
- if (!error || error[0]
- || (number < 0) || (number >= IRC_COLOR_TERM2IRC_NUM_COLORS))
- {
- free (info_color);
- return -1;
- }
-
- free (info_color);
-
- return irc_color_term2irc[number];
-}
-
-/*
- * Converts a terminal color to IRC color.
- *
- * Returns a IRC color number (between 0 and 15), -1 if error.
- */
-
-int
-irc_color_convert_term2irc (int color)
-{
- char str_color[64], *error, *info_color;
- long number;
-
- snprintf (str_color, sizeof (str_color), "%d", color);
-
- info_color = weechat_info_get ("color_term2rgb", str_color);
- if (!info_color || !info_color[0])
- {
- if (info_color)
- free (info_color);
- return -1;
- }
-
- error = NULL;
- number = strtol (info_color, &error, 10);
- if (!error || error[0] || (number < 0) || (number > 0xFFFFFF))
- {
- free (info_color);
- return -1;
- }
-
- free (info_color);
-
- return irc_color_convert_rgb2irc (number);
-}
-
/*
* Replaces ANSI colors by IRC colors (or removes them).
*
#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_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_RESET_CHAR '\x0F' /* reset color/attributes */
#define IRC_COLOR_RESET_STR "\x0F" /* [0F]... */
#include "src/plugins/irc/irc-color.h"
#include "src/plugins/irc/irc-config.h"
-extern int irc_color_convert_rgb2irc (int rgb);
+extern int irc_color_convert_rgb2term (long rgb);
+extern int irc_color_convert_rgb2irc (long rgb);
extern int irc_color_convert_term2irc (int color);
}
#define STRING_IRC_COLOR_REMAPPED \
"test_" \
IRC_COLOR_COLOR_STR "03,02" "remapped"
+#define STRING_IRC_COLOR_FG_ORANGE \
+ "test_" IRC_COLOR_HEX_COLOR_STR "FF7F00" "orange" \
+ IRC_COLOR_HEX_COLOR_STR "_end"
+#define STRING_IRC_COLOR_FG_YELLOW_BG_DARKMAGENTA \
+ "test_" IRC_COLOR_HEX_COLOR_STR "FFFF00,8B008B" \
+ "yellow/darkmagenta" \
+ IRC_COLOR_HEX_COLOR_STR "_end"
/* tests on irc_color_encode(): command line -> IRC color */
#define STRING_USER_BOLD \
#define STRING_USER_ATTRS_AND_COLORS \
"test_" "\x02" "\x1F" "\x03" "08,02" "bold_underline_yellow/blue" \
"\x02" "\x1F" "_normal_yellow/blue"
+#define STRING_USER_FG_ORANGE \
+ "test_" "\x04" "FF7F00" "orange" "\x04" "_end"
+#define STRING_USER_FG_YELLOW_BG_DARKMAGENTA \
+ "test_" "\x04" "FFFF00,8B008B" "yellow/darkmagenta" "\x04" "_end"
/* tests on irc_color_decode_ansi(): ANSI color -> IRC color */
#define STRING_ANSI_RESET "test_\x1B[mreset"
{
};
+/*
+ * Tests functions:
+ * irc_color_convert_rgb2term
+ */
+
+TEST(IrcColor, ConvertRgb2Term)
+{
+ LONGS_EQUAL(-1, irc_color_convert_rgb2term (-1));
+ LONGS_EQUAL(0, irc_color_convert_rgb2term (0));
+ LONGS_EQUAL(9, irc_color_convert_rgb2term (0xFF0000)); /* red */
+ LONGS_EQUAL(10, irc_color_convert_rgb2term (0x00FF00)); /* green */
+ LONGS_EQUAL(12, irc_color_convert_rgb2term (0x0000FF)); /* blue */
+ LONGS_EQUAL(11, irc_color_convert_rgb2term (0xFFFF00)); /* yellow */
+ LONGS_EQUAL(208, irc_color_convert_rgb2term (0xFF7F00)); /* orange */
+ LONGS_EQUAL(90, irc_color_convert_rgb2term (0x8B008B)); /* dark magenta */
+}
+
+/*
+ * Tests functions:
+ * irc_color_convert_rgb2irc
+ */
+
+TEST(IrcColor, ConvertRgb2Irc)
+{
+ LONGS_EQUAL(1, irc_color_convert_rgb2irc (0x000000));
+ LONGS_EQUAL(1, irc_color_convert_rgb2irc (0x010203));
+ LONGS_EQUAL(4, irc_color_convert_rgb2irc (0xFF0033));
+ LONGS_EQUAL(15, irc_color_convert_rgb2irc (0xAABBCC));
+}
+
+/*
+ * Tests functions:
+ * irc_color_convert_term2irc
+ */
+
+TEST(IrcColor, ConvertTerm2Irc)
+{
+ LONGS_EQUAL(1, irc_color_convert_term2irc (0));
+ LONGS_EQUAL(15, irc_color_convert_term2irc (123));
+ LONGS_EQUAL(13, irc_color_convert_term2irc (200));
+ LONGS_EQUAL(0, irc_color_convert_term2irc (255));
+}
+
/*
* Tests functions:
* irc_color_decode
gui_color_get_custom ("|green"));
WEE_CHECK_DECODE(string, STRING_IRC_COLOR_REMAPPED, 1);
config_file_option_unset (irc_config_color_mirc_remap);
+
+ /* color: hex 0xFF7F00 (orange / 208) */
+ WEE_CHECK_DECODE("test_orange_end",
+ STRING_IRC_COLOR_FG_ORANGE, 0);
+ snprintf (string, sizeof (string),
+ "test_%sorange%s_end",
+ gui_color_get_custom ("|208"),
+ gui_color_get_custom ("resetcolor"));
+ WEE_CHECK_DECODE(string, STRING_IRC_COLOR_FG_ORANGE, 1);
+
+ /* color: hex 0xFFFF00 (yellow / 11) on 0x8B008B (dark magenta / 90) */
+ WEE_CHECK_DECODE("test_yellow/darkmagenta_end",
+ STRING_IRC_COLOR_FG_YELLOW_BG_DARKMAGENTA, 0);
+ snprintf (string, sizeof (string),
+ "test_%syellow/darkmagenta%s_end",
+ gui_color_get_custom ("|11,90"),
+ gui_color_get_custom ("resetcolor"));
+ WEE_CHECK_DECODE(string, STRING_IRC_COLOR_FG_YELLOW_BG_DARKMAGENTA, 1);
}
/*
IRC_COLOR_BOLD_STR,
IRC_COLOR_UNDERLINE_STR);
WEE_CHECK_ENCODE(string, STRING_USER_ATTRS_AND_COLORS, 1);
-}
-
-/*
- * Tests functions:
- * irc_color_convert_rgb2irc
- */
-
-TEST(IrcColor, ConvertRgb2Irc)
-{
- LONGS_EQUAL(1, irc_color_convert_rgb2irc (0x000000));
- LONGS_EQUAL(1, irc_color_convert_rgb2irc (0x010203));
- LONGS_EQUAL(4, irc_color_convert_rgb2irc (0xFF0033));
- LONGS_EQUAL(15, irc_color_convert_rgb2irc (0xAABBCC));
-}
-/*
- * Tests functions:
- * irc_color_convert_term2irc
- */
+ /* color: hex 0xFF7F00 (orange / 208) */
+ WEE_CHECK_ENCODE("test_orange_end", STRING_USER_FG_ORANGE, 0);
+ snprintf (string, sizeof (string),
+ "test_%sFF7F00orange%s_end",
+ IRC_COLOR_HEX_COLOR_STR,
+ IRC_COLOR_HEX_COLOR_STR);
+ WEE_CHECK_ENCODE(string, STRING_USER_FG_ORANGE, 1);
-TEST(IrcColor, ConvertTerm2Irc)
-{
- LONGS_EQUAL(1, irc_color_convert_term2irc (0));
- LONGS_EQUAL(15, irc_color_convert_term2irc (123));
- LONGS_EQUAL(13, irc_color_convert_term2irc (200));
- LONGS_EQUAL(0, irc_color_convert_term2irc (255));
+ /* color: hex 0xFFFF00 (yellow / 11) on 0x8B008B (dark magenta / 90) */
+ WEE_CHECK_ENCODE("test_yellow/darkmagenta_end",
+ STRING_USER_FG_YELLOW_BG_DARKMAGENTA, 0);
+ snprintf (string, sizeof (string),
+ "test_%sFFFF00,8B008Byellow/darkmagenta%s_end",
+ IRC_COLOR_HEX_COLOR_STR,
+ IRC_COLOR_HEX_COLOR_STR);
+ WEE_CHECK_ENCODE(string, STRING_USER_FG_YELLOW_BG_DARKMAGENTA, 1);
}
/*