From 9f0d05e5735f9dfc9314d3c094aa5952f6ccc94e Mon Sep 17 00:00:00 2001 From: kofany Date: Sun, 24 Aug 2025 22:36:04 +0200 Subject: [PATCH] =?UTF-8?q?[2025-08-24=2021:25:00]=20POPRAWKA=20-=20nickal?= =?UTF-8?q?ign=20zamiast=20nickaligned,=20zwraca=20tylko=20padding,=20dzia?= =?UTF-8?q?=C5=82a=20jak=20nm2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config_dev | 1 + src/fe-common/core/fe-expandos.c | 76 +++++++++++++++----------------- themes/default.theme | 19 ++++---- 3 files changed, 45 insertions(+), 51 deletions(-) diff --git a/config_dev b/config_dev index 1dbe0825..e584e82d 100644 --- a/config_dev +++ b/config_dev @@ -317,6 +317,7 @@ settings = { window_auto_change = "yes"; print_active_channel = "yes"; theme = "default.theme"; + nick_column_enabled = "yes"; }; "fe-text" = { lag_min_show = "1s"; diff --git a/src/fe-common/core/fe-expandos.c b/src/fe-common/core/fe-expandos.c index 93069d10..3d201f66 100644 --- a/src/fe-common/core/fe-expandos.c +++ b/src/fe-common/core/fe-expandos.c @@ -47,12 +47,32 @@ static char *expando_winname(SERVER_REC *server, void *item, int *free_ret) return active_win->name; } -/* Nick column aligned - returns padded string with mode and nick */ -static char *expando_nickaligned(SERVER_REC *server, void *item, int *free_ret) +/* Count only valid nick characters (ignore color codes) */ +static int count_nick_chars(const char *str) { - int width, mode_len, nick_len, available_for_nick; + int count = 0; + if (!str) return 0; + + for (const char *p = str; *p; p++) { + /* Alfanumeryczne */ + if (isalnum(*p)) { + count++; + } + /* Specjalne znaki nicka */ + else if (*p == '-' || *p == '[' || *p == ']' || *p == '\\' || + *p == '`' || *p == '^' || *p == '{' || *p == '}') { + count++; + } + /* Ignoruje kody kolorów %B %N %Y %n itp. */ + } + return count; +} + +/* Nick column align - returns only padding spaces */ +static char *expando_nickalign(SERVER_REC *server, void *item, int *free_ret) +{ + int width, mode_chars, nick_chars, total_chars, padding; const char *mode; - char *result; if (!settings_get_bool("nick_column_enabled") || !nick_context_valid || !current_nick) { return ""; @@ -60,49 +80,25 @@ static char *expando_nickaligned(SERVER_REC *server, void *item, int *free_ret) width = settings_get_int("nick_column_width"); mode = current_mode ? current_mode : ""; - mode_len = strlen(mode); - nick_len = strlen(current_nick); - /* Always reserve 1 space for mode (even if empty) */ - available_for_nick = width - 1; + /* Zawsze 1 miejsce na mode (nawet spacja) */ + mode_chars = strlen(mode) > 0 ? strlen(mode) : 1; + nick_chars = count_nick_chars(current_nick); + total_chars = mode_chars + nick_chars; - if (mode_len == 0) { - /* No mode - use space + nick */ - if (nick_len <= available_for_nick) { - /* Nick fits - pad from left */ - int padding = width - 1 - nick_len; /* -1 for space */ - result = g_strdup_printf("%*s %s", padding, "", current_nick); - } else { - /* Nick too long - truncate with >> */ - result = g_strdup_printf(" %.*s>>", available_for_nick - 2, current_nick); - } - } else { - /* Has mode */ - int total_len = mode_len + nick_len; - if (total_len <= width) { - /* Mode + nick fits - pad from left */ - int padding = width - total_len; - result = g_strdup_printf("%*s%s%s", padding, "", mode, current_nick); - } else { - /* Too long - truncate nick with >> */ - int available_for_nick_with_mode = width - mode_len - 2; /* -2 for >> */ - if (available_for_nick_with_mode > 0) { - result = g_strdup_printf("%s%.*s>>", mode, available_for_nick_with_mode, current_nick); - } else { - /* Mode itself too long */ - result = g_strdup_printf("%.*s>>", width - 2, mode); - } - } + padding = width - total_chars; + if (padding < 0) { + padding = 0; /* Nie może być ujemny */ } /* Debug output */ if (settings_get_bool("debug_nick_column")) { - printf("DEBUG nickaligned: nick='%s', mode='%s', width=%d, result='%s'\n", - current_nick, mode, width, result); + printf("DEBUG nickalign: nick='%s', mode='%s', width=%d, mode_chars=%d, nick_chars=%d, padding=%d\n", + current_nick, mode, width, mode_chars, nick_chars, padding); } *free_ret = TRUE; - return result; + return g_strnfill(padding, ' '); } /* Update nick context for expandos */ @@ -129,7 +125,7 @@ void fe_expandos_init(void) expando_create("winname", expando_winname, "window changed", EXPANDO_ARG_NONE, "window name changed", EXPANDO_ARG_WINDOW, NULL); - expando_create("nickaligned", expando_nickaligned, + expando_create("nickalign", expando_nickalign, "message public", EXPANDO_ARG_NONE, "message own_public", EXPANDO_ARG_NONE, NULL); } @@ -138,5 +134,5 @@ void fe_expandos_deinit(void) { expando_destroy("winref", expando_winref); expando_destroy("winname", expando_winname); - expando_destroy("nickaligned", expando_nickaligned); + expando_destroy("nickalign", expando_nickalign); } diff --git a/themes/default.theme b/themes/default.theme index 6c079b63..72afa258 100644 --- a/themes/default.theme +++ b/themes/default.theme @@ -115,11 +115,8 @@ abstracts = { ## messages ## - # the basic styling of how to print message - # NICK COLUMN FEATURE: when enabled, uses $nickaligned expando - # Enable with: /SET nick_column_enabled ON - # Configure width: /SET nick_column_width 12 - msgnick = "%K<%n$nickaligned%K>%n %|"; + # the basic styling of how to print message, $0 = nick mode, $1 = nick + msgnick = "%K<%n$0$1-%K>%n %|"; # message from you is printed. "msgownnick" specifies the styling of the # nick ($0 part in msgnick) and "ownmsgnick" specifies the styling of the @@ -138,12 +135,12 @@ abstracts = { # privmsgnick = "%K{msgnick %R$*%K}%n"; # $0 = nick mode, $1 = nick - ownmsgnick = "{msgnick $0 $1-}"; - ownnick = "%_$*%n"; + ownmsgnick = "{msgnick %B$0 $1-}"; + ownnick = "%_%Y$*%n"; # public message in channel, $0 = nick mode, $1 = nick - pubmsgnick = "{msgnick $0 $1-}"; - pubnick = "%N$*%n"; + pubmsgnick = "{msgnick %M$0%N $1%n }"; + pubnick = "%G$*%n"; # public message in channel meant for me, $0 = nick mode, $1 = nick pubmsgmenick = "{msgnick $0 $1-}"; @@ -309,7 +306,7 @@ abstracts = { formats = { "fe-common/core" = { - own_msg = "{ownmsgnick $2 {ownnick $0}}$1"; + own_msg = "$nickalign{ownmsgnick $2 {ownnick $0}}$1"; own_msg_channel = "{ownmsgnick $3 {ownnick $0}{msgchannel $1}}$2"; own_msg_private = "{ownprivmsg msg $0}$1"; own_msg_private_query = "{ownprivmsgnick {ownprivnick $2}}$1"; @@ -317,7 +314,7 @@ formats = { 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 = "$nickalign{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";