mirror of
https://github.com/weechat/weechat.git
synced 2026-07-09 03:03:12 +02:00
Add hook type "command_run", add new function "string_remove_color" in plugin API (task #9089)
This commit is contained in:
@@ -170,161 +170,168 @@ gui_bar_window_print_string (struct t_gui_bar_window *bar_window,
|
||||
|
||||
while (string && string[0])
|
||||
{
|
||||
if (string[0] == GUI_COLOR_COLOR_CHAR)
|
||||
switch (string[0])
|
||||
{
|
||||
string++;
|
||||
switch (string[0])
|
||||
{
|
||||
case GUI_COLOR_FG_CHAR: /* fg color */
|
||||
if (string[1] && string[2])
|
||||
{
|
||||
str_fg[0] = string[1];
|
||||
str_fg[1] = string[2];
|
||||
str_fg[2] = '\0';
|
||||
sscanf (str_fg, "%d", &fg);
|
||||
gui_window_set_custom_color_fg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
|
||||
fg);
|
||||
string += 3;
|
||||
}
|
||||
break;
|
||||
case GUI_COLOR_BG_CHAR: /* bg color */
|
||||
if (string[1] && string[2])
|
||||
{
|
||||
str_bg[0] = string[1];
|
||||
str_bg[1] = string[2];
|
||||
str_bg[2] = '\0';
|
||||
sscanf (str_bg, "%d", &bg);
|
||||
gui_window_set_custom_color_bg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
|
||||
bg);
|
||||
string += 3;
|
||||
}
|
||||
break;
|
||||
case GUI_COLOR_FG_BG_CHAR: /* fg + bg color */
|
||||
if (string[1] && string[2] && (string[3] == ',')
|
||||
&& string[4] && string[5])
|
||||
{
|
||||
str_fg[0] = string[1];
|
||||
str_fg[1] = string[2];
|
||||
str_fg[2] = '\0';
|
||||
str_bg[0] = string[4];
|
||||
str_bg[1] = string[5];
|
||||
str_bg[2] = '\0';
|
||||
sscanf (str_fg, "%d", &fg);
|
||||
sscanf (str_bg, "%d", &bg);
|
||||
gui_window_set_custom_color_fg_bg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
|
||||
fg, bg);
|
||||
string += 6;
|
||||
}
|
||||
break;
|
||||
case GUI_COLOR_BAR_CHAR: /* bar color */
|
||||
switch (string[1])
|
||||
{
|
||||
case GUI_COLOR_BAR_FG_CHAR:
|
||||
/* bar foreground */
|
||||
gui_window_set_custom_color_fg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
|
||||
CONFIG_INTEGER(bar_window->bar->options[GUI_BAR_OPTION_COLOR_FG]));
|
||||
string += 2;
|
||||
break;
|
||||
case GUI_COLOR_BAR_DELIM_CHAR:
|
||||
/* bar delimiter */
|
||||
gui_window_set_custom_color_fg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
|
||||
CONFIG_INTEGER(bar_window->bar->options[GUI_BAR_OPTION_COLOR_DELIM]));
|
||||
string += 2;
|
||||
break;
|
||||
case GUI_COLOR_BAR_BG_CHAR:
|
||||
/* bar background */
|
||||
gui_window_set_custom_color_bg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
|
||||
CONFIG_INTEGER(bar_window->bar->options[GUI_BAR_OPTION_COLOR_BG]));
|
||||
string += 2;
|
||||
break;
|
||||
case GUI_COLOR_BAR_START_INPUT_CHAR:
|
||||
string += 2;
|
||||
break;
|
||||
case GUI_COLOR_BAR_MOVE_CURSOR_CHAR:
|
||||
/* move cursor to current position on screen */
|
||||
getyx (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
|
||||
bar_window->cursor_y, bar_window->cursor_x);
|
||||
bar_window->cursor_x += bar_window->x;
|
||||
bar_window->cursor_y += bar_window->y;
|
||||
string += 2;
|
||||
break;
|
||||
default:
|
||||
string++;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (isdigit (string[0]) && isdigit (string[1]))
|
||||
{
|
||||
str_fg[0] = string[0];
|
||||
str_fg[1] = string[1];
|
||||
str_fg[2] = '\0';
|
||||
sscanf (str_fg, "%d", &weechat_color);
|
||||
gui_window_set_weechat_color (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
|
||||
weechat_color);
|
||||
string += 2;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
next_char = utf8_next_char (string);
|
||||
if (!next_char)
|
||||
break;
|
||||
|
||||
memcpy (utf_char, string, next_char - string);
|
||||
utf_char[next_char - string] = '\0';
|
||||
|
||||
if ((((unsigned char)utf_char[0]) < 32) && (!utf_char[1]))
|
||||
{
|
||||
low_char = 1;
|
||||
snprintf (utf_char, sizeof (utf_char), "%c",
|
||||
'A' + ((unsigned char)utf_char[0]) - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
low_char = 0;
|
||||
if (!gui_window_utf_char_valid (utf_char))
|
||||
snprintf (utf_char, sizeof (utf_char), ".");
|
||||
}
|
||||
|
||||
size_on_screen = utf8_char_size_screen (utf_char);
|
||||
if (size_on_screen > 0)
|
||||
{
|
||||
if (x_with_hidden < bar_window->scroll_x)
|
||||
case GUI_COLOR_COLOR_CHAR:
|
||||
string++;
|
||||
switch (string[0])
|
||||
{
|
||||
/* hidden char (before scroll_x value) */
|
||||
x_with_hidden++;
|
||||
case GUI_COLOR_FG_CHAR: /* fg color */
|
||||
if (string[1] && string[2])
|
||||
{
|
||||
str_fg[0] = string[1];
|
||||
str_fg[1] = string[2];
|
||||
str_fg[2] = '\0';
|
||||
sscanf (str_fg, "%d", &fg);
|
||||
gui_window_set_custom_color_fg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
|
||||
fg);
|
||||
string += 3;
|
||||
}
|
||||
break;
|
||||
case GUI_COLOR_BG_CHAR: /* bg color */
|
||||
if (string[1] && string[2])
|
||||
{
|
||||
str_bg[0] = string[1];
|
||||
str_bg[1] = string[2];
|
||||
str_bg[2] = '\0';
|
||||
sscanf (str_bg, "%d", &bg);
|
||||
gui_window_set_custom_color_bg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
|
||||
bg);
|
||||
string += 3;
|
||||
}
|
||||
break;
|
||||
case GUI_COLOR_FG_BG_CHAR: /* fg + bg color */
|
||||
if (string[1] && string[2] && (string[3] == ',')
|
||||
&& string[4] && string[5])
|
||||
{
|
||||
str_fg[0] = string[1];
|
||||
str_fg[1] = string[2];
|
||||
str_fg[2] = '\0';
|
||||
str_bg[0] = string[4];
|
||||
str_bg[1] = string[5];
|
||||
str_bg[2] = '\0';
|
||||
sscanf (str_fg, "%d", &fg);
|
||||
sscanf (str_bg, "%d", &bg);
|
||||
gui_window_set_custom_color_fg_bg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
|
||||
fg, bg);
|
||||
string += 6;
|
||||
}
|
||||
break;
|
||||
case GUI_COLOR_BAR_CHAR: /* bar color */
|
||||
switch (string[1])
|
||||
{
|
||||
case GUI_COLOR_BAR_FG_CHAR:
|
||||
/* bar foreground */
|
||||
gui_window_set_custom_color_fg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
|
||||
CONFIG_INTEGER(bar_window->bar->options[GUI_BAR_OPTION_COLOR_FG]));
|
||||
string += 2;
|
||||
break;
|
||||
case GUI_COLOR_BAR_DELIM_CHAR:
|
||||
/* bar delimiter */
|
||||
gui_window_set_custom_color_fg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
|
||||
CONFIG_INTEGER(bar_window->bar->options[GUI_BAR_OPTION_COLOR_DELIM]));
|
||||
string += 2;
|
||||
break;
|
||||
case GUI_COLOR_BAR_BG_CHAR:
|
||||
/* bar background */
|
||||
gui_window_set_custom_color_bg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
|
||||
CONFIG_INTEGER(bar_window->bar->options[GUI_BAR_OPTION_COLOR_BG]));
|
||||
string += 2;
|
||||
break;
|
||||
case GUI_COLOR_BAR_START_INPUT_CHAR:
|
||||
string += 2;
|
||||
break;
|
||||
case GUI_COLOR_BAR_MOVE_CURSOR_CHAR:
|
||||
/* move cursor to current position on screen */
|
||||
getyx (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
|
||||
bar_window->cursor_y, bar_window->cursor_x);
|
||||
bar_window->cursor_x += bar_window->x;
|
||||
bar_window->cursor_y += bar_window->y;
|
||||
string += 2;
|
||||
break;
|
||||
default:
|
||||
string++;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (isdigit (string[0]) && isdigit (string[1]))
|
||||
{
|
||||
str_fg[0] = string[0];
|
||||
str_fg[1] = string[1];
|
||||
str_fg[2] = '\0';
|
||||
sscanf (str_fg, "%d", &weechat_color);
|
||||
gui_window_set_weechat_color (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
|
||||
weechat_color);
|
||||
string += 2;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case GUI_COLOR_RESET_CHAR:
|
||||
gui_window_set_custom_color_fg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
|
||||
CONFIG_INTEGER(bar_window->bar->options[GUI_BAR_OPTION_COLOR_FG]));
|
||||
gui_window_set_custom_color_bg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
|
||||
CONFIG_INTEGER(bar_window->bar->options[GUI_BAR_OPTION_COLOR_BG]));
|
||||
string++;
|
||||
break;
|
||||
default:
|
||||
next_char = utf8_next_char (string);
|
||||
if (!next_char)
|
||||
break;
|
||||
|
||||
memcpy (utf_char, string, next_char - string);
|
||||
utf_char[next_char - string] = '\0';
|
||||
|
||||
if ((((unsigned char)utf_char[0]) < 32) && (!utf_char[1]))
|
||||
{
|
||||
low_char = 1;
|
||||
snprintf (utf_char, sizeof (utf_char), "%c",
|
||||
'A' + ((unsigned char)utf_char[0]) - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (*x + size_on_screen > bar_window->width)
|
||||
{
|
||||
if (gui_bar_get_filling (bar_window->bar) == GUI_BAR_FILLING_VERTICAL)
|
||||
return 0;
|
||||
if (*y >= bar_window->height - 1)
|
||||
return 0;
|
||||
*x = 0;
|
||||
(*y)++;
|
||||
wmove (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar, *y, *x);
|
||||
}
|
||||
|
||||
output = string_iconv_from_internal (NULL, utf_char);
|
||||
if (low_char)
|
||||
wattron (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar, A_REVERSE);
|
||||
wprintw (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar, "%s",
|
||||
(output) ? output : utf_char);
|
||||
if (low_char)
|
||||
wattroff (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar, A_REVERSE);
|
||||
if (output)
|
||||
free (output);
|
||||
|
||||
*x += size_on_screen;
|
||||
low_char = 0;
|
||||
if (!gui_window_utf_char_valid (utf_char))
|
||||
snprintf (utf_char, sizeof (utf_char), ".");
|
||||
}
|
||||
}
|
||||
|
||||
string = next_char;
|
||||
|
||||
size_on_screen = utf8_char_size_screen (utf_char);
|
||||
if (size_on_screen > 0)
|
||||
{
|
||||
if (x_with_hidden < bar_window->scroll_x)
|
||||
{
|
||||
/* hidden char (before scroll_x value) */
|
||||
x_with_hidden++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (*x + size_on_screen > bar_window->width)
|
||||
{
|
||||
if (gui_bar_get_filling (bar_window->bar) == GUI_BAR_FILLING_VERTICAL)
|
||||
return 0;
|
||||
if (*y >= bar_window->height - 1)
|
||||
return 0;
|
||||
*x = 0;
|
||||
(*y)++;
|
||||
wmove (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar, *y, *x);
|
||||
}
|
||||
|
||||
output = string_iconv_from_internal (NULL, utf_char);
|
||||
if (low_char)
|
||||
wattron (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar, A_REVERSE);
|
||||
wprintw (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar, "%s",
|
||||
(output) ? output : utf_char);
|
||||
if (low_char)
|
||||
wattroff (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar, A_REVERSE);
|
||||
if (output)
|
||||
free (output);
|
||||
|
||||
*x += size_on_screen;
|
||||
}
|
||||
}
|
||||
string = next_char;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
|
||||
+75
-36
@@ -636,9 +636,10 @@ char *
|
||||
gui_bar_item_default_input_text (void *data, struct t_gui_bar_item *item,
|
||||
struct t_gui_window *window)
|
||||
{
|
||||
char *ptr_input, str_buffer[128], str_start_input[16], str_cursor[16], *buf;
|
||||
char *ptr_input, *ptr_input2, str_buffer[128], str_start_input[16];
|
||||
char str_cursor[16], *buf;
|
||||
const char *pos_cursor;
|
||||
int length, buf_pos;
|
||||
int length, length_cursor, length_start_input, buf_pos;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
@@ -647,9 +648,22 @@ gui_bar_item_default_input_text (void *data, struct t_gui_bar_item *item,
|
||||
if (!window)
|
||||
window = gui_current_window;
|
||||
|
||||
snprintf (str_cursor, sizeof (str_cursor), "%c%c%c",
|
||||
GUI_COLOR_COLOR_CHAR,
|
||||
GUI_COLOR_BAR_CHAR,
|
||||
GUI_COLOR_BAR_MOVE_CURSOR_CHAR);
|
||||
length_cursor = strlen (str_cursor);
|
||||
snprintf (str_start_input, sizeof (str_start_input), "%c%c%c",
|
||||
GUI_COLOR_COLOR_CHAR,
|
||||
GUI_COLOR_BAR_CHAR,
|
||||
GUI_COLOR_BAR_START_INPUT_CHAR);
|
||||
length_start_input = strlen (str_start_input);
|
||||
|
||||
/* for modifiers */
|
||||
snprintf (str_buffer, sizeof (str_buffer),
|
||||
"0x%lx", (long unsigned int)(window->buffer));
|
||||
|
||||
/* execute modifier with basic string (without cursor tag) */
|
||||
ptr_input = hook_modifier_exec (NULL,
|
||||
"weechat_input_text_display",
|
||||
str_buffer,
|
||||
@@ -660,46 +674,71 @@ gui_bar_item_default_input_text (void *data, struct t_gui_bar_item *item,
|
||||
ptr_input = (window->buffer->input_buffer) ?
|
||||
strdup (window->buffer->input_buffer) : NULL;
|
||||
}
|
||||
|
||||
if (!ptr_input)
|
||||
return NULL;
|
||||
|
||||
/* insert "move cursor" id in string */
|
||||
snprintf (str_start_input, sizeof (str_start_input), "%c%c%c",
|
||||
GUI_COLOR_COLOR_CHAR,
|
||||
GUI_COLOR_BAR_CHAR,
|
||||
GUI_COLOR_BAR_START_INPUT_CHAR);
|
||||
snprintf (str_cursor, sizeof (str_cursor), "%c%c%c",
|
||||
GUI_COLOR_COLOR_CHAR,
|
||||
GUI_COLOR_BAR_CHAR,
|
||||
GUI_COLOR_BAR_MOVE_CURSOR_CHAR);
|
||||
pos_cursor = gui_chat_string_add_offset (ptr_input,
|
||||
window->buffer->input_buffer_pos);
|
||||
length = strlen (str_start_input)+ strlen (ptr_input) +
|
||||
strlen (str_cursor) + 1;
|
||||
buf = malloc (length);
|
||||
if (buf)
|
||||
if (ptr_input)
|
||||
{
|
||||
snprintf (buf, length, "%s", str_start_input);
|
||||
buf_pos = strlen (buf);
|
||||
|
||||
if (!pos_cursor)
|
||||
pos_cursor = ptr_input;
|
||||
|
||||
/* add beginning of buffer */
|
||||
if (pos_cursor != ptr_input)
|
||||
pos_cursor = gui_chat_string_add_offset (ptr_input,
|
||||
window->buffer->input_buffer_pos);
|
||||
length = strlen (ptr_input) + length_cursor + 1;
|
||||
buf = malloc (length);
|
||||
if (buf)
|
||||
{
|
||||
memmove (buf + buf_pos, ptr_input, pos_cursor - ptr_input);
|
||||
buf_pos += (pos_cursor - ptr_input);
|
||||
buf_pos = 0;
|
||||
|
||||
if (!pos_cursor)
|
||||
pos_cursor = ptr_input;
|
||||
|
||||
/* add beginning of buffer */
|
||||
if (pos_cursor != ptr_input)
|
||||
{
|
||||
memmove (buf + buf_pos, ptr_input, pos_cursor - ptr_input);
|
||||
buf_pos += (pos_cursor - ptr_input);
|
||||
}
|
||||
/* add "move cursor here" identifier in string */
|
||||
snprintf (buf + buf_pos, length - buf_pos, "%s",
|
||||
str_cursor);
|
||||
/* add end of buffer */
|
||||
strcat (buf, pos_cursor);
|
||||
|
||||
free (ptr_input);
|
||||
ptr_input = buf;
|
||||
}
|
||||
/* add "move cursor here" identifier in string */
|
||||
snprintf (buf + buf_pos, length - buf_pos, "%s",
|
||||
str_cursor);
|
||||
/* add end of buffer */
|
||||
strcat (buf, pos_cursor);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
ptr_input = strdup (str_cursor);
|
||||
}
|
||||
|
||||
/* execute modifier with cursor in string */
|
||||
ptr_input2 = hook_modifier_exec (NULL,
|
||||
"weechat_input_text_display_with_cursor",
|
||||
str_buffer,
|
||||
(ptr_input) ? ptr_input : "");
|
||||
if (ptr_input)
|
||||
free (ptr_input);
|
||||
ptr_input = buf;
|
||||
ptr_input = ptr_input2;
|
||||
|
||||
/* insert "start input" at beginning of string */
|
||||
if (ptr_input)
|
||||
{
|
||||
length = strlen (ptr_input) + length_start_input + 1;
|
||||
buf = malloc (length);
|
||||
if (buf)
|
||||
{
|
||||
snprintf (buf, length, "%s%s", str_start_input, ptr_input);
|
||||
free (ptr_input);
|
||||
ptr_input = buf;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
length = length_start_input + length_cursor + 1;
|
||||
ptr_input = malloc (length);
|
||||
if (ptr_input)
|
||||
{
|
||||
snprintf (ptr_input, length, "%s%s", str_start_input, str_cursor);
|
||||
}
|
||||
}
|
||||
|
||||
return ptr_input;
|
||||
|
||||
Reference in New Issue
Block a user