Skip to content

Commit

Permalink
core: make nick prefix/suffix dynamic (move options from irc plugin t…
Browse files Browse the repository at this point in the history
…o core, add logger options) (bug #37531)
  • Loading branch information
flashcode committed Apr 29, 2013
1 parent cf8a125 commit 16cc0b6
Show file tree
Hide file tree
Showing 16 changed files with 251 additions and 101 deletions.
6 changes: 5 additions & 1 deletion ChangeLog
@@ -1,7 +1,7 @@
WeeChat ChangeLog
=================
Sébastien Helleu <flashcode@flashtux.org>
v0.4.1-dev, 2013-04-28
v0.4.1-dev, 2013-04-29


This document lists all changes for each version.
Expand All @@ -14,6 +14,10 @@ http://weechat.org/files/releasenotes/ReleaseNotes-devel.html[release notes]
Version 0.4.1 (under dev!)
--------------------------

* core: make nick prefix/suffix dynamic (not stored in the line): move options
irc.look.nick_{prefix|suffix} to weechat.look.nick_{prefix|suffix} and options
irc.color.nick_{prefix|suffix} to weechat.color.chat_nick_{prefix|suffix},
add new options logger.file.nick_{prefix|suffix} (bug #37531)
* core: reset scroll in window before zooming on a merged buffer (bug #38207)
* core: install icon file (patch #7972)
* core: fix refresh of item "completion": clear it after any action that is
Expand Down
28 changes: 27 additions & 1 deletion NEWS
@@ -1,7 +1,7 @@
WeeChat Release Notes
=====================
Sébastien Helleu <flashcode@flashtux.org>
v0.4.1-dev, 2013-03-24
v0.4.1-dev, 2013-04-29


This document lists important changes for each version, that require manual
Expand All @@ -16,6 +16,32 @@ http://weechat.org/files/changelog/ChangeLog-devel.html[ChangeLog]
Version 0.4.1 (under dev!)
--------------------------

=== Dynamic nick prefix/suffix ===

The nick prefix/suffix (for example: "<" and ">") are now dynamic and used on
display (not stored any more in the line).

Options moved from irc plugin (irc.conf) to core (weechat.conf):

* 'irc.look.nick_prefix' moved to 'weechat.look.nick_prefix'
* 'irc.look.nick_suffix' moved to 'weechat.look.nick_suffix'
* 'irc.color.nick_prefix' moved to 'weechat.color.chat_nick_prefix'
* 'irc.color.nick_suffix' moved to 'weechat.color.chat_nick_suffix'

Types and default values for these four options remain unchanged.

After `/upgrade`, if you set new options to non-empty strings, and if old
options were set to non-empty strings too, you will see double prefix/suffix
on old messages, this is normal behaviour (lines displayed before `/upgrade`
have prefix/suffix saved in prefix, but new lines don't have them any more).

New options in logger plugin (logger.conf):

* 'logger.file.nick_prefix': prefix for nicks in log files (default: empty
string)
* 'logger.file.nick_suffix': suffix for nicks in log files (default: empty
string)

=== IRC reconnection on important lag ===

Option 'irc.network.lag_disconnect' has been renamed to
Expand Down
49 changes: 49 additions & 0 deletions src/core/wee-config.c
Expand Up @@ -124,6 +124,8 @@ struct t_config_option *config_look_item_buffer_filter;
struct t_config_option *config_look_jump_current_to_previous_buffer;
struct t_config_option *config_look_jump_previous_buffer_when_closing;
struct t_config_option *config_look_jump_smart_back_to_buffer;
struct t_config_option *config_look_nick_prefix;
struct t_config_option *config_look_nick_suffix;
struct t_config_option *config_look_mouse;
struct t_config_option *config_look_mouse_timer_delay;
struct t_config_option *config_look_paste_bracketed;
Expand Down Expand Up @@ -175,6 +177,8 @@ struct t_config_option *config_color_chat_server;
struct t_config_option *config_color_chat_channel;
struct t_config_option *config_color_chat_nick;
struct t_config_option *config_color_chat_nick_colors;
struct t_config_option *config_color_chat_nick_prefix;
struct t_config_option *config_color_chat_nick_suffix;
struct t_config_option *config_color_chat_nick_self;
struct t_config_option *config_color_chat_nick_offline;
struct t_config_option *config_color_chat_nick_offline_highlight;
Expand Down Expand Up @@ -248,6 +252,7 @@ struct t_config_option *config_plugin_save_config_on_unload;

/* other */

int config_length_nick_prefix_suffix = 0;
int config_length_prefix_same_nick = 0;
struct t_hook *config_day_change_timer = NULL;
int config_day_change_old_day = -1;
Expand Down Expand Up @@ -407,6 +412,26 @@ config_compute_prefix_max_length_all_buffers ()
}
}

/*
* Callback for changes on options "weechat.look.nick_prefix" and
* "weechat.look.nick_suffix".
*/

void
config_change_nick_prefix_suffix (void *data, struct t_config_option *option)
{
/* make C compiler happy */
(void) data;
(void) option;

config_length_nick_prefix_suffix =
gui_chat_strlen_screen (CONFIG_STRING(config_look_nick_prefix))
+ gui_chat_strlen_screen (CONFIG_STRING(config_look_nick_suffix));

config_compute_prefix_max_length_all_buffers ();
gui_window_ask_refresh (1);
}

/*
* Callback for changes on option "weechat.look.prefix_same_nick".
*/
Expand Down Expand Up @@ -2152,6 +2177,18 @@ config_weechat_init_options ()
"jump_smart_back_to_buffer", "boolean",
N_("jump back to initial buffer after reaching end of hotlist"),
NULL, 0, 0, "on", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL);
config_look_nick_prefix = config_file_new_option (
weechat_config_file, ptr_section,
"nick_prefix", "string",
N_("text to display before nick in prefix of message, example: \"<\""),
NULL, 0, 0, "", NULL, 0, NULL, NULL,
&config_change_nick_prefix_suffix, NULL, NULL, NULL);
config_look_nick_suffix = config_file_new_option (
weechat_config_file, ptr_section,
"nick_suffix", "string",
N_("text to display after nick in prefix of message, example: \">\""),
NULL, 0, 0, "", NULL, 0, NULL, NULL,
&config_change_nick_prefix_suffix, NULL, NULL, NULL);
config_look_mouse = config_file_new_option (
weechat_config_file, ptr_section,
"mouse", "boolean",
Expand Down Expand Up @@ -2529,6 +2566,18 @@ config_weechat_init_options ()
NULL, 0, 0, "cyan,magenta,green,brown,lightblue,default,lightcyan,"
"lightmagenta,lightgreen,blue", NULL, 0,
NULL, NULL, &config_change_nick_colors, NULL, NULL, NULL);
config_color_chat_nick_prefix = config_file_new_option (
weechat_config_file, ptr_section,
"chat_nick_prefix", "color",
N_("color for nick prefix (string displayed before nick in prefix)"),
NULL, GUI_COLOR_CHAT_NICK_PREFIX, 0, "green", NULL, 0, NULL, NULL,
&config_change_color, NULL, NULL, NULL);
config_color_chat_nick_suffix = config_file_new_option (
weechat_config_file, ptr_section,
"chat_nick_suffix", "color",
N_("color for nick suffix (string displayed after nick in suffix)"),
NULL, GUI_COLOR_CHAT_NICK_SUFFIX, 0, "green", NULL, 0, NULL, NULL,
&config_change_color, NULL, NULL, NULL);
config_color_chat_nick_self = config_file_new_option (
weechat_config_file, ptr_section,
"chat_nick_self", "color",
Expand Down
5 changes: 5 additions & 0 deletions src/core/wee-config.h
Expand Up @@ -148,6 +148,8 @@ extern struct t_config_option *config_look_item_buffer_filter;
extern struct t_config_option *config_look_jump_current_to_previous_buffer;
extern struct t_config_option *config_look_jump_previous_buffer_when_closing;
extern struct t_config_option *config_look_jump_smart_back_to_buffer;
extern struct t_config_option *config_look_nick_prefix;
extern struct t_config_option *config_look_nick_suffix;
extern struct t_config_option *config_look_mouse;
extern struct t_config_option *config_look_mouse_timer_delay;
extern struct t_config_option *config_look_paste_bracketed;
Expand Down Expand Up @@ -197,6 +199,8 @@ extern struct t_config_option *config_color_chat_server;
extern struct t_config_option *config_color_chat_channel;
extern struct t_config_option *config_color_chat_nick;
extern struct t_config_option *config_color_chat_nick_colors;
extern struct t_config_option *config_color_chat_nick_prefix;
extern struct t_config_option *config_color_chat_nick_suffix;
extern struct t_config_option *config_color_chat_nick_self;
extern struct t_config_option *config_color_chat_nick_offline;
extern struct t_config_option *config_color_chat_nick_offline_highlight;
Expand Down Expand Up @@ -260,6 +264,7 @@ extern struct t_config_option *config_plugin_extension;
extern struct t_config_option *config_plugin_path;
extern struct t_config_option *config_plugin_save_config_on_unload;

extern int config_length_nick_prefix_suffix;
extern int config_length_prefix_same_nick;
extern regex_t *config_highlight_regex;
extern char **config_highlight_tags;
Expand Down
94 changes: 74 additions & 20 deletions src/gui/curses/gui-curses-chat.c
Expand Up @@ -602,9 +602,9 @@ gui_chat_display_time_to_prefix (struct t_gui_window *window,
char str_space[] = " ";
char *prefix_no_color, *prefix_highlighted, *ptr_prefix, *ptr_prefix2;
char *ptr_prefix_color;
const char *short_name, *str_color;
const char *short_name, *str_color, *ptr_nick_prefix, *ptr_nick_suffix;
int i, length, length_allowed, num_spaces, prefix_length, extra_spaces;
int chars_displayed, nick_offline;
int chars_displayed, nick_offline, prefix_is_nick, length_nick_prefix_suffix;
struct t_gui_lines *mixed_lines;

if (!simulate)
Expand Down Expand Up @@ -773,7 +773,7 @@ gui_chat_display_time_to_prefix (struct t_gui_window *window,

/* get prefix for display */
gui_line_get_prefix_for_display (line, &ptr_prefix, &prefix_length,
&ptr_prefix_color);
&ptr_prefix_color, &prefix_is_nick);
if (ptr_prefix)
{
ptr_prefix2 = NULL;
Expand All @@ -794,6 +794,20 @@ gui_chat_display_time_to_prefix (struct t_gui_window *window,
ptr_prefix = (ptr_prefix2) ? ptr_prefix2 : strdup (ptr_prefix);
}

/* get nick prefix/suffix (if prefix is a nick) */
if (prefix_is_nick && (config_length_nick_prefix_suffix > 0))
{
ptr_nick_prefix = CONFIG_STRING(config_look_nick_prefix);
ptr_nick_suffix = CONFIG_STRING(config_look_nick_suffix);
length_nick_prefix_suffix = config_length_nick_prefix_suffix;
}
else
{
ptr_nick_prefix = NULL;
ptr_nick_suffix = NULL;
length_nick_prefix_suffix = 0;
}

/* display prefix */
if (ptr_prefix
&& (ptr_prefix[0]
Expand All @@ -816,7 +830,19 @@ gui_chat_display_time_to_prefix (struct t_gui_window *window,
else
length_allowed = window->buffer->lines->prefix_max_length;

num_spaces = length_allowed - prefix_length;
/*
* if we are not able to display at least 1 char of prefix (inside
* prefix/suffix), then do not display nick prefix/suffix at all
*/
if (ptr_nick_prefix && ptr_nick_suffix
&& (length_nick_prefix_suffix + 1 > length_allowed))
{
ptr_nick_prefix = NULL;
ptr_nick_suffix = NULL;
length_nick_prefix_suffix = 0;
}

num_spaces = length_allowed - prefix_length - length_nick_prefix_suffix;

if (CONFIG_INTEGER(config_look_prefix_align) == CONFIG_LOOK_PREFIX_ALIGN_RIGHT)
{
Expand All @@ -830,6 +856,20 @@ gui_chat_display_time_to_prefix (struct t_gui_window *window,
}
}

/* display prefix before nick (for example "<") */
if (ptr_nick_prefix)
{
if (!simulate)
{
gui_window_set_weechat_color (GUI_WINDOW_OBJECTS(window)->win_chat,
GUI_COLOR_CHAT_NICK_PREFIX);
}
gui_chat_display_word (window, line,
ptr_nick_prefix,
NULL, 1, num_lines, count,
lines_displayed, simulate, 0, 0);
}

nick_offline = CONFIG_BOOLEAN(config_look_color_nick_offline)
&& gui_line_has_offline_nick (line);

Expand Down Expand Up @@ -888,15 +928,14 @@ gui_chat_display_time_to_prefix (struct t_gui_window *window,
(prefix_highlighted) ? prefix_highlighted : ptr_prefix,
(prefix_highlighted) ?
prefix_highlighted + gui_chat_string_real_pos (prefix_highlighted,
length_allowed) :
length_allowed - length_nick_prefix_suffix - 1) :
ptr_prefix + gui_chat_string_real_pos (ptr_prefix,
length_allowed),
length_allowed - length_nick_prefix_suffix - 1),
1, num_lines, count, lines_displayed,
simulate,
CONFIG_BOOLEAN(config_look_color_inactive_prefix),
nick_offline);
if (chars_displayed < length_allowed)
extra_spaces = length_allowed - chars_displayed;
extra_spaces = length_allowed - length_nick_prefix_suffix - 1 - chars_displayed;
}
else
{
Expand All @@ -922,17 +961,15 @@ gui_chat_display_time_to_prefix (struct t_gui_window *window,
GUI_COLOR_CHAT);
}

if (CONFIG_INTEGER(config_look_prefix_align) == CONFIG_LOOK_PREFIX_ALIGN_LEFT)
for (i = 0; i < extra_spaces; i++)
{
for (i = 0; i < num_spaces; i++)
{
gui_chat_display_word (window, line, str_space,
NULL, 1, num_lines, count, lines_displayed,
simulate,
CONFIG_BOOLEAN(config_look_color_inactive_prefix),
0);
}
gui_chat_display_word (window, line, str_space,
NULL, 1, num_lines, count, lines_displayed,
simulate,
CONFIG_BOOLEAN(config_look_color_inactive_prefix),
0);
}

if ((CONFIG_INTEGER(config_look_prefix_align) != CONFIG_LOOK_PREFIX_ALIGN_NONE)
&& (num_spaces < 0))
{
Expand All @@ -948,9 +985,24 @@ gui_chat_display_time_to_prefix (struct t_gui_window *window,
CONFIG_BOOLEAN(config_look_color_inactive_prefix),
0);
}
else

/* display suffix after nick (for example ">") */
if (ptr_nick_suffix)
{
if (!simulate)
{
gui_window_set_weechat_color (GUI_WINDOW_OBJECTS(window)->win_chat,
GUI_COLOR_CHAT_NICK_SUFFIX);
}
gui_chat_display_word (window, line,
ptr_nick_suffix,
NULL, 1, num_lines, count,
lines_displayed, simulate, 0, 0);
}

if (CONFIG_INTEGER(config_look_prefix_align) == CONFIG_LOOK_PREFIX_ALIGN_LEFT)
{
if (window->buffer->lines->prefix_max_length > 0)
for (i = 0; i < num_spaces; i++)
{
gui_chat_display_word (window, line, str_space,
NULL, 1, num_lines, count, lines_displayed,
Expand All @@ -959,14 +1011,16 @@ gui_chat_display_time_to_prefix (struct t_gui_window *window,
0);
}
}
for (i = 0; i < extra_spaces; i++)

if (window->buffer->lines->prefix_max_length > 0)
{
gui_chat_display_word (window, line, str_space,
NULL, 1, num_lines, count, lines_displayed,
simulate,
CONFIG_BOOLEAN(config_look_color_inactive_prefix),
0);
}

if ((CONFIG_INTEGER(config_look_prefix_align) != CONFIG_LOOK_PREFIX_ALIGN_NONE)
&& (CONFIG_STRING(config_look_prefix_suffix)
&& CONFIG_STRING(config_look_prefix_suffix)[0]))
Expand Down
2 changes: 2 additions & 0 deletions src/gui/curses/gui-curses-color.c
Expand Up @@ -1421,6 +1421,8 @@ gui_color_init_weechat ()
gui_color_build (GUI_COLOR_CHAT_PREFIX_BUFFER_INACTIVE_BUFFER, CONFIG_COLOR(config_color_chat_prefix_buffer_inactive_buffer), CONFIG_COLOR(config_color_chat_bg));
gui_color_build (GUI_COLOR_CHAT_NICK_OFFLINE, CONFIG_COLOR(config_color_chat_nick_offline), CONFIG_COLOR(config_color_chat_bg));
gui_color_build (GUI_COLOR_CHAT_NICK_OFFLINE_HIGHLIGHT, CONFIG_COLOR(config_color_chat_nick_offline_highlight), CONFIG_COLOR(config_color_chat_nick_offline_highlight_bg));
gui_color_build (GUI_COLOR_CHAT_NICK_PREFIX, CONFIG_COLOR(config_color_chat_nick_prefix), CONFIG_COLOR(config_color_chat_bg));
gui_color_build (GUI_COLOR_CHAT_NICK_SUFFIX, CONFIG_COLOR(config_color_chat_nick_suffix), CONFIG_COLOR(config_color_chat_bg));

/*
* define old nick colors for compatibility on /upgrade with previous
Expand Down
2 changes: 2 additions & 0 deletions src/gui/gui-color.h
Expand Up @@ -76,6 +76,8 @@ enum t_gui_color_enum
GUI_COLOR_CHAT_PREFIX_BUFFER_INACTIVE_BUFFER,
GUI_COLOR_CHAT_NICK_OFFLINE,
GUI_COLOR_CHAT_NICK_OFFLINE_HIGHLIGHT,
GUI_COLOR_CHAT_NICK_PREFIX,
GUI_COLOR_CHAT_NICK_SUFFIX,

/* number of colors */
GUI_COLOR_NUM_COLORS,
Expand Down

0 comments on commit 16cc0b6

Please sign in to comment.