mirror of
https://github.com/irssi/irssi.git
synced 2024-12-04 14:46:39 -05:00
Some fixes for handling %n
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@792 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
parent
000ba23aa7
commit
1541257ac7
@ -1,5 +1,7 @@
|
||||
# these characters are automatically replaced with specified color
|
||||
replaces = { "[]<>=" = "%K$0-%n"; };
|
||||
replaces = {
|
||||
"[]<>=" = "%K$0-%n";
|
||||
};
|
||||
|
||||
# %n specifies the color set in higher level, like in
|
||||
# {ctcp {nick $0-} requested ... }
|
||||
@ -7,7 +9,7 @@ replaces = { "[]<>=" = "%K$0-%n"; };
|
||||
# "requested" text would be green
|
||||
|
||||
abstracts = {
|
||||
# generic
|
||||
# generic
|
||||
line_start = "%B-%W!%B-%n";
|
||||
hilight = "%_$0-%_";
|
||||
|
||||
@ -16,7 +18,7 @@ abstracts = {
|
||||
server = "%_$0-%_";
|
||||
reason = "[$0-]";
|
||||
|
||||
# channel specific messages
|
||||
# channel specific messages
|
||||
channick_hilight = "%C$0-%n";
|
||||
chanhost_hilight = "[%c$0-%n]";
|
||||
channick = "%c$0-%n";
|
||||
@ -24,24 +26,24 @@ abstracts = {
|
||||
channelhilight = "%c$0-%n";
|
||||
ban = "%c$0-%n";
|
||||
|
||||
# messages
|
||||
# messages
|
||||
msgnick = "<$0-> %|";
|
||||
msgownnick = "%W$0-%n";
|
||||
msgchannel = "%K:%c$0-%n";
|
||||
msgme = "%Y$0-%n";
|
||||
privmsgnick = "[%R$0-%n] ";
|
||||
privmsgnick = "[%R$0-%n] "
|
||||
privmsghost = "%K(%r$0-%K)%n";
|
||||
ownprivmsg = "[%r$0-%n] ";
|
||||
ownprivmsgdest = "%K(%R$0-%K)";
|
||||
|
||||
# actions
|
||||
# actions
|
||||
action = "%W * $0-%n ";
|
||||
ownaction = "{action $0-}";
|
||||
pvtaction = "%W (*) $0-%n ";
|
||||
pvtaction_query = "{action $0-}";
|
||||
pubaction = "{action $0-}";
|
||||
|
||||
# notices
|
||||
# notices
|
||||
ownnotice = "[%r$0-]%n ";
|
||||
ownnotice_target = "%K(%R$0-%K)";
|
||||
notice = "%K-%M$0-%K-%n ";
|
||||
@ -49,37 +51,37 @@ abstracts = {
|
||||
pvtnotice_nick = "%K(%m$0-%K)";
|
||||
servernotice = "%g!$0-%n ";
|
||||
|
||||
# ctcp
|
||||
# ctcp
|
||||
ownctcp = "[%r$0-] ";
|
||||
ownctcp_target = "K(%R$0-%K)";
|
||||
ownctcp_target = "%K(%R$0-%K)";
|
||||
ctcp = "%g$0-%n";
|
||||
|
||||
# wall
|
||||
# wall
|
||||
ownwall = "[%W$0-] ";
|
||||
ownwall_channel = "%K/%c$0-";
|
||||
|
||||
# wallops
|
||||
# wallops
|
||||
wallop = "%W$0-%n: ";
|
||||
wallop_nick = "%n$0-";
|
||||
wallop_action = "%W * $0-%n ";
|
||||
|
||||
# netsplits
|
||||
# netsplits
|
||||
netsplit = "%G$0-%n";
|
||||
netjoin = "%C$0-%n";
|
||||
|
||||
# /names list
|
||||
# /names list
|
||||
names_nickstat = "%_$0-%_";
|
||||
names_users = "[%g$0-%n]";
|
||||
names_channel = "%G$0-%n";
|
||||
|
||||
# dcc
|
||||
# dcc
|
||||
dcc = "%g$0-%n";
|
||||
dccfile = "%_$0-%_";
|
||||
|
||||
dccownmsg = "[%r$0-%n] ";
|
||||
dccownnick = "%K(%R$1%K)%n";
|
||||
dccownaction = "{action $0-}";
|
||||
dccmsg = "[%G$0-%n] ";
|
||||
dccmsg = "[%G$0-%n] "
|
||||
dccmsghost = "%K(%g$0-%K)%n";
|
||||
dccquerynick = "%G$0-%n";
|
||||
dccaction = "%W (*dcc*) $0-%n %|";
|
||||
@ -381,7 +383,7 @@ formats = {
|
||||
notify_join = "{nick $0} [$1@$2] [{hilight $3}] has joined to $4";
|
||||
notify_part = "{nick $0} has left $4";
|
||||
notify_away = "{nick $0} [$5] [$1@$2] [{hilight $3}] is now away: $4";
|
||||
notify_unaway = "{nick $0} [$4] [$1@$2] [{hilight $3}] is now unaway";
|
||||
notify_unaway = "{nick $0} [$4] [$1@$2] [{hilight $3}] is now unaway"
|
||||
notify_unidle = "{nick $0} [$5] [$1@$2] [{hilight $3}] just stopped idling";
|
||||
notify_online = "On $0: {hilight $1}";
|
||||
notify_offline = "Offline: $0";
|
||||
|
@ -99,7 +99,9 @@ void theme_destroy(THEME_REC *rec)
|
||||
}
|
||||
|
||||
static char *theme_format_expand_data(THEME_REC *theme,
|
||||
const char **format, int root);
|
||||
const char **format,
|
||||
char default_color,
|
||||
char *before_arg_color, int root);
|
||||
|
||||
static int theme_replace_find(THEME_REC *theme, char chr)
|
||||
{
|
||||
@ -115,26 +117,48 @@ static int theme_replace_find(THEME_REC *theme, char chr)
|
||||
return -1;
|
||||
}
|
||||
|
||||
static char *theme_replace_expand(THEME_REC *theme, int index, char chr)
|
||||
static char *theme_replace_expand(THEME_REC *theme, int index,
|
||||
char default_color, char chr)
|
||||
{
|
||||
GSList *rec;
|
||||
char data[2];
|
||||
char *ret, *abstract, data[2];
|
||||
|
||||
rec = g_slist_nth(theme->replace_values, index);
|
||||
g_return_val_if_fail(rec != NULL, NULL);
|
||||
|
||||
data[0] = chr; data[1] = '\0';
|
||||
return parse_special_string(rec->data, NULL, NULL, data, NULL);
|
||||
|
||||
abstract = rec->data;
|
||||
abstract = theme_format_expand_data(theme, (const char **) &abstract,
|
||||
default_color, NULL, FALSE);
|
||||
ret = parse_special_string(abstract, NULL, NULL, data, NULL);
|
||||
g_free(abstract);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* append next "item", either a character or $variable */
|
||||
static const char *colorformats = "n01234567krgybmpcwKRGYBMPCW";
|
||||
|
||||
#define IS_COLOR_FORMAT(c) \
|
||||
(strchr(colorformats, c) != NULL)
|
||||
|
||||
/* append next "item", either a character, $variable or %format */
|
||||
static void theme_format_append_next(THEME_REC *theme, GString *str,
|
||||
const char **format)
|
||||
const char **format,
|
||||
char default_color, char *last_color)
|
||||
{
|
||||
int index;
|
||||
char *value;
|
||||
char *value, chr;
|
||||
|
||||
if (**format == '$') {
|
||||
chr = **format;
|
||||
if ((chr == '$' || chr == '%') &&
|
||||
(*format)[1] == '\0') {
|
||||
/* last char, always append */
|
||||
g_string_append_c(str, chr);
|
||||
(*format)++;
|
||||
return;
|
||||
}
|
||||
|
||||
if (chr == '$') {
|
||||
/* $variable .. we'll always need to skip this, since it
|
||||
may contain characters that are in replace chars. */
|
||||
const char *orig;
|
||||
@ -143,6 +167,7 @@ static void theme_format_append_next(THEME_REC *theme, GString *str,
|
||||
|
||||
orig = *format;
|
||||
(*format)++;
|
||||
|
||||
value = parse_special((char **) format, NULL, NULL,
|
||||
args, &free_ret, NULL );
|
||||
if (free_ret) g_free(value);
|
||||
@ -155,11 +180,31 @@ static void theme_format_append_next(THEME_REC *theme, GString *str,
|
||||
return;
|
||||
}
|
||||
|
||||
index = theme_replace_find(theme, **format);
|
||||
if (**format == '%') {
|
||||
/* format */
|
||||
(*format)++;
|
||||
if (**format != '{' && **format != '}') {
|
||||
chr = **format;
|
||||
if (**format == 'n')
|
||||
chr = default_color;
|
||||
|
||||
if (IS_COLOR_FORMAT(chr))
|
||||
*last_color = chr;
|
||||
g_string_append_c(str, '%');
|
||||
g_string_append_c(str, chr);
|
||||
(*format)++;
|
||||
return;
|
||||
}
|
||||
|
||||
/* %{ or %} gives us { or } char */
|
||||
chr = **format;
|
||||
}
|
||||
|
||||
index = theme_replace_find(theme, chr);
|
||||
if (index == -1)
|
||||
g_string_append_c(str, **format);
|
||||
g_string_append_c(str, chr);
|
||||
else {
|
||||
value = theme_replace_expand(theme, index, **format);
|
||||
value = theme_replace_expand(theme, index, default_color, chr);
|
||||
g_string_append(str, value);
|
||||
g_free(value);
|
||||
}
|
||||
@ -169,7 +214,8 @@ static void theme_format_append_next(THEME_REC *theme, GString *str,
|
||||
|
||||
/* expand a single {abstract ...data... } */
|
||||
static char *theme_format_expand_abstract(THEME_REC *theme,
|
||||
const char **formatp)
|
||||
const char **formatp,
|
||||
char default_color)
|
||||
{
|
||||
const char *p, *format;
|
||||
char *abstract, *data, *ret;
|
||||
@ -202,12 +248,14 @@ static char *theme_format_expand_abstract(THEME_REC *theme,
|
||||
|
||||
/* abstract may itself contain abstracts or replaces :) */
|
||||
p = data = abstract;
|
||||
abstract = theme_format_expand_data(theme, &p, FALSE);
|
||||
abstract = theme_format_expand_data(theme, &p, default_color,
|
||||
&default_color, FALSE);
|
||||
g_free(data);
|
||||
|
||||
/* now we'll need to get the data part. it may contain
|
||||
more abstracts, they are automatically expanded. */
|
||||
data = theme_format_expand_data(theme, formatp, FALSE);
|
||||
data = theme_format_expand_data(theme, formatp, default_color,
|
||||
NULL, FALSE);
|
||||
|
||||
ret = parse_special_string(abstract, NULL, NULL, data, NULL);
|
||||
g_free(abstract);
|
||||
@ -218,10 +266,13 @@ static char *theme_format_expand_abstract(THEME_REC *theme,
|
||||
/* expand the data part in {abstract data}. If root is TRUE, we're actually
|
||||
expanding the original format string so we ignore all extra } chars. */
|
||||
static char *theme_format_expand_data(THEME_REC *theme,
|
||||
const char **format, int root)
|
||||
const char **format,
|
||||
char default_color,
|
||||
char *before_arg_color, int root)
|
||||
{
|
||||
GString *str;
|
||||
char *ret, *abstract;
|
||||
char last_color = default_color;
|
||||
|
||||
str = g_string_new(NULL);
|
||||
|
||||
@ -232,7 +283,16 @@ static char *theme_format_expand_data(THEME_REC *theme,
|
||||
}
|
||||
|
||||
if (**format != '{') {
|
||||
theme_format_append_next(theme, str, format);
|
||||
if (before_arg_color != NULL &&
|
||||
**format == '$' && (*format)[1] == '0') {
|
||||
/* save the color before $0 ..
|
||||
this is for the %n replacing */
|
||||
*before_arg_color = last_color;
|
||||
before_arg_color = NULL;
|
||||
}
|
||||
|
||||
theme_format_append_next(theme, str, format,
|
||||
default_color, &last_color);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -241,7 +301,8 @@ static char *theme_format_expand_data(THEME_REC *theme,
|
||||
break; /* error */
|
||||
|
||||
/* get a single {...} */
|
||||
abstract = theme_format_expand_abstract(theme, format);
|
||||
abstract = theme_format_expand_abstract(theme, format,
|
||||
last_color);
|
||||
if (abstract != NULL) {
|
||||
g_string_append(str, abstract);
|
||||
g_free(abstract);
|
||||
@ -258,7 +319,7 @@ static char *theme_format_expand(THEME_REC *theme, const char *format)
|
||||
g_return_val_if_fail(theme != NULL, NULL);
|
||||
g_return_val_if_fail(format != NULL, NULL);
|
||||
|
||||
return theme_format_expand_data(theme, &format, TRUE);
|
||||
return theme_format_expand_data(theme, &format, 'n', NULL, TRUE);
|
||||
}
|
||||
|
||||
static MODULE_THEME_REC *theme_module_create(THEME_REC *theme, const char *module)
|
||||
|
Loading…
Reference in New Issue
Block a user