diff --git a/src/core/wee-config.c b/src/core/wee-config.c index 7b24f68fc..7bfd364f5 100644 --- a/src/core/wee-config.c +++ b/src/core/wee-config.c @@ -157,6 +157,7 @@ struct t_config_option *config_look_hotlist_suffix; struct t_config_option *config_look_hotlist_unique_numbers; struct t_config_option *config_look_hotlist_update_on_buffer_switch; struct t_config_option *config_look_input_cursor_scroll; +struct t_config_option *config_look_input_multiline_lead_linebreak; struct t_config_option *config_look_input_share; struct t_config_option *config_look_input_share_overwrite; struct t_config_option *config_look_input_undo_max; @@ -3369,6 +3370,13 @@ config_weechat_init_options () "to display end of line"), NULL, 0, 100, "20", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + config_look_input_multiline_lead_linebreak = config_file_new_option ( + weechat_config_file, weechat_config_section_look, + "input_multiline_lead_linebreak", "boolean", + N_("start the input text on a new line when the input contains " + "multiple lines, so that the start of the lines align"), + NULL, 0, 0, "on", NULL, 0, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); config_look_input_share = config_file_new_option ( weechat_config_file, weechat_config_section_look, "input_share", "integer", diff --git a/src/core/wee-config.h b/src/core/wee-config.h index 7746daa79..f1963426b 100644 --- a/src/core/wee-config.h +++ b/src/core/wee-config.h @@ -209,6 +209,7 @@ extern struct t_config_option *config_look_hotlist_suffix; extern struct t_config_option *config_look_hotlist_unique_numbers; extern struct t_config_option *config_look_hotlist_update_on_buffer_switch; extern struct t_config_option *config_look_input_cursor_scroll; +extern struct t_config_option *config_look_input_multiline_lead_linebreak; extern struct t_config_option *config_look_input_share; extern struct t_config_option *config_look_input_share_overwrite; extern struct t_config_option *config_look_input_undo_max; diff --git a/src/gui/gui-bar-item.c b/src/gui/gui-bar-item.c index d8778937e..1391d6ece 100644 --- a/src/gui/gui-bar-item.c +++ b/src/gui/gui-bar-item.c @@ -836,9 +836,10 @@ gui_bar_item_input_text_cb (const void *pointer, void *data, struct t_hashtable *extra_info) { char *ptr_input, *ptr_input2, str_buffer[128], str_start_input[16]; - char str_cursor[16], *buf, str_key_debug[1024]; + char str_cursor[16], *buf, str_key_debug[1024], *str_lead_linebreak; const char *pos_cursor; - int length, length_cursor, length_start_input, buf_pos; + int length, length_cursor, length_start_input, length_lead_linebreak; + int buf_pos, is_multiline; /* make C compiler happy */ (void) pointer; @@ -937,14 +938,34 @@ gui_bar_item_input_text_cb (const void *pointer, void *data, ptr_input = ptr_input2; } + /* + * transform '\n' to '\r' so the newlines are displayed as real new lines + * instead of spaces + */ + is_multiline = 0; + ptr_input2 = ptr_input; + while (ptr_input2 && ptr_input2[0]) + { + if (ptr_input2[0] == '\n') + { + ptr_input2[0] = '\r'; + is_multiline = 1; + } + ptr_input2 = (char *)utf8_next_char (ptr_input2); + } + + str_lead_linebreak = (is_multiline && + CONFIG_BOOLEAN(config_look_input_multiline_lead_linebreak)) ? "\r" : ""; + length_lead_linebreak = strlen (str_lead_linebreak); + /* insert "start input" at beginning of string */ if (ptr_input) { - length = strlen (ptr_input) + length_start_input + 1; + length = strlen (ptr_input) + length_start_input + length_lead_linebreak + 1; buf = malloc (length); if (buf) { - snprintf (buf, length, "%s%s", str_start_input, ptr_input); + snprintf (buf, length, "%s%s%s", str_start_input, str_lead_linebreak, ptr_input); free (ptr_input); ptr_input = buf; } @@ -960,18 +981,6 @@ gui_bar_item_input_text_cb (const void *pointer, void *data, } } - /* - * transform '\n' to '\r' so the newlines are displayed as real new lines - * instead of spaces - */ - ptr_input2 = ptr_input; - while (ptr_input2 && ptr_input2[0]) - { - if (ptr_input2[0] == '\n') - ptr_input2[0] = '\r'; - ptr_input2 = (char *)utf8_next_char (ptr_input2); - } - return ptr_input; }