summaryrefslogtreecommitdiff
path: root/src/irc
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2006-04-02 21:53:41 +0000
committerSebastien Helleu <flashcode@flashtux.org>2006-04-02 21:53:41 +0000
commitd01081241a903b3b1a112883b7a76397b0d0dae9 (patch)
treea8ff4b026f92f4e4b3182b639f2c812992aa88fd /src/irc
parent8ef6192b4963b293f7539d46b260cf514ac3acb2 (diff)
downloadweechat-d01081241a903b3b1a112883b7a76397b0d0dae9.zip
Added nick alignment options
Diffstat (limited to 'src/irc')
-rw-r--r--src/irc/irc-commands.c2
-rw-r--r--src/irc/irc-display.c128
-rw-r--r--src/irc/irc-recv.c4
-rw-r--r--src/irc/irc-send.c18
-rw-r--r--src/irc/irc-server.c4
-rw-r--r--src/irc/irc.h4
6 files changed, 126 insertions, 34 deletions
diff --git a/src/irc/irc-commands.c b/src/irc/irc-commands.c
index b17581bf1..2ec2bb313 100644
--- a/src/irc/irc-commands.c
+++ b/src/irc/irc-commands.c
@@ -128,7 +128,7 @@ t_irc_command irc_commands[] =
NULL, 0, 2, 1, NULL, irc_cmd_send_links, NULL },
{ "list", N_("list channels and their topic"),
N_("[channel[,channel] [server]]"),
- N_("channel: channel to list\nserver: server name"),
+ N_("channel: channel to list (a regexp is allowed)\nserver: server name"),
NULL, 0, MAX_ARGS, 1, NULL, irc_cmd_send_list, NULL },
{ "lusers", N_("get statistics about the size of the IRC network"),
N_("[mask [target]]"),
diff --git a/src/irc/irc-display.c b/src/irc/irc-display.c
index 5c0f35399..fd24754a8 100644
--- a/src/irc/irc-display.c
+++ b/src/irc/irc-display.c
@@ -92,12 +92,23 @@ void
irc_display_prefix (t_irc_server *server, t_gui_buffer *buffer, char *prefix)
{
int type;
+ char format[32];
type = MSG_TYPE_INFO | MSG_TYPE_PREFIX;
if (!cfg_log_plugin_msg && (prefix == PREFIX_PLUGIN))
type |= MSG_TYPE_NOLOG;
+ if (buffer)
+ {
+ if (cfg_look_align_other
+ && (BUFFER_IS_CHANNEL(buffer) || BUFFER_IS_PRIVATE(buffer)))
+ {
+ snprintf (format, 32, "%%-%ds", cfg_look_align_size - 2);
+ gui_printf_type (buffer, MSG_TYPE_NICK, format, " ");
+ }
+ }
+
if (prefix[0] == prefix[2])
{
gui_printf_type (buffer, type, "%s%c%s%c%s%c ",
@@ -139,10 +150,57 @@ void
irc_display_nick (t_gui_buffer *buffer, t_irc_nick *nick, char *nickname,
int type, int display_around, int color_nick, int no_nickmode)
{
- if (display_around)
+ char format[32], *ptr_nickname;
+ int i, nickname_length, external_nick, length, spaces, disable_prefix_suffix;
+
+ ptr_nickname = strdup ((nick) ? nick->nick : nickname);
+ if (!ptr_nickname)
+ return;
+ nickname_length = strlen (ptr_nickname);
+ external_nick = (!nick && !BUFFER_IS_PRIVATE(buffer));
+ disable_prefix_suffix = ((cfg_look_align_nick != CFG_LOOK_ALIGN_NICK_NONE)
+ && ((int)strlen (cfg_look_nick_prefix) +
+ (int)strlen (cfg_look_nick_suffix) > cfg_look_align_size - 4));
+
+ /* calculate length to display, to truncate it if too long */
+ length = nickname_length;
+ if (!disable_prefix_suffix && cfg_look_nick_prefix)
+ length += strlen (cfg_look_nick_prefix);
+ if (external_nick)
+ length += 2;
+ if (nick)
+ {
+ if (nick->flags & (NICK_CHANOWNER | NICK_CHANADMIN |
+ NICK_OP | NICK_HALFOP | NICK_VOICE))
+ length += 1;
+ else if (cfg_look_nickmode_empty && !no_nickmode)
+ length += 1;
+ }
+ if (!disable_prefix_suffix && cfg_look_nick_suffix)
+ length += strlen (cfg_look_nick_suffix);
+
+ /* calculate number of spaces to insert before or after nick */
+ spaces = 0;
+ if (cfg_look_align_nick != CFG_LOOK_ALIGN_NICK_NONE)
+ spaces = cfg_look_align_size - length;
+
+ /* display prefix */
+ if (display_around && !disable_prefix_suffix
+ && cfg_look_nick_prefix && cfg_look_nick_prefix[0])
gui_printf_type (buffer, type, "%s%s",
GUI_COLOR(COLOR_WIN_CHAT_DARK),
- (nick || BUFFER_IS_PRIVATE(buffer)) ? "<" : ">");
+ cfg_look_nick_prefix);
+
+ /* display spaces before nick, if needed */
+ if (display_around
+ && (cfg_look_align_nick == CFG_LOOK_ALIGN_NICK_RIGHT)
+ && (spaces > 0))
+ {
+ snprintf (format, 32, "%%-%ds", spaces);
+ gui_printf_type (buffer, type, format, " ");
+ }
+
+ /* display nick mode */
if (nick && cfg_look_nickmode)
{
if (nick->flags & NICK_CHANOWNER)
@@ -160,26 +218,64 @@ irc_display_nick (t_gui_buffer *buffer, t_irc_nick *nick, char *nickname,
else if (nick->flags & NICK_VOICE)
gui_printf_type (buffer, type, "%s+",
GUI_COLOR(COLOR_WIN_NICK_VOICE));
- else
- if (cfg_look_nickmode_empty && !no_nickmode)
- gui_printf_type (buffer, type, "%s ",
- GUI_COLOR(COLOR_WIN_CHAT));
+ else if (cfg_look_nickmode_empty && !no_nickmode)
+ gui_printf_type (buffer, type, "%s ",
+ GUI_COLOR(COLOR_WIN_CHAT));
}
- if (color_nick < 0)
+
+ /* display nick */
+ if (external_nick)
gui_printf_type (buffer, type, "%s%s",
- GUI_COLOR(COLOR_WIN_CHAT_HIGHLIGHT),
- (nick) ? nick->nick : nickname);
- else
+ GUI_COLOR(COLOR_WIN_CHAT_DARK),
+ "(");
+ if (display_around && (spaces < 0))
+ {
+ i = nickname_length + spaces - 1;
+ if (i < 3)
+ {
+ if (nickname_length < 3)
+ i = nickname_length;
+ else
+ i = 3;
+ }
+ ptr_nickname[i] = '\0';
+ }
+ gui_printf_type_nick (buffer, type,
+ (nick) ? nick->nick : nickname,
+ "%s%s",
+ (color_nick < 0) ?
+ GUI_COLOR(COLOR_WIN_CHAT_HIGHLIGHT) :
+ GUI_COLOR((nick && color_nick) ?
+ nick->color : COLOR_WIN_CHAT),
+ ptr_nickname);
+ if (display_around && (spaces < 0))
+ gui_printf_type (buffer, type, "%s+",
+ GUI_COLOR(COLOR_WIN_NICK_MORE));
+ if (external_nick)
gui_printf_type (buffer, type, "%s%s",
- GUI_COLOR((nick && color_nick) ?
- nick->color : COLOR_WIN_CHAT),
- (nick) ? nick->nick : nickname);
+ GUI_COLOR(COLOR_WIN_CHAT_DARK),
+ ")");
- if (display_around)
+ /* display spaces after nick, if needed */
+ if (display_around
+ && (cfg_look_align_nick == CFG_LOOK_ALIGN_NICK_LEFT)
+ && (spaces > 0))
+ {
+ snprintf (format, 32, "%%-%ds", spaces);
+ gui_printf_type (buffer, type, format, " ");
+ }
+
+ /* display suffix */
+ if (display_around && !disable_prefix_suffix
+ && cfg_look_nick_suffix && cfg_look_nick_suffix[0])
gui_printf_type (buffer, type, "%s%s",
GUI_COLOR(COLOR_WIN_CHAT_DARK),
- (nick || BUFFER_IS_PRIVATE(buffer)) ? "> " : "< ");
- gui_printf_type (buffer, type, GUI_NO_COLOR);
+ cfg_look_nick_suffix);
+
+ gui_printf_type (buffer, type, "%s%s",
+ GUI_NO_COLOR,
+ (display_around) ? " " : "");
+ free (ptr_nickname);
}
/*
diff --git a/src/irc/irc-recv.c b/src/irc/irc-recv.c
index a9bc88be4..3bb396fb8 100644
--- a/src/irc/irc-recv.c
+++ b/src/irc/irc-recv.c
@@ -3662,9 +3662,9 @@ irc_cmd_recv_322 (t_irc_server *server, char *host, char *nick, char *arguments)
else
pos = arguments;
- if (server->cmd_list_re)
+ if (server->cmd_list_regexp)
{
- if (regexec (server->cmd_list_re, pos, 0, NULL, 0) == 0) {
+ if (regexec (server->cmd_list_regexp, pos, 0, NULL, 0) == 0) {
irc_display_prefix (server, server->buffer, PREFIX_SERVER);
gui_printf (server->buffer, "%s\n", pos);
}
diff --git a/src/irc/irc-send.c b/src/irc/irc-send.c
index f43fe18fb..c942e3d38 100644
--- a/src/irc/irc-send.c
+++ b/src/irc/irc-send.c
@@ -1121,21 +1121,21 @@ irc_cmd_send_list (t_irc_server *server, t_irc_channel *channel,
char buffer[512];
int ret;
- if (server->cmd_list_re)
+ if (server->cmd_list_regexp)
{
- regfree (server->cmd_list_re);
- free (server->cmd_list_re);
- server->cmd_list_re = NULL;
+ regfree (server->cmd_list_regexp);
+ free (server->cmd_list_regexp);
+ server->cmd_list_regexp = NULL;
}
if (arguments)
{
- server->cmd_list_re = (regex_t *) malloc (sizeof (regex_t));
- if (server->cmd_list_re)
+ server->cmd_list_regexp = (regex_t *) malloc (sizeof (regex_t));
+ if (server->cmd_list_regexp)
{
- if ((ret = regcomp (server->cmd_list_re, arguments, REG_NOSUB | REG_ICASE)) != 0)
+ if ((ret = regcomp (server->cmd_list_regexp, arguments, REG_NOSUB | REG_ICASE)) != 0)
{
- regerror (ret, server->cmd_list_re, buffer, sizeof(buffer));
+ regerror (ret, server->cmd_list_regexp, buffer, sizeof(buffer));
gui_printf (server->buffer,
_("%s \"%s\" is not a valid regular expression (%s)\n"),
WEECHAT_ERROR, arguments, buffer);
@@ -1146,7 +1146,7 @@ irc_cmd_send_list (t_irc_server *server, t_irc_channel *channel,
else
{
gui_printf (server->buffer,
- _("%s unable to alloc memory for regular expression\n"),
+ _("%s not enough memory for regular expression\n"),
WEECHAT_ERROR);
}
}
diff --git a/src/irc/irc-server.c b/src/irc/irc-server.c
index c5be5ef9b..9a28a39c2 100644
--- a/src/irc/irc-server.c
+++ b/src/irc/irc-server.c
@@ -106,13 +106,11 @@ server_init (t_irc_server *server)
server->lag_check_time.tv_sec = 0;
server->lag_check_time.tv_usec = 0;
server->lag_next_check = time (NULL) + cfg_irc_lag_check;
+ server->cmd_list_regexp = NULL;
server->buffer = NULL;
server->saved_buffer = NULL;
server->channels = NULL;
server->last_channel = NULL;
-
- /* regexp vars */
- server->cmd_list_re = NULL;
}
/*
diff --git a/src/irc/irc.h b/src/irc/irc.h
index 715972758..b56227a40 100644
--- a/src/irc/irc.h
+++ b/src/irc/irc.h
@@ -172,15 +172,13 @@ struct t_irc_server
int lag; /* lag (in milliseconds) */
struct timeval lag_check_time; /* last time lag was checked (ping sent) */
time_t lag_next_check; /* time for next check */
+ regex_t *cmd_list_regexp; /* compiled Regular Expression for /list */
t_gui_buffer *buffer; /* GUI buffer allocated for server */
t_gui_buffer *saved_buffer; /* channel before jumping to next server */
t_irc_channel *channels; /* opened channels on server */
t_irc_channel *last_channel; /* last opened channal on server */
t_irc_server *prev_server; /* link to previous server */
t_irc_server *next_server; /* link to next server */
-
- /* regexp vars */
- regex_t *cmd_list_re; /* compiled Regular Expression for /list */
};
/* irc commands */