mirror of
https://github.com/weechat/weechat.git
synced 2026-07-09 11:13:12 +02:00
core: add support of UTF-8 chars in horizontal/vertical separators
This commit is contained in:
+23
-6
@@ -728,6 +728,21 @@ config_check_prefix_buffer_align_more (void *data,
|
||||
return (utf8_strlen_screen (value) == 1) ? 1 : 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Checks options "weechat.look.separator_{horizontal|vertical}".
|
||||
*/
|
||||
|
||||
int
|
||||
config_check_separator (void *data, struct t_config_option *option,
|
||||
const char *value)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
(void) option;
|
||||
|
||||
return (utf8_strlen_screen (value) <= 1) ? 1 : 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Callback for changes on a color option.
|
||||
*/
|
||||
@@ -2578,16 +2593,18 @@ config_weechat_init_options ()
|
||||
"separator_horizontal", "string",
|
||||
N_("char used to draw horizontal separators around bars and windows "
|
||||
"(empty value will draw a real line with ncurses, but may cause bugs "
|
||||
"with URL selection under some terminals), wide chars are NOT "
|
||||
"allowed here"),
|
||||
NULL, 0, 0, "-", NULL, 0, NULL, NULL, &config_change_buffers, NULL, NULL, NULL);
|
||||
"with URL selection under some terminals); "
|
||||
"width on screen must be exactly one char"),
|
||||
NULL, 0, 0, "-", NULL, 0,
|
||||
&config_check_separator, NULL, &config_change_buffers, NULL, NULL, NULL);
|
||||
config_look_separator_vertical = config_file_new_option (
|
||||
weechat_config_file, ptr_section,
|
||||
"separator_vertical", "string",
|
||||
N_("char used to draw vertical separators around bars and windows "
|
||||
"(empty value will draw a real line with ncurses), wide chars are "
|
||||
"NOT allowed here"),
|
||||
NULL, 0, 0, "", NULL, 0, NULL, NULL, &config_change_buffers, NULL, NULL, NULL);
|
||||
"(empty value will draw a real line with ncurses); "
|
||||
"width on screen must be exactly one char"),
|
||||
NULL, 0, 0, "", NULL, 0,
|
||||
&config_check_separator, NULL, &config_change_buffers, NULL, NULL, NULL);
|
||||
config_look_time_format = config_file_new_option (
|
||||
weechat_config_file, ptr_section,
|
||||
"time_format", "string",
|
||||
|
||||
@@ -405,7 +405,7 @@ gui_bar_window_draw (struct t_gui_bar_window *bar_window,
|
||||
int chars_available, index, size;
|
||||
int length_screen_before_cursor, length_screen_after_cursor;
|
||||
int diff, max_length, optimal_number_of_lines;
|
||||
int some_data_not_displayed, separator_horizontal, separator_vertical;
|
||||
int some_data_not_displayed;
|
||||
int index_item, index_subitem, index_line;
|
||||
|
||||
if (!gui_init_ok)
|
||||
@@ -747,47 +747,35 @@ gui_bar_window_draw (struct t_gui_bar_window *bar_window,
|
||||
|
||||
if (CONFIG_INTEGER(bar_window->bar->options[GUI_BAR_OPTION_SEPARATOR]))
|
||||
{
|
||||
separator_horizontal = ACS_HLINE;
|
||||
separator_vertical = ACS_VLINE;
|
||||
if (CONFIG_STRING(config_look_separator_horizontal)
|
||||
&& CONFIG_STRING(config_look_separator_horizontal)[0])
|
||||
{
|
||||
separator_horizontal = utf8_char_int (CONFIG_STRING(config_look_separator_horizontal));
|
||||
if (separator_horizontal > 127)
|
||||
separator_horizontal = ACS_HLINE;
|
||||
}
|
||||
if (CONFIG_STRING(config_look_separator_vertical)
|
||||
&& CONFIG_STRING(config_look_separator_vertical)[0])
|
||||
{
|
||||
separator_vertical = utf8_char_int (CONFIG_STRING(config_look_separator_vertical));
|
||||
if (separator_vertical > 127)
|
||||
separator_vertical = ACS_VLINE;
|
||||
}
|
||||
switch (CONFIG_INTEGER(bar_window->bar->options[GUI_BAR_OPTION_POSITION]))
|
||||
{
|
||||
case GUI_BAR_POSITION_BOTTOM:
|
||||
gui_window_set_weechat_color (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_separator,
|
||||
GUI_COLOR_SEPARATOR);
|
||||
mvwhline (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_separator,
|
||||
0, 0, separator_horizontal, bar_window->width);
|
||||
gui_window_hline (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_separator,
|
||||
0, 0, bar_window->width,
|
||||
CONFIG_STRING(config_look_separator_horizontal));
|
||||
break;
|
||||
case GUI_BAR_POSITION_TOP:
|
||||
gui_window_set_weechat_color (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_separator,
|
||||
GUI_COLOR_SEPARATOR);
|
||||
mvwhline (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_separator,
|
||||
0, 0, separator_horizontal, bar_window->width);
|
||||
gui_window_hline (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_separator,
|
||||
0, 0, bar_window->width,
|
||||
CONFIG_STRING(config_look_separator_horizontal));
|
||||
break;
|
||||
case GUI_BAR_POSITION_LEFT:
|
||||
gui_window_set_weechat_color (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_separator,
|
||||
GUI_COLOR_SEPARATOR);
|
||||
mvwvline (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_separator,
|
||||
0, 0, separator_vertical, bar_window->height);
|
||||
gui_window_vline (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_separator,
|
||||
0, 0, bar_window->height,
|
||||
CONFIG_STRING(config_look_separator_vertical));
|
||||
break;
|
||||
case GUI_BAR_POSITION_RIGHT:
|
||||
gui_window_set_weechat_color (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_separator,
|
||||
GUI_COLOR_SEPARATOR);
|
||||
mvwvline (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_separator,
|
||||
0, 0, separator_vertical, bar_window->height);
|
||||
gui_window_vline (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_separator,
|
||||
0, 0, bar_window->height,
|
||||
CONFIG_STRING(config_look_separator_vertical));
|
||||
break;
|
||||
case GUI_BAR_NUM_POSITIONS:
|
||||
break;
|
||||
|
||||
@@ -39,7 +39,6 @@
|
||||
#include "../../core/wee-hook.h"
|
||||
#include "../../core/wee-log.h"
|
||||
#include "../../core/wee-string.h"
|
||||
#include "../../core/wee-utf8.h"
|
||||
#include "../../plugins/plugin.h"
|
||||
#include "../gui-window.h"
|
||||
#include "../gui-bar.h"
|
||||
@@ -1047,6 +1046,60 @@ gui_window_calculate_pos_size (struct t_gui_window *window)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Draws a horizontal line (like ncurses function "mvwhline", but UTF-8 chars
|
||||
* are supported).
|
||||
*
|
||||
* If "string" is NULL or empty, the ACS_HLINE char is used (plain line).
|
||||
* If "string" is not NULL and not empty, its width on screen must be exactly
|
||||
* one char.
|
||||
*/
|
||||
|
||||
void
|
||||
gui_window_hline (WINDOW *window, int x, int y, int width, const char *string)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (string && string[0])
|
||||
{
|
||||
for (i = 0; i < width; i++)
|
||||
{
|
||||
mvwaddstr (window, y, x + i, string);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mvwhline (window, y, x, ACS_HLINE, width);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Draws a vertical line (like ncurses function "mvwvline", but UTF-8 chars
|
||||
* are supported).
|
||||
*
|
||||
* If "string" is NULL or empty, the ACS_VLINE char is used (plain line).
|
||||
* If "string" is not NULL and not empty, its width on screen must be exactly
|
||||
* one char.
|
||||
*/
|
||||
|
||||
void
|
||||
gui_window_vline (WINDOW *window, int x, int y, int height, const char *string)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (string && string[0])
|
||||
{
|
||||
for (i = 0; i < height; i++)
|
||||
{
|
||||
mvwaddstr (window, y + i, x, string);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mvwvline (window, y, x, ACS_VLINE, height);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Draws window separators.
|
||||
*/
|
||||
@@ -1054,7 +1107,7 @@ gui_window_calculate_pos_size (struct t_gui_window *window)
|
||||
void
|
||||
gui_window_draw_separators (struct t_gui_window *window)
|
||||
{
|
||||
int separator_char, separator_horizontal, separator_vertical, x, width;
|
||||
int separator_horizontal, separator_vertical, x, width;
|
||||
|
||||
/* remove separators */
|
||||
if (GUI_WINDOW_OBJECTS(window)->win_separator_horiz)
|
||||
@@ -1086,16 +1139,9 @@ gui_window_draw_separators (struct t_gui_window *window)
|
||||
x);
|
||||
gui_window_set_weechat_color (GUI_WINDOW_OBJECTS(window)->win_separator_horiz,
|
||||
GUI_COLOR_SEPARATOR);
|
||||
separator_char = ACS_HLINE;
|
||||
if (CONFIG_STRING(config_look_separator_horizontal)
|
||||
&& CONFIG_STRING(config_look_separator_horizontal)[0])
|
||||
{
|
||||
separator_char = utf8_char_int (CONFIG_STRING(config_look_separator_horizontal));
|
||||
if (separator_char > 127)
|
||||
separator_char = ACS_VLINE;
|
||||
}
|
||||
mvwhline (GUI_WINDOW_OBJECTS(window)->win_separator_horiz, 0, 0,
|
||||
separator_char, width);
|
||||
gui_window_hline (GUI_WINDOW_OBJECTS(window)->win_separator_horiz,
|
||||
0, 0, width,
|
||||
CONFIG_STRING(config_look_separator_horizontal));
|
||||
wnoutrefresh (GUI_WINDOW_OBJECTS(window)->win_separator_horiz);
|
||||
}
|
||||
|
||||
@@ -1108,16 +1154,9 @@ gui_window_draw_separators (struct t_gui_window *window)
|
||||
window->win_x - 1);
|
||||
gui_window_set_weechat_color (GUI_WINDOW_OBJECTS(window)->win_separator_vertic,
|
||||
GUI_COLOR_SEPARATOR);
|
||||
separator_char = ACS_VLINE;
|
||||
if (CONFIG_STRING(config_look_separator_vertical)
|
||||
&& CONFIG_STRING(config_look_separator_vertical)[0])
|
||||
{
|
||||
separator_char = utf8_char_int (CONFIG_STRING(config_look_separator_vertical));
|
||||
if (separator_char > 127)
|
||||
separator_char = ACS_VLINE;
|
||||
}
|
||||
mvwvline (GUI_WINDOW_OBJECTS(window)->win_separator_vertic, 0, 0,
|
||||
separator_char, window->win_height);
|
||||
gui_window_vline (GUI_WINDOW_OBJECTS(window)->win_separator_vertic,
|
||||
0, 0, window->win_height,
|
||||
CONFIG_STRING(config_look_separator_vertical));
|
||||
wnoutrefresh (GUI_WINDOW_OBJECTS(window)->win_separator_vertic);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,6 +134,10 @@ extern void gui_window_string_apply_color_set_attr (unsigned char **str,
|
||||
WINDOW *window);
|
||||
extern void gui_window_string_apply_color_remove_attr (unsigned char **str,
|
||||
WINDOW *window);
|
||||
extern void gui_window_hline (WINDOW *window, int x, int y, int width,
|
||||
const char *string);
|
||||
extern void gui_window_vline (WINDOW *window, int x, int y, int height,
|
||||
const char *string);
|
||||
extern void gui_window_set_title (const char *title);
|
||||
|
||||
#endif /* __WEECHAT_GUI_CURSES_H */
|
||||
|
||||
Reference in New Issue
Block a user