diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2022-11-21 20:45:25 +0100 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2022-11-21 20:45:41 +0100 |
commit | baab9cc7c52e011a10cf5b1d97d6707e6e067597 (patch) | |
tree | a2dcce2df3099f5e26d63f7dab2ade1491efa76d /src | |
parent | a8639969c5d0c8ecc950332a18480b2cb499173d (diff) | |
download | weechat-baab9cc7c52e011a10cf5b1d97d6707e6e067597.zip |
core: add option `unicode` in command `/debug`
Diffstat (limited to 'src')
-rw-r--r-- | src/core/wee-command.c | 29 | ||||
-rw-r--r-- | src/core/wee-debug.c | 86 | ||||
-rw-r--r-- | src/core/wee-debug.h | 1 |
3 files changed, 113 insertions, 3 deletions
diff --git a/src/core/wee-command.c b/src/core/wee-command.c index e7e3ddf64..5fb9201bb 100644 --- a/src/core/wee-command.c +++ b/src/core/wee-command.c @@ -1833,6 +1833,7 @@ COMMAND_CALLBACK(debug) struct t_config_option *ptr_option; struct t_weechat_plugin *ptr_plugin; struct timeval time_start, time_end; + char *result; int debug; /* make C compiler happy */ @@ -2025,6 +2026,18 @@ COMMAND_CALLBACK(debug) return WEECHAT_RC_OK; } + if (string_strcasecmp (argv[1], "unicode") == 0) + { + COMMAND_MIN_ARGS(3, "unicode"); + result = eval_expression (argv_eol[2], NULL, NULL, NULL); + if (result) + { + debug_unicode_string (result); + free (result); + } + return WEECHAT_RC_OK; + } + if (string_strcasecmp (argv[1], "windows") == 0) { debug_windows_tree (); @@ -7653,7 +7666,8 @@ command_init () "term|windows" " || mouse|cursor [verbose]" " || hdata [free]" - " || time <command>"), + " || time <command>" + " || unicode <string>"), N_(" list: list plugins with debug levels\n" " set: set debug level for plugin\n" " plugin: name of plugin (\"core\" for WeeChat core)\n" @@ -7677,7 +7691,15 @@ command_init () " term: display infos about terminal\n" " windows: display windows tree\n" " time: measure time to execute a command or to send text to " - "the current buffer"), + "the current buffer\n" + " unicode: display information about unicode chars in string " + "(evaluated, see /help eval)\n" + "\n" + "Examples:\n" + " /debug set irc 1\n" + " /debug mouse verbose\n" + " /debug time /filter toggle\n" + " /debug unicode ${chars:${\\u26C0}-${\\u26CF}}"), "list" " || set %(plugins_names)|" PLUGIN_CORE " || dump %(plugins_names)|" PLUGIN_CORE @@ -7695,7 +7717,8 @@ command_init () " || tags" " || term" " || windows" - " || time %(commands:/)", + " || time %(commands:/)" + " || unicode", &command_debug, NULL, NULL); hook_command ( NULL, "eval", diff --git a/src/core/wee-debug.c b/src/core/wee-debug.c index 6a5038194..6c4145cdd 100644 --- a/src/core/wee-debug.c +++ b/src/core/wee-debug.c @@ -48,11 +48,13 @@ #include "wee-log.h" #include "wee-proxy.h" #include "wee-string.h" +#include "wee-utf8.h" #include "wee-util.h" #include "../gui/gui-bar.h" #include "../gui/gui-bar-item.h" #include "../gui/gui-buffer.h" #include "../gui/gui-chat.h" +#include "../gui/gui-color.h" #include "../gui/gui-completion.h" #include "../gui/gui-filter.h" #include "../gui/gui-hotlist.h" @@ -760,6 +762,90 @@ debug_display_time_elapsed (struct timeval *time1, struct timeval *time2, } /* + * Display information about a unicode codepoint. + */ + +void +debug_unicode_char (unsigned int codepoint) +{ + char utf8_char[5], hexa[64], *ptr_hexa; + wchar_t wstring[4+2]; + int i, size, length_wcswidth; + + utf8_int_string (codepoint, utf8_char); + size = strlen (utf8_char); + + hexa[0] = '\0'; + ptr_hexa = hexa; + for (i = 0; i < size; i++) + { + ptr_hexa[0] = '0'; + ptr_hexa[1] = 'x'; + ptr_hexa += 2; + string_base16_encode (utf8_char + i, 1, ptr_hexa); + ptr_hexa += 2; + if (i < size - 1) + { + ptr_hexa[0] = ' '; + ptr_hexa++; + } + } + ptr_hexa[0] = '\0'; + + length_wcswidth = -1; + if (mbstowcs (wstring, utf8_char, 1) != (size_t)(-1)) + length_wcswidth = wcswidth (wstring, 1); + + gui_chat_printf (NULL, + "\t \"%s\" (%u, U+%04X, %s): %d %s/%s %d, %d %s/%s %d, %d, %d", + utf8_char, + codepoint, + codepoint, + hexa, + strlen (utf8_char), + GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS), + GUI_COLOR(GUI_COLOR_CHAT), + utf8_strlen (utf8_char), + gui_chat_strlen (utf8_char), + GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS), + GUI_COLOR(GUI_COLOR_CHAT), + length_wcswidth, + utf8_strlen_screen (utf8_char), + gui_chat_strlen_screen (utf8_char)); +} + +/* + * Display information about all unicode chars of a string. + */ + +void +debug_unicode_string (const char *string) +{ + const char *ptr_string; + if (!string || !string[0]) + return; + + gui_chat_printf (NULL, ""); + gui_chat_printf (NULL, + _("Unicode: \"char\" " + "(codepoint, hex codepoint, UTF-8 sequence): " + "strlen %s/%s " + "utf8_strlen, gui_chat_strlen %s/%s " + "wcswidth, utf8_strlen_screen, gui_chat_strlen_screen:"), + GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS), + GUI_COLOR(GUI_COLOR_CHAT), + GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS), + GUI_COLOR(GUI_COLOR_CHAT)); + + ptr_string = string; + while (ptr_string && ptr_string[0]) + { + debug_unicode_char (utf8_char_int (ptr_string)); + ptr_string = utf8_next_char (ptr_string); + } +} + +/* * Initializes debug. */ diff --git a/src/core/wee-debug.h b/src/core/wee-debug.h index dbf2675a8..16351482a 100644 --- a/src/core/wee-debug.h +++ b/src/core/wee-debug.h @@ -36,6 +36,7 @@ extern void debug_display_time_elapsed (struct timeval *time1, struct timeval *time2, const char *message, int display); +extern void debug_unicode_string (const char *string); extern void debug_init (); extern void debug_end (); |