mirror of
https://github.com/irssi/irssi.git
synced 2026-08-08 19:30:15 +02:00
Implement automatic nick column formatting 'on-the-fly'
Major improvement: No theme modification required!
Features:
- When nick_column_enabled=OFF: Normal theme behavior
- When nick_column_enabled=ON: Automatic formatting applied
Changes:
1. Enhanced expandos to handle OFF state:
- expando_nickalign() returns '' when disabled
- expando_nicktrunc() returns original nick when disabled
2. Added automatic format modification in format_get_text_theme_charargs():
- Detects message formats (own_msg, pubmsg, etc.)
- Automatically adds $nickalign prefix
- Replaces {ownnick $0} with {ownnick $nicktrunc}
- Replaces {pubnick $0} with {pubnick $nicktrunc}
- Replaces {menick $0} with {menick $nicktrunc}
3. Restored original theme format:
- own_msg = '{ownmsgnick $2 {ownnick $0}}$1'
- No manual $nickalign/$nicktrunc needed
Result: Clean theme compatibility + automatic nick column when enabled
Timestamp: 2025-01-25 00:20
This commit is contained in:
parent
cf9af2298e
commit
ad0d88b123
3 changed files with 103 additions and 12 deletions
|
|
@ -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 : "";
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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";
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue