]> jfr.im git - irc/weechat/weechat.git/commitdiff
irc: add support of RGB colors in messages (issue #2025)
authorSébastien Helleu <redacted>
Wed, 1 Nov 2023 12:21:06 +0000 (13:21 +0100)
committerSébastien Helleu <redacted>
Wed, 1 Nov 2023 12:21:06 +0000 (13:21 +0100)
This is made using standard color code '\x04' followed by text color (RGB as
hexadecimal) and optional background (RGB as hexadecimal).

13 files changed:
ChangeLog.adoc
ReleaseNotes.adoc
doc/de/weechat_user.de.adoc
doc/en/weechat_user.en.adoc
doc/fr/weechat_user.fr.adoc
doc/it/weechat_user.it.adoc
doc/ja/weechat_user.ja.adoc
doc/pl/weechat_user.pl.adoc
doc/sr/weechat_user.sr.adoc
src/gui/curses/gui-curses-key.c
src/plugins/irc/irc-color.c
src/plugins/irc/irc-color.h
tests/unit/plugins/irc/test-irc-color.cpp

index 9c9aae167b9cc766dbdfbb385c80a8aea2306386..d127b7c907e55376f6604361cf868b3add929d08 100644 (file)
@@ -18,6 +18,7 @@ New features::
   * 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)
index 3acd0fddec5087eda4581fb23666724011f653a6..69f27a31375937d4343b43331f31b3750c54d857 100644 (file)
@@ -14,6 +14,18 @@ For a complete list of changes, please look at ChangeLog.
 [[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
 
index 10e11fd6efafe91fd0eb4443f6f5197780eb5b58..a30396ac1b08aace09459a30423a9b53e3b3b836 100644 (file)
@@ -1016,6 +1016,13 @@ Zeichen, genutzt werden:
 | 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).
@@ -1023,8 +1030,9 @@ Zeichen, genutzt werden:
 |===
 
 [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]:
 
@@ -1587,6 +1595,8 @@ Sie können mit dem Befehl <<command_weechat_key,/key>> geändert und neue hinzu
 | 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+`
index 61e0d69fe125bb6b82740fd7ade6052695d1809d..41dc69b737a7535a76f9509f7cab4c7699571757 100644 (file)
@@ -1007,6 +1007,11 @@ follow (press kbd:[Ctrl+c] then following letter, with optional value):
 | 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).
@@ -1014,8 +1019,8 @@ follow (press kbd:[Ctrl+c] then following letter, with optional value):
 |===
 
 [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:
 
@@ -1574,6 +1579,7 @@ They can be changed and new ones can be added with the <<command_weechat_key,/ke
 | 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+`
index f741e18e3f9db2cda57117a851ac958779c1a99f..65b386b865e22b688eb1dbf20e54929aa6250b06 100644 (file)
@@ -1022,6 +1022,11 @@ suit et éventuellement une valeur) :
 | 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).
@@ -1029,8 +1034,8 @@ suit et éventuellement une valeur) :
 |===
 
 [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 :
 
@@ -1609,6 +1614,7 @@ Ils peuvent être modifiés et de nouveaux peuvent être ajoutés avec la comman
 | 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+`
index 9e8eb09e5d94bcc6e9a61278da36064f5f61ea60..5a0b426b5a9769fe4a2055c60a3e938928f855b8 100644 (file)
@@ -1106,6 +1106,13 @@ opzionale):
   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).
@@ -1113,8 +1120,9 @@ opzionale):
 |===
 
 [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:
 
@@ -1720,6 +1728,8 @@ They can be changed and new ones can be added with the <<command_weechat_key,/ke
 | 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+`
index c8f6b814995ff43e86e72e9d3c9fc4bc42032fdd..d7276bc3a2e875edaf80d2025d303b72daa23756 100644 (file)
@@ -1077,6 +1077,13 @@ IRC 等のプラグインでは、以下の色コードと属性を利用でき
 | 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]  | テキストを反転 (テキスト表示色と背景色の入れ替え)
@@ -1084,8 +1091,9 @@ IRC 等のプラグインでは、以下の色コードと属性を利用でき
 |===
 
 [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] 用の色コード:
 
@@ -1681,6 +1689,8 @@ They can be changed and new ones can be added with the <<command_weechat_key,/ke
 | キー                   | 説明 | コマンド
 | 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+`
index 1354d718275594a10ef80ebc3cf8ef66b5e78afb..47b85a24605a1420c7f56ef49e71072c8cbbf60f 100644 (file)
@@ -1016,6 +1016,13 @@ Dla niektórych wtyczek jak IRC, można użyć kolorów i atrybutów w następuj
 | 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)
@@ -1023,8 +1030,9 @@ Dla niektórych wtyczek jak IRC, można użyć kolorów i atrybutów w następuj
 |===
 
 [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]:
 
@@ -1590,6 +1598,8 @@ Można je zmienić oraz dodać nowe za pomocą komendy <<command_weechat_key,/ke
 | 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+`
index cff381ff30fa9134f5f294b62e6e242db0ea2a52..1acb2ae4e22ab6548bb2d6ecbf7b6f7c50f45193 100644 (file)
@@ -950,6 +950,13 @@ WeeChat командна линија (на дну прозора) вам омо
 | 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]  | Обрнути видео (боје текста и позадине се замењују једна са другом).
@@ -957,7 +964,9 @@ WeeChat командна линија (на дну прозора) вам омо
 |===
 
 [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] су:
 
@@ -1494,7 +1503,9 @@ WeeChat нуди доста подразумеваних тастерских п
 |===
 | Тастер                | Опис | Команда
 | 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+`
index 44444f3a8b0377890e7d97f439f6633f68b0dff3..cb5279ff06edb4a49db1cbe1b7d8d04d69c5c095 100644 (file)
@@ -140,6 +140,7 @@ gui_key_default_bindings (int context, int create_option)
         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");
index 012cfa5cd8f32ee2f4be0c8711ae3b74c0d0d555..b110fcfbce85e011f7d4e04e2d957d781278697b 100644 (file)
@@ -83,6 +83,121 @@ char irc_color_term2irc[IRC_COLOR_TERM2IRC_NUM_COLORS] =
 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.
  *
@@ -95,11 +210,12 @@ regex_t *irc_color_regex_ansi = NULL;
 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;
@@ -211,19 +327,21 @@ irc_color_decode (const char *string, int keep_colors)
                         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);
@@ -253,6 +371,94 @@ irc_color_decode (const char *string, int keep_colors)
                     }
                 }
                 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
@@ -364,6 +570,53 @@ irc_color_encode (const char *string, int keep_colors)
                     }
                 }
                 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);
@@ -398,80 +651,6 @@ irc_color_encode (const char *string, int keep_colors)
     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).
  *
index 6e576c050ec243333bde582aeb382a30d5427eee..9f937c85fb76baff15ebcdc3ade1069411e0f52c 100644 (file)
 #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]...                       */
 
index 3ed9773643778052e449161704330ab350fa94ee..e6065fdcce501bde34a22a2da4b67d0a69c3770c 100644 (file)
@@ -31,7 +31,8 @@ extern "C"
 #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);
 }
 
@@ -70,6 +71,13 @@ 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                                                \
@@ -92,6 +100,10 @@ extern int irc_color_convert_term2irc (int color);
 #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"
@@ -144,6 +156,49 @@ TEST_GROUP(IrcColor)
 {
 };
 
+/*
+ * 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
@@ -269,6 +324,24 @@ TEST(IrcColor, 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);
 }
 
 /*
@@ -375,32 +448,23 @@ TEST(IrcColor, Encode)
               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);
 }
 
 /*