1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-07 02:03:13 +02:00

core: add option whitespace in command /debug (closes #947)

New options are added to configure the chars displayed for spaces and
tabulations:

- weechat.look.whitespace_char: char for spaces
- weechat.look.tab_whitespace_char: first char for tabulations
This commit is contained in:
Sébastien Helleu
2025-02-15 20:03:57 +01:00
parent 8e9692809d
commit 3c9eb6dcac
22 changed files with 739 additions and 365 deletions
+14 -2
View File
@@ -2291,6 +2291,13 @@ COMMAND_CALLBACK(debug)
return WEECHAT_RC_OK;
}
if (string_strcmp (argv[1], "whitespace") == 0)
{
gui_chat_whitespace_mode ^= 1;
gui_window_ask_refresh (1);
return WEECHAT_RC_OK;
}
COMMAND_ERROR;
}
@@ -8620,7 +8627,8 @@ command_init ()
" || mouse|cursor [verbose]"
" || hdata [free]"
" || time <command>"
" || unicode <string>"),
" || unicode <string>"
" || whitespace"),
CMD_ARGS_DESC(
N_("raw[list]: list plugins with debug levels"),
N_("raw[set]: set debug level for plugin"),
@@ -8662,6 +8670,9 @@ command_init ()
"the current buffer"),
N_("raw[unicode]: display information about string and unicode chars "
"(evaluated, see /help eval)"),
N_("raw[whitespace]: toggle whitespace mode: make spaces and tabulations "
"visible in buffers and bars (see options weechat.look.whitespace_char "
"and weechat.look.tab_whitespace_char)"),
"",
N_("Examples:"),
AI(" /debug set irc 1"),
@@ -8690,7 +8701,8 @@ command_init ()
" || url"
" || windows"
" || time %(commands:/)"
" || unicode",
" || unicode"
" || whitespace",
&command_debug, NULL, NULL);
hook_command (
NULL, "eval",
+67 -7
View File
@@ -217,8 +217,10 @@ struct t_config_option *config_look_scroll_page_percent = NULL;
struct t_config_option *config_look_search_text_not_found_alert = NULL;
struct t_config_option *config_look_separator_horizontal = NULL;
struct t_config_option *config_look_separator_vertical = NULL;
struct t_config_option *config_look_tab_whitespace_char = NULL;
struct t_config_option *config_look_tab_width = NULL;
struct t_config_option *config_look_time_format = NULL;
struct t_config_option *config_look_whitespace_char = NULL;
struct t_config_option *config_look_window_auto_zoom = NULL;
struct t_config_option *config_look_window_separator_horizontal = NULL;
struct t_config_option *config_look_window_separator_vertical = NULL;
@@ -361,6 +363,7 @@ int config_num_highlight_tags = 0;
char **config_plugin_extensions = NULL;
int config_num_plugin_extensions = 0;
char config_tab_spaces[TAB_MAX_WIDTH + 1];
char config_tab_spaces_whitespace[(TAB_MAX_WIDTH * 4) + 1];
struct t_config_look_word_char_item *config_word_chars_highlight = NULL;
int config_word_chars_highlight_count = 0;
struct t_config_look_word_char_item *config_word_chars_input = NULL;
@@ -1311,20 +1314,54 @@ config_check_separator (const void *pointer, void *data,
}
/*
* Callback for changes on option "weechat.look.tab_width".
* Checks options "weechat.look.whitespace_char" and
* "weechat.look.tab_whitespace_char".
*/
void
config_change_tab_width (const void *pointer, void *data,
struct t_config_option *option)
int
config_check_whitespace_char (const void *pointer, void *data,
struct t_config_option *option,
const char *value)
{
/* make C compiler happy */
(void) pointer;
(void) data;
(void) option;
memset (config_tab_spaces, ' ', CONFIG_INTEGER(config_look_tab_width));
config_tab_spaces[CONFIG_INTEGER(config_look_tab_width)] = '\0';
return (utf8_strlen_screen (value) == 1) ? 1 : 0;
}
/*
* Callback for changes on options "weechat.look.tab_width" and
* "weechat.look.tab_whitespace_char".
*/
void
config_change_tab (const void *pointer, void *data,
struct t_config_option *option)
{
int tab_width, i;
/* make C compiler happy */
(void) pointer;
(void) data;
(void) option;
tab_width = CONFIG_INTEGER(config_look_tab_width);
/* build a string with spaces that replace Tab char */
memset (config_tab_spaces, ' ', tab_width);
config_tab_spaces[tab_width] = '\0';
/* replaces spaces in whitespace mode */
config_tab_spaces_whitespace[0] = '\0';
strcat (config_tab_spaces_whitespace,
CONFIG_STRING(config_look_tab_whitespace_char));
for (i = 1; i < tab_width; i++)
{
strcat (config_tab_spaces_whitespace,
CONFIG_STRING(config_look_whitespace_char));
}
gui_window_ask_refresh (1);
}
@@ -4336,13 +4373,24 @@ config_weechat_init_options ()
&config_check_separator, NULL, NULL,
&config_change_buffers, NULL, NULL,
NULL, NULL, NULL);
config_look_tab_whitespace_char = config_file_new_option (
weechat_config_file, weechat_config_section_look,
"tab_whitespace_char", "string",
N_("first char to display for tabulations when whitespace mode is "
"enabled with command `/debug whitespace`; width on screen must "
"be exactly one char; subsequent chars are set by option "
"weechat.look.whitespace_char"),
NULL, 0, 0, "", NULL, 0,
&config_check_whitespace_char, NULL, NULL,
&config_change_tab, NULL, NULL,
NULL, NULL, NULL);
config_look_tab_width = config_file_new_option (
weechat_config_file, weechat_config_section_look,
"tab_width", "integer",
N_("number of spaces used to display tabs in messages"),
NULL, 1, TAB_MAX_WIDTH, "1", NULL, 0,
NULL, NULL, NULL,
&config_change_tab_width, NULL, NULL,
&config_change_tab, NULL, NULL,
NULL, NULL, NULL);
config_look_time_format = config_file_new_option (
weechat_config_file, weechat_config_section_look,
@@ -4351,6 +4399,16 @@ config_weechat_init_options ()
"messages (see man strftime for date/time specifiers)"),
NULL, 0, 0, "%a, %d %b %Y %T", NULL, 0,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
config_look_whitespace_char = config_file_new_option (
weechat_config_file, weechat_config_section_look,
"whitespace_char", "string",
N_("char to display for spaces when whitespace mode is enabled with "
"command `/debug whitespace`; width on screen must be exactly "
"one char; see also option weechat.look.tab_whitespace_char"),
NULL, 0, 0, "·", NULL, 0,
&config_check_whitespace_char, NULL, NULL,
&config_change_buffers, NULL, NULL,
NULL, NULL, NULL);
config_look_window_auto_zoom = config_file_new_option (
weechat_config_file, weechat_config_section_look,
"window_auto_zoom", "boolean",
@@ -5477,6 +5535,8 @@ config_weechat_init ()
time_t seconds;
snprintf (config_tab_spaces, sizeof (config_tab_spaces), " ");
snprintf (config_tab_spaces_whitespace, sizeof (config_tab_spaces_whitespace),
"\u2192");
rc = config_weechat_init_options ();
+3
View File
@@ -273,8 +273,10 @@ extern struct t_config_option *config_look_scroll_page_percent;
extern struct t_config_option *config_look_search_text_not_found_alert;
extern struct t_config_option *config_look_separator_horizontal;
extern struct t_config_option *config_look_separator_vertical;
extern struct t_config_option *config_look_tab_whitespace_char;
extern struct t_config_option *config_look_tab_width;
extern struct t_config_option *config_look_time_format;
extern struct t_config_option *config_look_whitespace_char;
extern struct t_config_option *config_look_window_auto_zoom;
extern struct t_config_option *config_look_window_separator_horizontal;
extern struct t_config_option *config_look_window_separator_vertical;
@@ -397,6 +399,7 @@ extern int config_num_highlight_tags;
extern char **config_plugin_extensions;
extern int config_num_plugin_extensions;
extern char config_tab_spaces[];
extern char config_tab_spaces_whitespace[];
extern struct t_config_look_word_char_item *config_word_chars_highlight;
extern int config_word_chars_highlight_count;
extern struct t_config_look_word_char_item *config_word_chars_input;
+8 -1
View File
@@ -351,7 +351,14 @@ gui_bar_window_print_string (struct t_gui_bar_window *bar_window,
if (utf_char[0] == '\t')
{
/* expand tabulation with spaces */
ptr_char = config_tab_spaces;
ptr_char = (gui_chat_whitespace_mode) ?
config_tab_spaces_whitespace : config_tab_spaces;
}
else if ((utf_char[0] == ' ') && gui_chat_whitespace_mode)
{
/* replace space in whitespace mode */
snprintf (utf_char, sizeof (utf_char),
"%s", CONFIG_STRING(config_look_whitespace_char));
}
else if (((unsigned char)utf_char[0]) < 32)
{
+8 -1
View File
@@ -411,7 +411,14 @@ gui_chat_display_word_raw (struct t_gui_window *window, struct t_gui_line *line,
if (utf_char[0] == '\t')
{
/* expand tabulation with spaces */
ptr_char = config_tab_spaces;
ptr_char = (gui_chat_whitespace_mode) ?
config_tab_spaces_whitespace : config_tab_spaces;
}
else if ((utf_char[0] == ' ') && gui_chat_whitespace_mode)
{
/* replace space in whitespace mode */
snprintf (utf_char, sizeof (utf_char),
"%s", CONFIG_STRING(config_look_whitespace_char));
}
else if (((unsigned char)utf_char[0]) < 32)
{
+1
View File
@@ -60,6 +60,7 @@ struct t_gui_buffer *gui_chat_mute_buffer = NULL; /* mute buffer */
int gui_chat_display_tags = 0; /* display tags? */
char **gui_chat_lines_waiting_buffer = NULL; /* lines waiting for core */
/* buffer */
int gui_chat_whitespace_mode = 0; /* make whitespaces visible */
/* command /pipe */
int gui_chat_pipe = 0; /* pipe enabled */
+1
View File
@@ -80,6 +80,7 @@ extern char gui_chat_prefix_empty[];
extern int gui_chat_time_length;
extern int gui_chat_mute;
extern struct t_gui_buffer *gui_chat_mute_buffer;
extern int gui_chat_whitespace_mode;
extern int gui_chat_pipe;
extern char *gui_chat_pipe_command;
extern struct t_gui_buffer *gui_chat_pipe_buffer;