1
0
mirror of https://github.com/irssi/irssi.git synced 2024-12-04 14:46:39 -05:00

/SET prompt, /SET prompt_window - Specifies the text in prompt.

'prompt' is used when channel or query is active in window and
'prompt_window' is used with empty windows.


git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1005 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
Timo Sirainen 2000-12-17 07:39:22 +00:00 committed by cras
parent aac80846b8
commit bbc33bff5e
17 changed files with 294 additions and 74 deletions

View File

@ -81,7 +81,7 @@ static void cmd_msg(const char *data, SERVER_REC *server, WI_ITEM_REC *item)
free_ret = FALSE; free_ret = FALSE;
if (strcmp(target, ",") == 0 || strcmp(target, ".") == 0) { if (strcmp(target, ",") == 0 || strcmp(target, ".") == 0) {
target = parse_special(&target, server, item, target = parse_special(&target, server, item,
NULL, &free_ret, NULL); NULL, &free_ret, NULL, 0);
} else if (strcmp(target, "*") == 0 && item != NULL) } else if (strcmp(target, "*") == 0 && item != NULL)
target = item->name; target = item->name;

View File

@ -44,6 +44,8 @@ typedef struct {
int signal_args[MAX_EXPANDO_SIGNALS]; int signal_args[MAX_EXPANDO_SIGNALS];
} EXPANDO_REC; } EXPANDO_REC;
static int timer_tag;
static EXPANDO_REC *char_expandos[127]; static EXPANDO_REC *char_expandos[127];
static GHashTable *expandos; static GHashTable *expandos;
static time_t client_start_time; static time_t client_start_time;
@ -86,6 +88,14 @@ void expando_create(const char *key, EXPANDO_FUNC func, ...)
va_end(va); va_end(va);
} }
static EXPANDO_REC *expando_find(const char *key)
{
if (key[1] != '\0')
return g_hash_table_lookup(expandos, key);
else
return char_expandos[(int) *key];
}
/* Add new signal to expando */ /* Add new signal to expando */
void expando_add_signal(const char *key, const char *signal, ExpandoArg arg) void expando_add_signal(const char *key, const char *signal, ExpandoArg arg)
{ {
@ -94,15 +104,15 @@ void expando_add_signal(const char *key, const char *signal, ExpandoArg arg)
g_return_if_fail(key != NULL); g_return_if_fail(key != NULL);
g_return_if_fail(signal != NULL); g_return_if_fail(signal != NULL);
if (key[1] != '\0') rec = expando_find(key);
rec = g_hash_table_lookup(expandos, key);
else {
/* single character expando */
rec = char_expandos[(int) *key];
}
g_return_if_fail(rec != NULL); g_return_if_fail(rec != NULL);
if (rec->signals < MAX_EXPANDO_SIGNALS) { if (arg == EXPANDO_NEVER) {
/* expando changes never */
rec->signals = -1;
} else if (rec->signals < MAX_EXPANDO_SIGNALS) {
g_return_if_fail(rec->signals != -1);
rec->signal_ids[rec->signals] = signal_get_uniq_id(signal); rec->signal_ids[rec->signals] = signal_get_uniq_id(signal);
rec->signal_args[rec->signals] = arg; rec->signal_args[rec->signals] = arg;
rec->signals++; rec->signals++;
@ -135,6 +145,64 @@ void expando_destroy(const char *key, EXPANDO_FUNC func)
} }
} }
void expando_bind(const char *key, int funccount, SIGNAL_FUNC *funcs)
{
SIGNAL_FUNC func;
EXPANDO_REC *rec;
int n, arg;
g_return_if_fail(key != NULL);
g_return_if_fail(funccount >= 1);
g_return_if_fail(funcs != NULL);
g_return_if_fail(funcs[0] != NULL);
rec = expando_find(key);
g_return_if_fail(rec != NULL);
if (rec->signals == 0) {
/* it's unknown when this expando changes..
check it once in a second */
signal_add("expando timer", funcs[EXPANDO_ARG_NONE]);
}
for (n = 0; n < rec->signals; n++) {
arg = rec->signal_args[n];
func = arg < funccount ? funcs[arg] : NULL;
if (func == NULL) func = funcs[EXPANDO_ARG_NONE];
signal_add_to_id(MODULE_NAME, 1, rec->signal_ids[n], func);
}
}
void expando_unbind(const char *key, int funccount, SIGNAL_FUNC *funcs)
{
SIGNAL_FUNC func;
EXPANDO_REC *rec;
int n, arg;
g_return_if_fail(key != NULL);
g_return_if_fail(funccount >= 1);
g_return_if_fail(funcs != NULL);
g_return_if_fail(funcs[0] != NULL);
rec = expando_find(key);
g_return_if_fail(rec != NULL);
if (rec->signals == 0) {
/* it's unknown when this expando changes..
check it once in a second */
signal_remove("expando timer", funcs[EXPANDO_ARG_NONE]);
}
for (n = 0; n < rec->signals; n++) {
arg = rec->signal_args[n];
func = arg < funccount ? funcs[arg] : NULL;
if (func == NULL) func = funcs[EXPANDO_ARG_NONE];
signal_remove_id(rec->signal_ids[n], func);
}
}
EXPANDO_FUNC expando_find_char(char chr) EXPANDO_FUNC expando_find_char(char chr)
{ {
g_return_val_if_fail(chr < sizeof(char_expandos) / g_return_val_if_fail(chr < sizeof(char_expandos) /
@ -360,6 +428,12 @@ static void cmd_msg(const char *data, SERVER_REC *server)
cmd_params_free(free_arg); cmd_params_free(free_arg);
} }
static int sig_timer(void)
{
signal_emit("expando timer", 0);
return 1;
}
void expandos_init(void) void expandos_init(void)
{ {
#ifdef HAVE_SYS_UTSNAME_H #ifdef HAVE_SYS_UTSNAME_H
@ -455,6 +529,7 @@ void expandos_init(void)
"window changed", EXPANDO_ARG_NONE, "window changed", EXPANDO_ARG_NONE,
"window server changed", EXPANDO_ARG_WINDOW, NULL); "window server changed", EXPANDO_ARG_WINDOW, NULL);
timer_tag = g_timeout_add(1000, (GSourceFunc) sig_timer, NULL);
signal_add("command msg", (SIGNAL_FUNC) cmd_msg); signal_add("command msg", (SIGNAL_FUNC) cmd_msg);
signal_add("message public", (SIGNAL_FUNC) sig_message_public); signal_add("message public", (SIGNAL_FUNC) sig_message_public);
signal_add("message private", (SIGNAL_FUNC) sig_message_private); signal_add("message private", (SIGNAL_FUNC) sig_message_private);
@ -479,6 +554,7 @@ void expandos_deinit(void)
g_free_not_null(last_privmsg_from); g_free_not_null(last_public_from); g_free_not_null(last_privmsg_from); g_free_not_null(last_public_from);
g_free_not_null(sysname); g_free_not_null(sysrelease); g_free_not_null(sysname); g_free_not_null(sysrelease);
g_source_remove(timer_tag);
signal_remove("message public", (SIGNAL_FUNC) sig_message_public); signal_remove("message public", (SIGNAL_FUNC) sig_message_public);
signal_remove("message private", (SIGNAL_FUNC) sig_message_private); signal_remove("message private", (SIGNAL_FUNC) sig_message_private);
signal_remove("command msg", (SIGNAL_FUNC) cmd_msg); signal_remove("command msg", (SIGNAL_FUNC) cmd_msg);

View File

@ -1,6 +1,7 @@
#ifndef __EXPANDOS_H #ifndef __EXPANDOS_H
#define __EXPANDOS_H #define __EXPANDOS_H
#include "signals.h"
#include "servers.h" #include "servers.h"
/* first argument of signal must match to active .. */ /* first argument of signal must match to active .. */
@ -25,6 +26,9 @@ void expando_add_signal(const char *key, const char *signal, ExpandoArg arg);
/* Destroy expando */ /* Destroy expando */
void expando_destroy(const char *key, EXPANDO_FUNC func); void expando_destroy(const char *key, EXPANDO_FUNC func);
void expando_bind(const char *key, int funccount, SIGNAL_FUNC *funcs);
void expando_unbind(const char *key, int funccount, SIGNAL_FUNC *funcs);
/* internal: */ /* internal: */
EXPANDO_FUNC expando_find_char(char chr); EXPANDO_FUNC expando_find_char(char chr);
EXPANDO_FUNC expando_find_long(const char *key); EXPANDO_FUNC expando_find_long(const char *key);

View File

@ -146,25 +146,24 @@ static int signal_remove_from_lists(SIGNAL_REC *rec, int signal_id,
return 0; return 0;
} }
void signal_remove_id(int signal_id, SIGNAL_FUNC func)
{
SIGNAL_REC *rec;
g_return_if_fail(signal_id >= 0);
g_return_if_fail(func != NULL);
rec = g_hash_table_lookup(signals, GINT_TO_POINTER(signal_id));
if (rec != NULL)
signal_remove_from_lists(rec, signal_id, func);
}
/* unbind signal */ /* unbind signal */
void signal_remove(const char *signal, SIGNAL_FUNC func) void signal_remove(const char *signal, SIGNAL_FUNC func)
{ {
SIGNAL_REC *rec;
int signal_id, found;
g_return_if_fail(signal != NULL); g_return_if_fail(signal != NULL);
g_return_if_fail(func != NULL);
signal_id = signal_get_uniq_id(signal); signal_remove_id(signal_get_uniq_id(signal), func);
rec = g_hash_table_lookup(signals, GINT_TO_POINTER(signal_id));
found = rec == NULL ? 0 :
signal_remove_from_lists(rec, signal_id, func);
if (!found) {
g_warning("signal_remove() : signal \"%s\" isn't "
"grabbed for %p", signal, func);
}
} }
/* Remove all NULL functions from signal list */ /* Remove all NULL functions from signal list */

View File

@ -23,6 +23,7 @@ void signal_add_to_id(const char *module, int pos,
/* unbind signal */ /* unbind signal */
void signal_remove(const char *signal, SIGNAL_FUNC func); void signal_remove(const char *signal, SIGNAL_FUNC func);
void signal_remove_id(int signal_id, SIGNAL_FUNC func);
/* emit signal */ /* emit signal */
int signal_emit(const char *signal, int params, ...); int signal_emit(const char *signal, int params, ...);

View File

@ -125,7 +125,7 @@ static char *get_long_variable_value(const char *key, SERVER_REC *server,
} }
static char *get_long_variable(char **cmd, SERVER_REC *server, static char *get_long_variable(char **cmd, SERVER_REC *server,
void *item, int *free_ret) void *item, int *free_ret, int getname)
{ {
char *start, *var, *ret; char *start, *var, *ret;
@ -134,14 +134,20 @@ static char *get_long_variable(char **cmd, SERVER_REC *server,
while (isvarchar((*cmd)[1])) (*cmd)++; while (isvarchar((*cmd)[1])) (*cmd)++;
var = g_strndup(start, (int) (*cmd-start)+1); var = g_strndup(start, (int) (*cmd-start)+1);
if (getname) {
*free_ret = TRUE;
return var;
}
ret = get_long_variable_value(var, server, item, free_ret); ret = get_long_variable_value(var, server, item, free_ret);
g_free(var); g_free(var);
return ret; return ret;
} }
/* return the value of the variable found from `cmd' */ /* return the value of the variable found from `cmd'.
if 'getname' is TRUE, return the name of the variable instead it's value */
static char *get_variable(char **cmd, SERVER_REC *server, void *item, static char *get_variable(char **cmd, SERVER_REC *server, void *item,
char **arglist, int *free_ret, int *arg_used) char **arglist, int *free_ret, int *arg_used,
int getname)
{ {
EXPANDO_FUNC func; EXPANDO_FUNC func;
@ -149,15 +155,20 @@ static char *get_variable(char **cmd, SERVER_REC *server, void *item,
/* argument */ /* argument */
*free_ret = TRUE; *free_ret = TRUE;
if (arg_used != NULL) *arg_used = TRUE; if (arg_used != NULL) *arg_used = TRUE;
return get_argument(cmd, arglist); return getname ? g_strdup_printf("%c", **cmd) :
get_argument(cmd, arglist);
} }
if (isalpha(**cmd) && isvarchar((*cmd)[1])) { if (isalpha(**cmd) && isvarchar((*cmd)[1])) {
/* long variable name.. */ /* long variable name.. */
return get_long_variable(cmd, server, item, free_ret); return get_long_variable(cmd, server, item, free_ret, getname);
} }
/* single character variable. */ /* single character variable. */
if (getname) {
*free_ret = TRUE;
return g_strdup_printf("%c", **cmd);
}
*free_ret = FALSE; *free_ret = FALSE;
func = expando_find_char(**cmd); func = expando_find_char(**cmd);
return func == NULL ? NULL : func(server, item, free_ret); return func == NULL ? NULL : func(server, item, free_ret);
@ -184,13 +195,17 @@ static char *get_history(char **cmd, void *item, int *free_ret)
} }
static char *get_special_value(char **cmd, SERVER_REC *server, void *item, static char *get_special_value(char **cmd, SERVER_REC *server, void *item,
char **arglist, int *free_ret, int *arg_used) char **arglist, int *free_ret, int *arg_used,
int flags)
{ {
char command, *value, *p; char command, *value, *p;
int len; int len;
if (**cmd == '!') { if (**cmd == '!') {
/* find text from command history */ /* find text from command history */
if (flags & PARSE_FLAG_GETNAME)
return "!";
return get_history(cmd, item, free_ret); return get_history(cmd, item, free_ret);
} }
@ -203,12 +218,19 @@ static char *get_special_value(char **cmd, SERVER_REC *server, void *item,
/* default to $* */ /* default to $* */
char *temp_cmd = "*"; char *temp_cmd = "*";
if (flags & PARSE_FLAG_GETNAME)
return "*";
*free_ret = TRUE; *free_ret = TRUE;
return get_argument(&temp_cmd, arglist); return get_argument(&temp_cmd, arglist);
} }
} }
value = get_variable(cmd, server, item, arglist, free_ret, arg_used); value = get_variable(cmd, server, item, arglist, free_ret,
arg_used, flags & PARSE_FLAG_GETNAME);
if (flags & PARSE_FLAG_GETNAME)
return value;
if (command == '#') { if (command == '#') {
/* number of words */ /* number of words */
@ -314,7 +336,7 @@ static char *get_alignment(const char *text, int align, int flags, char pad)
/* Parse and expand text after '$' character. return value has to be /* Parse and expand text after '$' character. return value has to be
g_free()'d if `free_ret' is TRUE. */ g_free()'d if `free_ret' is TRUE. */
char *parse_special(char **cmd, SERVER_REC *server, void *item, char *parse_special(char **cmd, SERVER_REC *server, void *item,
char **arglist, int *free_ret, int *arg_used) char **arglist, int *free_ret, int *arg_used, int flags)
{ {
static char **nested_orig_cmd = NULL; /* FIXME: KLUDGE! */ static char **nested_orig_cmd = NULL; /* FIXME: KLUDGE! */
char command, *value; char command, *value;
@ -355,7 +377,8 @@ char *parse_special(char **cmd, SERVER_REC *server, void *item,
} else { } else {
(*cmd)++; (*cmd)++;
nest_value = parse_special(cmd, server, item, arglist, nest_value = parse_special(cmd, server, item, arglist,
&nest_free, arg_used); &nest_free, arg_used,
flags);
} }
while ((*nested_orig_cmd)[1] != '\0') { while ((*nested_orig_cmd)[1] != '\0') {
@ -377,10 +400,13 @@ char *parse_special(char **cmd, SERVER_REC *server, void *item,
} }
value = get_special_value(cmd, server, item, arglist, value = get_special_value(cmd, server, item, arglist,
free_ret, arg_used); free_ret, arg_used, flags);
if (**cmd == '\0') if (**cmd == '\0')
g_error("parse_special() : buffer overflow!"); g_error("parse_special() : buffer overflow!");
if (value != NULL && *value != '\0' && (flags & PARSE_FLAG_ISSET_ANY))
*arg_used = TRUE;
if (brackets) { if (brackets) {
while (**cmd != '}' && (*cmd)[1] != '\0') while (**cmd != '}' && (*cmd)[1] != '\0')
(*cmd)++; (*cmd)++;
@ -388,7 +414,7 @@ char *parse_special(char **cmd, SERVER_REC *server, void *item,
if (nest_free) g_free(nest_value); if (nest_free) g_free(nest_value);
if (command == '[') { if (command == '[' && (flags & PARSE_FLAG_GETNAME) == 0) {
/* alignment */ /* alignment */
char *p; char *p;
@ -406,7 +432,7 @@ char *parse_special(char **cmd, SERVER_REC *server, void *item,
/* parse the whole string. $ and \ chars are replaced */ /* parse the whole string. $ and \ chars are replaced */
char *parse_special_string(const char *cmd, SERVER_REC *server, void *item, char *parse_special_string(const char *cmd, SERVER_REC *server, void *item,
const char *data, int *arg_used) const char *data, int *arg_used, int flags)
{ {
char code, **arglist, *ret; char code, **arglist, *ret;
GString *str; GString *str;
@ -438,7 +464,8 @@ char *parse_special_string(const char *cmd, SERVER_REC *server, void *item,
char *ret; char *ret;
ret = parse_special((char **) &cmd, server, item, ret = parse_special((char **) &cmd, server, item,
arglist, &need_free, arg_used); arglist, &need_free, arg_used,
flags);
if (ret != NULL) { if (ret != NULL) {
g_string_append(str, ret); g_string_append(str, ret);
if (need_free) g_free(ret); if (need_free) g_free(ret);
@ -488,7 +515,7 @@ void eval_special_string(const char *cmd, const char *data,
} }
ret = parse_special_string(start, server, item, ret = parse_special_string(start, server, item,
data, &arg_used); data, &arg_used, 0);
if (arg_used) arg_used_ever = TRUE; if (arg_used) arg_used_ever = TRUE;
if (strchr(cmdchars, *ret) == NULL) { if (strchr(cmdchars, *ret) == NULL) {
@ -525,3 +552,42 @@ void special_history_func_set(SPECIAL_HISTORY_FUNC func)
{ {
history_func = func; history_func = func;
} }
static void special_vars_signals_do(const char *text, int funccount,
SIGNAL_FUNC *funcs, int bind)
{
char *ret;
int need_free;
while (*text != '\0') {
if (*text == '\\' && text[1] != '\0') {
text += 2;
} else if (*text == '$' && text[1] != '\0') {
text++;
ret = parse_special((char **) &text, NULL, NULL,
NULL, &need_free, NULL,
PARSE_FLAG_GETNAME);
if (ret != NULL) {
if (bind)
expando_bind(ret, funccount, funcs);
else
expando_unbind(ret, funccount, funcs);
if (need_free) g_free(ret);
}
}
else text++;
}
}
void special_vars_add_signals(const char *text,
int funccount, SIGNAL_FUNC *funcs)
{
special_vars_signals_do(text, funccount, funcs, TRUE);
}
void special_vars_remove_signals(const char *text,
int funccount, SIGNAL_FUNC *funcs)
{
special_vars_signals_do(text, funccount, funcs, FALSE);
}

View File

@ -1,19 +1,23 @@
#ifndef __SPECIAL_VARS_H #ifndef __SPECIAL_VARS_H
#define __SPECIAL_VARS_H #define __SPECIAL_VARS_H
#include "signals.h"
#include "servers.h" #include "servers.h"
#define PARSE_FLAG_GETNAME 0x01 /* return argument name instead of it's value */
#define PARSE_FLAG_ISSET_ANY 0x02 /* arg_used field specifies that at least one of the $variables was non-empty */
typedef char* (*SPECIAL_HISTORY_FUNC) typedef char* (*SPECIAL_HISTORY_FUNC)
(const char *text, void *item, int *free_ret); (const char *text, void *item, int *free_ret);
/* Parse and expand text after '$' character. return value has to be /* Parse and expand text after '$' character. return value has to be
g_free()'d if `free_ret' is TRUE. */ g_free()'d if `free_ret' is TRUE. */
char *parse_special(char **cmd, SERVER_REC *server, void *item, char *parse_special(char **cmd, SERVER_REC *server, void *item,
char **arglist, int *free_ret, int *arg_used); char **arglist, int *free_ret, int *arg_used, int flags);
/* parse the whole string. $ and \ chars are replaced */ /* parse the whole string. $ and \ chars are replaced */
char *parse_special_string(const char *cmd, SERVER_REC *server, void *item, char *parse_special_string(const char *cmd, SERVER_REC *server, void *item,
const char *data, int *arg_used); const char *data, int *arg_used, int flags);
/* execute the commands in string - commands can be split with ';' */ /* execute the commands in string - commands can be split with ';' */
void eval_special_string(const char *cmd, const char *data, void eval_special_string(const char *cmd, const char *data,
@ -21,4 +25,9 @@ void eval_special_string(const char *cmd, const char *data,
void special_history_func_set(SPECIAL_HISTORY_FUNC func); void special_history_func_set(SPECIAL_HISTORY_FUNC func);
void special_vars_add_signals(const char *text,
int funccount, SIGNAL_FUNC *funcs);
void special_vars_remove_signals(const char *text,
int funccount, SIGNAL_FUNC *funcs);
#endif #endif

View File

@ -29,13 +29,23 @@ static char *expando_winref(SERVER_REC *server, void *item, int *free_ret)
return g_strdup_printf("%d", active_win->refnum); return g_strdup_printf("%d", active_win->refnum);
} }
/* Window name */
static char *expando_winname(SERVER_REC *server, void *item, int *free_ret)
{
return active_win->name;
}
void fe_expandos_init(void) void fe_expandos_init(void)
{ {
expando_create("winref", expando_winref, expando_create("winref", expando_winref,
"window changed", EXPANDO_ARG_NONE, NULL); "window changed", EXPANDO_ARG_NONE,
"window refnum changed", EXPANDO_ARG_WINDOW, NULL);
expando_create("winname", expando_winname,
"window name changed", EXPANDO_ARG_WINDOW, NULL);
} }
void fe_expandos_deinit(void) void fe_expandos_deinit(void)
{ {
expando_destroy("winref", expando_winref); expando_destroy("winref", expando_winref);
expando_destroy("winname", expando_winname);
} }

View File

@ -350,7 +350,8 @@ static void autolog_open(void *server, const char *target)
return; return;
} }
fname = parse_special_string(autolog_path, server, NULL, target, NULL); fname = parse_special_string(autolog_path, server, NULL,
target, NULL, 0);
if (log_find(fname) == NULL) { if (log_find(fname) == NULL) {
log = log_create_rec(fname, autolog_level); log = log_create_rec(fname, autolog_level);
log_item_add(log, LOG_ITEM_TARGET, target, server); log_item_add(log, LOG_ITEM_TARGET, target, server);

View File

@ -169,7 +169,7 @@ static void cmd_msg(const char *data, SERVER_REC *server, WI_ITEM_REC *item)
if (strcmp(target, ",") == 0 || strcmp(target, ".") == 0) { if (strcmp(target, ",") == 0 || strcmp(target, ".") == 0) {
/* , and . are handled specially */ /* , and . are handled specially */
newtarget = parse_special(&target, server, item, newtarget = parse_special(&target, server, item,
NULL, &free_ret, NULL); NULL, &free_ret, NULL, 0);
if (newtarget == NULL) { if (newtarget == NULL) {
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
*target == ',' ? IRCTXT_NO_MSGS_GOT : *target == ',' ? IRCTXT_NO_MSGS_GOT :

View File

@ -237,8 +237,10 @@ static char *format_get_text_args(TEXT_DEST_REC *dest,
/* argument */ /* argument */
char *ret; char *ret;
ret = parse_special((char **) &text, active_win->active_server, ret = parse_special((char **) &text,
active_win->active, arglist, &need_free, NULL); active_win->active_server,
active_win->active, arglist,
&need_free, NULL, 0);
if (ret != NULL) { if (ret != NULL) {
/* string shouldn't end with \003 or it could /* string shouldn't end with \003 or it could

View File

@ -137,7 +137,7 @@ static char *theme_replace_expand(THEME_REC *theme, int index,
abstract = rec->data; abstract = rec->data;
abstract = theme_format_expand_data(theme, (const char **) &abstract, abstract = theme_format_expand_data(theme, (const char **) &abstract,
default_color, last_color, 0); default_color, last_color, 0);
ret = parse_special_string(abstract, NULL, NULL, data, NULL); ret = parse_special_string(abstract, NULL, NULL, data, NULL, 0);
g_free(abstract); g_free(abstract);
return ret; return ret;
} }
@ -158,7 +158,7 @@ static void theme_format_append_variable(GString *str, const char **format)
(*format)++; (*format)++;
value = parse_special((char **) format, NULL, NULL, value = parse_special((char **) format, NULL, NULL,
args, &free_ret, NULL ); args, &free_ret, NULL, 0);
if (free_ret) g_free(value); if (free_ret) g_free(value);
(*format)++; (*format)++;
@ -290,7 +290,7 @@ static char *theme_format_expand_abstract(THEME_REC *theme,
g_free(tmp); g_free(tmp);
} }
ret = parse_special_string(abstract, NULL, NULL, data, NULL); ret = parse_special_string(abstract, NULL, NULL, data, NULL, 0);
g_free(abstract); g_free(abstract);
g_free(data); g_free(data);
return ret; return ret;

View File

@ -67,7 +67,7 @@ static void handle_key_redirect(int key)
func(key, data, active_win->active_server, active_win->active); func(key, data, active_win->active_server, active_win->active);
gui_entry_remove_perm_prompt(); gui_entry_remove_perm_prompt();
window_update_prompt(active_win); window_update_prompt();
} }
static void handle_entry_redirect(const char *line) static void handle_entry_redirect(const char *line)
@ -83,7 +83,7 @@ static void handle_entry_redirect(const char *line)
func(line, data, active_win->active_server, active_win->active); func(line, data, active_win->active_server, active_win->active);
gui_entry_remove_perm_prompt(); gui_entry_remove_perm_prompt();
window_update_prompt(active_win); window_update_prompt();
} }
static int get_scroll_count(void) static int get_scroll_count(void)

View File

@ -23,6 +23,7 @@
#include "servers.h" #include "servers.h"
#include "misc.h" #include "misc.h"
#include "settings.h" #include "settings.h"
#include "special-vars.h"
#include "irc.h" #include "irc.h"
#include "channels.h" #include "channels.h"
@ -47,6 +48,8 @@ static int linecache_tag;
static int window_create_override; static int window_create_override;
static int default_indent_pos; static int default_indent_pos;
static char *prompt, *prompt_window;
static GUI_WINDOW_REC *gui_window_init(WINDOW_REC *window, MAIN_WINDOW_REC *parent) static GUI_WINDOW_REC *gui_window_init(WINDOW_REC *window, MAIN_WINDOW_REC *parent)
{ {
GUI_WINDOW_REC *gui; GUI_WINDOW_REC *gui;
@ -670,30 +673,51 @@ void gui_window_update_ypos(GUI_WINDOW_REC *gui)
gui->ypos += gui_window_get_linecount(gui, tmp->data); gui->ypos += gui_window_get_linecount(gui, tmp->data);
} }
void window_update_prompt(WINDOW_REC *window) void window_update_prompt(void)
{ {
WI_ITEM_REC *item; const char *special;
char *text, *str; char *prompt, *text;
int var_used;
if (window != active_win) return; special = settings_get_str(active_win->active != NULL ?
"prompt" : "prompt_window");
item = window->active; if (*special == '\0') {
if (item != NULL)
text = item->name;
else if (window->name != NULL)
text = window->name;
else {
gui_entry_set_prompt(""); gui_entry_set_prompt("");
return; return;
} }
prompt = parse_special_string(special, active_win->active_server,
active_win->active, "", &var_used,
PARSE_FLAG_ISSET_ANY);
if (!var_used && strchr(special, '$') != NULL) {
/* none of the $vars had non-empty values, use empty prompt */
*prompt = '\0';
}
/* set prompt */ /* set prompt */
text = show_lowascii(text); text = show_lowascii(prompt);
str = g_strdup_printf("[%1.17s] ", text); gui_entry_set_prompt(text);
g_free(text); g_free(text);
gui_entry_set_prompt(str); g_free(prompt);
if (*str != '\0') g_free(str); }
static void window_update_prompt_server(SERVER_REC *server)
{
if (server == active_win->active_server)
window_update_prompt();
}
static void window_update_prompt_window(WINDOW_REC *window)
{
if (window == active_win)
window_update_prompt();
}
static void window_update_prompt_window_item(WI_ITEM_REC *item)
{
if (item == active_win->active)
window_update_prompt();
} }
void gui_window_reparent(WINDOW_REC *window, MAIN_WINDOW_REC *parent) void gui_window_reparent(WINDOW_REC *window, MAIN_WINDOW_REC *parent)
@ -727,7 +751,7 @@ static void signal_window_changed(WINDOW_REC *window)
} }
screen_refresh_freeze(); screen_refresh_freeze();
window_update_prompt(window); window_update_prompt();
gui_window_redraw(window); gui_window_redraw(window);
screen_refresh_thaw(); screen_refresh_thaw();
} }
@ -1060,15 +1084,45 @@ void gui_window_reformat_line(WINDOW_REC *window, LINE_REC *line)
g_string_free(raw, TRUE); g_string_free(raw, TRUE);
} }
static void sig_check_window_update(WINDOW_REC *window)
{
if (window == active_win)
window_update_prompt();
}
static void read_settings(void) static void read_settings(void)
{ {
SIGNAL_FUNC funcs[] = {
(SIGNAL_FUNC) window_update_prompt,
(SIGNAL_FUNC) window_update_prompt_server,
(SIGNAL_FUNC) window_update_prompt_window,
(SIGNAL_FUNC) window_update_prompt_window_item
};
default_indent_pos = settings_get_int("indent"); default_indent_pos = settings_get_int("indent");
if (prompt != NULL) {
special_vars_remove_signals(prompt, 4, funcs);
special_vars_remove_signals(prompt_window, 4, funcs);
g_free(prompt);
g_free(prompt_window);
}
prompt = g_strdup(settings_get_str("prompt"));
prompt_window = g_strdup(settings_get_str("prompt_window"));
special_vars_add_signals(prompt, 4, funcs);
special_vars_add_signals(prompt_window, 4, funcs);
if (active_win != NULL) window_update_prompt();
} }
void gui_windows_init(void) void gui_windows_init(void)
{ {
settings_add_int("lookandfeel", "indent", 10); settings_add_int("lookandfeel", "indent", 10);
settings_add_str("lookandfeel", "prompt", "[$T] ");
settings_add_str("lookandfeel", "prompt_window", "[$winname] ");
prompt = NULL; prompt_window = NULL;
window_create_override = -1; window_create_override = -1;
linecache_tag = g_timeout_add(LINE_CACHE_CHECK_TIME, (GSourceFunc) sig_check_linecache, NULL); linecache_tag = g_timeout_add(LINE_CACHE_CHECK_TIME, (GSourceFunc) sig_check_linecache, NULL);
@ -1077,15 +1131,15 @@ void gui_windows_init(void)
signal_add("window created", (SIGNAL_FUNC) gui_window_created); signal_add("window created", (SIGNAL_FUNC) gui_window_created);
signal_add("window destroyed", (SIGNAL_FUNC) gui_window_destroyed); signal_add("window destroyed", (SIGNAL_FUNC) gui_window_destroyed);
signal_add_first("window changed", (SIGNAL_FUNC) signal_window_changed); signal_add_first("window changed", (SIGNAL_FUNC) signal_window_changed);
signal_add("window item changed", (SIGNAL_FUNC) window_update_prompt); signal_add("window item remove", (SIGNAL_FUNC) sig_check_window_update);
signal_add("window name changed", (SIGNAL_FUNC) window_update_prompt);
signal_add("window item remove", (SIGNAL_FUNC) window_update_prompt);
signal_add("setup changed", (SIGNAL_FUNC) read_settings); signal_add("setup changed", (SIGNAL_FUNC) read_settings);
} }
void gui_windows_deinit(void) void gui_windows_deinit(void)
{ {
g_source_remove(linecache_tag); g_source_remove(linecache_tag);
g_free_not_null(prompt);
g_free_not_null(prompt_window);
while (windows != NULL) while (windows != NULL)
window_destroy(windows->data); window_destroy(windows->data);
@ -1094,8 +1148,6 @@ void gui_windows_deinit(void)
signal_remove("window created", (SIGNAL_FUNC) gui_window_created); signal_remove("window created", (SIGNAL_FUNC) gui_window_created);
signal_remove("window destroyed", (SIGNAL_FUNC) gui_window_destroyed); signal_remove("window destroyed", (SIGNAL_FUNC) gui_window_destroyed);
signal_remove("window changed", (SIGNAL_FUNC) signal_window_changed); signal_remove("window changed", (SIGNAL_FUNC) signal_window_changed);
signal_remove("window item changed", (SIGNAL_FUNC) window_update_prompt); signal_remove("window item remove", (SIGNAL_FUNC) sig_check_window_update);
signal_remove("window name changed", (SIGNAL_FUNC) window_update_prompt);
signal_remove("window item remove", (SIGNAL_FUNC) window_update_prompt);
signal_remove("setup changed", (SIGNAL_FUNC) read_settings); signal_remove("setup changed", (SIGNAL_FUNC) read_settings);
} }

View File

@ -113,7 +113,7 @@ void gui_window_reparent(WINDOW_REC *window, MAIN_WINDOW_REC *parent);
#define is_window_bottom(gui) \ #define is_window_bottom(gui) \
((gui)->ypos >= -1 && (gui)->ypos <= (gui)->parent->last_line-(gui)->parent->first_line) ((gui)->ypos >= -1 && (gui)->ypos <= (gui)->parent->last_line-(gui)->parent->first_line)
void window_update_prompt(WINDOW_REC *window); void window_update_prompt(void);
void gui_window_newline(GUI_WINDOW_REC *gui, int visible); void gui_window_newline(GUI_WINDOW_REC *gui, int visible);
void gui_window_scroll(WINDOW_REC *window, int lines); void gui_window_scroll(WINDOW_REC *window, int lines);
void gui_window_update_ypos(GUI_WINDOW_REC *gui); void gui_window_update_ypos(GUI_WINDOW_REC *gui);

View File

@ -87,7 +87,7 @@ static void ctcp_version(IRC_SERVER_REC *server, const char *data,
g_return_if_fail(nick != NULL); g_return_if_fail(nick != NULL);
reply = parse_special_string(settings_get_str("ctcp_version_reply"), reply = parse_special_string(settings_get_str("ctcp_version_reply"),
SERVER(server), NULL, "", NULL); SERVER(server), NULL, "", NULL, 0);
str = g_strdup_printf("NOTICE %s :\001VERSION %s\001", nick, reply); str = g_strdup_printf("NOTICE %s :\001VERSION %s\001", nick, reply);
ctcp_send_reply(server, str); ctcp_send_reply(server, str);
g_free(str); g_free(str);

View File

@ -772,7 +772,7 @@ static void cmd_wall(const char *data, IRC_SERVER_REC *server, WI_ITEM_REC *item
args = g_strconcat(chanrec->name, " ", msg, NULL); args = g_strconcat(chanrec->name, " ", msg, NULL);
msg = parse_special_string(settings_get_str("wall_format"), msg = parse_special_string(settings_get_str("wall_format"),
SERVER(server), item, args, NULL); SERVER(server), item, args, NULL, 0);
g_free(args); g_free(args);
for (tmp = nicks; tmp != NULL; tmp = tmp->next) { for (tmp = nicks; tmp != NULL; tmp = tmp->next) {