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

core: Add an option to start multiline input text on a new line

This does the same as the lead_linebreak option in multiline.pl. That
is, when the input contains more than one line, the first line will be
displayed beneath the previous items in the bar. This is practical
because all the lines in the input will be aligned.

Related to #1498
This commit is contained in:
Trygve Aaberge
2020-05-13 02:30:32 +02:00
committed by Sébastien Helleu
parent af493ac976
commit c63321bb7a
3 changed files with 34 additions and 16 deletions
+8
View File
@@ -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",
+1
View File
@@ -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;
+25 -16
View File
@@ -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;
}