diff --git a/src/fe-common/core/fe-expandos.c b/src/fe-common/core/fe-expandos.c index 20054f04..02e419a5 100644 --- a/src/fe-common/core/fe-expandos.c +++ b/src/fe-common/core/fe-expandos.c @@ -75,7 +75,12 @@ static char *expando_nickalign(SERVER_REC *server, void *item, int *free_ret) int width, mode_chars, nick_chars, total_chars, padding; const char *mode; - if (!settings_get_bool("nick_column_enabled") || !nick_context_valid || !current_nick) { + /* Gdy wyłączone - zwróć pusty string */ + if (!settings_get_bool("nick_column_enabled")) { + return ""; + } + + if (!nick_context_valid || !current_nick) { return ""; } @@ -110,7 +115,12 @@ static char *expando_nicktrunc(SERVER_REC *server, void *item, int *free_ret) const char *mode; char *result; - if (!settings_get_bool("nick_column_enabled") || !nick_context_valid || !current_nick) { + /* Gdy wyłączone - zwróć oryginalny nick */ + if (!settings_get_bool("nick_column_enabled")) { + return current_nick ? current_nick : ""; + } + + if (!nick_context_valid || !current_nick) { return current_nick ? current_nick : ""; } diff --git a/src/fe-common/core/formats.c b/src/fe-common/core/formats.c index e04a503d..886f1578 100644 --- a/src/fe-common/core/formats.c +++ b/src/fe-common/core/formats.c @@ -828,12 +828,79 @@ char *format_get_text_theme_args(THEME_REC *theme, const char *module, formatnum, arglist); } +/* Check if format number is a message format that needs nick column */ +static gboolean is_message_format(int formatnum) +{ + return (formatnum == TXT_OWN_MSG || formatnum == TXT_OWN_MSG_CHANNEL || + formatnum == TXT_PUBMSG || formatnum == TXT_PUBMSG_CHANNEL || + formatnum == TXT_PUBMSG_ME || formatnum == TXT_PUBMSG_ME_CHANNEL || + formatnum == TXT_PUBMSG_HILIGHT || formatnum == TXT_PUBMSG_HILIGHT_CHANNEL); +} + +/* Apply nick column formatting to format string */ +static char *apply_nick_column_formatting(const char *format) +{ + GString *result; + char *modified; + char *pos, *before, *after, *temp; + + if (!format) return NULL; + + result = g_string_new(""); + + /* Add $nickalign at the beginning if not already present */ + if (!strstr(format, "$nickalign")) { + g_string_append(result, "$nickalign"); + } + + /* Replace nick templates with truncated versions */ + modified = g_strdup(format); + + /* Replace {ownnick $0} with {ownnick $nicktrunc} */ + pos = strstr(modified, "{ownnick $0}"); + if (pos) { + before = g_strndup(modified, pos - modified); + after = pos + strlen("{ownnick $0}"); + g_free(modified); + modified = g_strdup_printf("%s{ownnick $nicktrunc}%s", before, after); + g_free(before); + } + + /* Replace {pubnick $0} with {pubnick $nicktrunc} */ + pos = strstr(modified, "{pubnick $0}"); + if (pos) { + before = g_strndup(modified, pos - modified); + after = pos + strlen("{pubnick $0}"); + temp = modified; + modified = g_strdup_printf("%s{pubnick $nicktrunc}%s", before, after); + g_free(temp); + g_free(before); + } + + /* Replace {menick $0} with {menick $nicktrunc} */ + pos = strstr(modified, "{menick $0}"); + if (pos) { + before = g_strndup(modified, pos - modified); + after = pos + strlen("{menick $0}"); + temp = modified; + modified = g_strdup_printf("%s{menick $nicktrunc}%s", before, after); + g_free(temp); + g_free(before); + } + + g_string_append(result, modified); + g_free(modified); + + return g_string_free_and_steal(result); +} + char *format_get_text_theme_charargs(THEME_REC *theme, const char *module, TEXT_DEST_REC *dest, int formatnum, char **args) { MODULE_THEME_REC *module_theme; - char *text; + char *text, *modified_text = NULL; + char *result; if (module == NULL) return NULL; @@ -843,7 +910,21 @@ char *format_get_text_theme_charargs(THEME_REC *theme, const char *module, return NULL; text = module_theme->expanded_formats[formatnum]; - return format_get_text_args(dest, text, args); + + /* Apply nick column formatting if enabled and this is a message format */ + if (settings_get_bool("nick_column_enabled") && + g_strcmp0(module, "fe-common/core") == 0 && + is_message_format(formatnum)) { + modified_text = apply_nick_column_formatting(text); + text = modified_text; + } + + result = format_get_text_args(dest, text, args); + + if (modified_text) + g_free(modified_text); + + return result; } char *format_get_text(const char *module, WINDOW_REC *window, diff --git a/themes/default.theme b/themes/default.theme index 0a877272..13341159 100644 --- a/themes/default.theme +++ b/themes/default.theme @@ -306,14 +306,14 @@ abstracts = { formats = { "fe-common/core" = { - own_msg = "$nickalign{ownmsgnick $2 {ownnick $nicktrunc}}$1"; - own_msg_channel = "$nickalign{ownmsgnick $3 {ownnick $nicktrunc}{msgchannel $1}}$2"; - pubmsg_me = "$nickalign{pubmsgmenick $2 {menick $nicktrunc}}$1"; - pubmsg_me_channel = "$nickalign{pubmsgmenick $3 {menick $nicktrunc}{msgchannel $1}}$2"; - pubmsg_hilight = "$nickalign{pubmsghinick $0 $3 $nicktrunc}$2"; - pubmsg_hilight_channel = "$nickalign{pubmsghinick $0 $4 $nicktrunc{msgchannel $2}}$3"; - pubmsg = "$nickalign{pubmsgnick $2 {pubnick $nicktrunc}}$1"; - pubmsg_channel = "$nickalign{pubmsgnick $3 {pubnick $nicktrunc}{msgchannel $1}}$2"; + own_msg = "{ownmsgnick $2 {ownnick $0}}$1"; + own_msg_channel = "{ownmsgnick $3 {ownnick $0}{msgchannel $1}}$2"; + pubmsg_me = "{pubmsgmenick $2 {menick $0}}$1"; + pubmsg_me_channel = "{pubmsgmenick $3 {menick $0}{msgchannel $1}}$2"; + pubmsg_hilight = "{pubmsghinick $0 $3 $1}$2"; + pubmsg_hilight_channel = "{pubmsghinick $0 $4 $1{msgchannel $2}}$3"; + pubmsg = "{pubmsgnick $2 {pubnick $0}}$1"; + pubmsg_channel = "{pubmsgnick $3 {pubnick $0}{msgchannel $1}}$2"; msg_private = "{privmsg $0 $1}$2"; msg_private_query = "{privmsgnick $0}$2";