[2025-08-24 21:25:00] POPRAWKA - nickalign zamiast nickaligned, zwraca tylko padding, działa jak nm2

This commit is contained in:
kofany 2025-08-24 22:36:04 +02:00
commit 9f0d05e573
3 changed files with 47 additions and 53 deletions

View file

@ -317,6 +317,7 @@ settings = {
window_auto_change = "yes"; window_auto_change = "yes";
print_active_channel = "yes"; print_active_channel = "yes";
theme = "default.theme"; theme = "default.theme";
nick_column_enabled = "yes";
}; };
"fe-text" = { "fe-text" = {
lag_min_show = "1s"; lag_min_show = "1s";

View file

@ -47,12 +47,32 @@ static char *expando_winname(SERVER_REC *server, void *item, int *free_ret)
return active_win->name; return active_win->name;
} }
/* Nick column aligned - returns padded string with mode and nick */ /* Count only valid nick characters (ignore color codes) */
static char *expando_nickaligned(SERVER_REC *server, void *item, int *free_ret) 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; const char *mode;
char *result;
if (!settings_get_bool("nick_column_enabled") || !nick_context_valid || !current_nick) { if (!settings_get_bool("nick_column_enabled") || !nick_context_valid || !current_nick) {
return ""; return "";
@ -60,49 +80,25 @@ static char *expando_nickaligned(SERVER_REC *server, void *item, int *free_ret)
width = settings_get_int("nick_column_width"); width = settings_get_int("nick_column_width");
mode = current_mode ? current_mode : ""; mode = current_mode ? current_mode : "";
mode_len = strlen(mode);
nick_len = strlen(current_nick);
/* Always reserve 1 space for mode (even if empty) */ /* Zawsze 1 miejsce na mode (nawet spacja) */
available_for_nick = width - 1; 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) { padding = width - total_chars;
/* No mode - use space + nick */ if (padding < 0) {
if (nick_len <= available_for_nick) { padding = 0; /* Nie może być ujemny */
/* 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);
}
}
} }
/* Debug output */ /* Debug output */
if (settings_get_bool("debug_nick_column")) { if (settings_get_bool("debug_nick_column")) {
printf("DEBUG nickaligned: nick='%s', mode='%s', width=%d, result='%s'\n", printf("DEBUG nickalign: nick='%s', mode='%s', width=%d, mode_chars=%d, nick_chars=%d, padding=%d\n",
current_nick, mode, width, result); current_nick, mode, width, mode_chars, nick_chars, padding);
} }
*free_ret = TRUE; *free_ret = TRUE;
return result; return g_strnfill(padding, ' ');
} }
/* Update nick context for expandos */ /* Update nick context for expandos */
@ -129,7 +125,7 @@ void fe_expandos_init(void)
expando_create("winname", expando_winname, expando_create("winname", expando_winname,
"window changed", EXPANDO_ARG_NONE, "window changed", EXPANDO_ARG_NONE,
"window name changed", EXPANDO_ARG_WINDOW, NULL); "window name changed", EXPANDO_ARG_WINDOW, NULL);
expando_create("nickaligned", expando_nickaligned, expando_create("nickalign", expando_nickalign,
"message public", EXPANDO_ARG_NONE, "message public", EXPANDO_ARG_NONE,
"message own_public", EXPANDO_ARG_NONE, NULL); "message own_public", EXPANDO_ARG_NONE, NULL);
} }
@ -138,5 +134,5 @@ void fe_expandos_deinit(void)
{ {
expando_destroy("winref", expando_winref); expando_destroy("winref", expando_winref);
expando_destroy("winname", expando_winname); expando_destroy("winname", expando_winname);
expando_destroy("nickaligned", expando_nickaligned); expando_destroy("nickalign", expando_nickalign);
} }

View file

@ -115,11 +115,8 @@ abstracts = {
## messages ## messages
## ##
# the basic styling of how to print message # the basic styling of how to print message, $0 = nick mode, $1 = nick
# NICK COLUMN FEATURE: when enabled, uses $nickaligned expando msgnick = "%K<%n$0$1-%K>%n %|";
# Enable with: /SET nick_column_enabled ON
# Configure width: /SET nick_column_width 12
msgnick = "%K<%n$nickaligned%K>%n %|";
# message from you is printed. "msgownnick" specifies the styling of the # message from you is printed. "msgownnick" specifies the styling of the
# nick ($0 part in msgnick) and "ownmsgnick" 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"; # privmsgnick = "%K{msgnick %R$*%K}%n";
# $0 = nick mode, $1 = nick # $0 = nick mode, $1 = nick
ownmsgnick = "{msgnick $0 $1-}"; ownmsgnick = "{msgnick %B$0 $1-}";
ownnick = "%_$*%n"; ownnick = "%_%Y$*%n";
# public message in channel, $0 = nick mode, $1 = nick # public message in channel, $0 = nick mode, $1 = nick
pubmsgnick = "{msgnick $0 $1-}"; pubmsgnick = "{msgnick %M$0%N $1%n }";
pubnick = "%N$*%n"; pubnick = "%G$*%n";
# public message in channel meant for me, $0 = nick mode, $1 = nick # public message in channel meant for me, $0 = nick mode, $1 = nick
pubmsgmenick = "{msgnick $0 $1-}"; pubmsgmenick = "{msgnick $0 $1-}";
@ -309,7 +306,7 @@ abstracts = {
formats = { formats = {
"fe-common/core" = { "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_channel = "{ownmsgnick $3 {ownnick $0}{msgchannel $1}}$2";
own_msg_private = "{ownprivmsg msg $0}$1"; own_msg_private = "{ownprivmsg msg $0}$1";
own_msg_private_query = "{ownprivmsgnick {ownprivnick $2}}$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_me_channel = "{pubmsgmenick $3 {menick $0}{msgchannel $1}}$2";
pubmsg_hilight = "{pubmsghinick $0 $3 $1}$2"; pubmsg_hilight = "{pubmsghinick $0 $3 $1}$2";
pubmsg_hilight_channel = "{pubmsghinick $0 $4 $1{msgchannel $2}}$3"; 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"; pubmsg_channel = "{pubmsgnick $3 {pubnick $0}{msgchannel $1}}$2";
msg_private = "{privmsg $0 $1}$2"; msg_private = "{privmsg $0 $1}$2";
msg_private_query = "{privmsgnick $0}$2"; msg_private_query = "{privmsgnick $0}$2";