summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2016-09-03 08:28:05 +0200
committerSébastien Helleu <flashcode@flashtux.org>2016-09-03 08:28:05 +0200
commit0572d0c4f50e278dae26a7b8a751ed77be981363 (patch)
treee866d2acdd196fee90425757df7084ee94723222 /src/core
parentf4b96dfa0f30167a825bb6fa5905a94bb0bf26d4 (diff)
downloadweechat-0572d0c4f50e278dae26a7b8a751ed77be981363.zip
core: evaluate content of option "weechat.look.item_time_format" (issue #791)
Diffstat (limited to 'src/core')
-rw-r--r--src/core/wee-config.c56
-rw-r--r--src/core/wee-config.h1
2 files changed, 55 insertions, 2 deletions
diff --git a/src/core/wee-config.c b/src/core/wee-config.c
index c1e50202b..35b67889e 100644
--- a/src/core/wee-config.c
+++ b/src/core/wee-config.c
@@ -37,6 +37,7 @@
#include "weechat.h"
#include "wee-config.h"
+#include "wee-eval.h"
#include "wee-hashtable.h"
#include "wee-hook.h"
#include "wee-log.h"
@@ -314,6 +315,7 @@ int config_word_chars_input_count = 0;
char **config_nick_colors = NULL;
int config_num_nick_colors = 0;
struct t_hashtable *config_hashtable_nick_color_force = NULL;
+char *config_item_time_evaluated = NULL;
/*
@@ -954,6 +956,49 @@ config_change_item_away (const void *pointer, void *data,
}
/*
+ * Callback for changes on options "weechat.look.item_time_format".
+ */
+
+void
+config_change_item_time_format (const void *pointer, void *data,
+ struct t_config_option *option)
+{
+ /* make C compiler happy */
+ (void) pointer;
+ (void) data;
+ (void) option;
+
+ if (config_item_time_evaluated)
+ free (config_item_time_evaluated);
+ config_item_time_evaluated = eval_expression (
+ CONFIG_STRING(config_look_item_time_format), NULL, NULL, NULL);
+
+ config_change_buffer_content (NULL, NULL, NULL);
+}
+
+/*
+ * Gets the current time formatted for the bar item status.
+ */
+
+void
+config_get_item_time (char *text_time, int max_length)
+{
+ time_t date;
+ struct tm *local_time;
+
+ if (!config_item_time_evaluated)
+ config_change_item_time_format (NULL, NULL, NULL);
+
+ text_time[0] = '\0';
+
+ date = time (NULL);
+ local_time = localtime (&date);
+ strftime (text_time, max_length,
+ config_item_time_evaluated,
+ local_time);
+}
+
+/*
* Callback for changes on option "weechat.look.paste_bracketed".
*/
@@ -2948,10 +2993,11 @@ config_weechat_init_options ()
weechat_config_file, ptr_section,
"item_time_format", "string",
N_("time format for \"time\" bar item (see man strftime for date/time "
- "specifiers)"),
+ "specifiers) (note: content is evaluated, so you can use colors "
+ "with format \"${color:xxx}\", see /help eval)"),
NULL, 0, 0, "%H:%M", NULL, 0,
NULL, NULL, NULL,
- &config_change_buffer_content, NULL, NULL,
+ &config_change_item_time_format, NULL, NULL,
NULL, NULL, NULL);
config_look_jump_current_to_previous_buffer = config_file_new_option (
weechat_config_file, ptr_section,
@@ -4509,4 +4555,10 @@ config_weechat_free ()
hashtable_free (config_hashtable_nick_color_force);
config_hashtable_nick_color_force = NULL;
}
+
+ if (config_item_time_evaluated)
+ {
+ free (config_item_time_evaluated);
+ config_item_time_evaluated = NULL;
+ }
}
diff --git a/src/core/wee-config.h b/src/core/wee-config.h
index e4c4a3d33..6682f25f1 100644
--- a/src/core/wee-config.h
+++ b/src/core/wee-config.h
@@ -358,6 +358,7 @@ extern int config_weechat_debug_set (const char *plugin_name,
extern void config_weechat_debug_set_all ();
extern int config_weechat_notify_set (struct t_gui_buffer *buffer,
const char *notify);
+extern void config_get_item_time (char *text_time, int max_length);
extern int config_weechat_init ();
extern int config_weechat_read ();
extern int config_weechat_write ();