mirror of
https://github.com/weechat/weechat.git
synced 2026-06-27 13:26:38 +02:00
Added date option for printf functions (weechat core and plugins API)
This commit is contained in:
@@ -40,7 +40,8 @@ enum t_gui_buffer_type
|
||||
|
||||
struct t_gui_line
|
||||
{
|
||||
time_t date; /* date/time of line */
|
||||
time_t date; /* date/time of line (may be past) */
|
||||
time_t date_printed; /* date/time when weechat print it */
|
||||
char *str_time; /* time string (for display) */
|
||||
char *prefix; /* prefix for line (may be NULL) */
|
||||
int prefix_length; /* prefix length (on screen) */
|
||||
|
||||
+11
-6
@@ -399,8 +399,8 @@ gui_chat_line_free (struct t_gui_line *line)
|
||||
*/
|
||||
|
||||
void
|
||||
gui_chat_line_add (struct t_gui_buffer *buffer, time_t date, char *prefix,
|
||||
char *message)
|
||||
gui_chat_line_add (struct t_gui_buffer *buffer, time_t date,
|
||||
time_t date_printed, char *prefix, char *message)
|
||||
{
|
||||
struct t_gui_line *new_line, *ptr_line;
|
||||
|
||||
@@ -413,6 +413,7 @@ gui_chat_line_add (struct t_gui_buffer *buffer, time_t date, char *prefix,
|
||||
|
||||
/* add new line */
|
||||
new_line->date = date;
|
||||
new_line->date_printed = date_printed;
|
||||
new_line->str_time = (date == 0) ?
|
||||
NULL : gui_chat_get_time_string (date);
|
||||
new_line->prefix = (prefix) ?
|
||||
@@ -446,14 +447,15 @@ gui_chat_line_add (struct t_gui_buffer *buffer, time_t date, char *prefix,
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_chat_printf: display a message in a buffer
|
||||
* gui_chat_printf_date: display a message in a buffer
|
||||
*/
|
||||
|
||||
void
|
||||
gui_chat_printf (struct t_gui_buffer *buffer, char *message, ...)
|
||||
gui_chat_printf_date (struct t_gui_buffer *buffer, time_t date,
|
||||
char *message, ...)
|
||||
{
|
||||
static char buf[8192];
|
||||
time_t date;
|
||||
time_t date_printed;
|
||||
int display_time;
|
||||
char *pos, *pos_prefix, *pos_tab, *pos_end;
|
||||
va_list argptr;
|
||||
@@ -476,7 +478,9 @@ gui_chat_printf (struct t_gui_buffer *buffer, char *message, ...)
|
||||
|
||||
utf8_normalize (buf, '?');
|
||||
|
||||
date = time (NULL);
|
||||
date_printed = time (NULL);
|
||||
if (date <= 0)
|
||||
date = date_printed;
|
||||
|
||||
pos = buf;
|
||||
while (pos)
|
||||
@@ -509,6 +513,7 @@ gui_chat_printf (struct t_gui_buffer *buffer, char *message, ...)
|
||||
|
||||
if (gui_init_ok)
|
||||
gui_chat_line_add (buffer, (display_time) ? date : 0,
|
||||
(display_time) ? date_printed : 0,
|
||||
pos_prefix, pos);
|
||||
else
|
||||
{
|
||||
|
||||
+4
-1
@@ -22,6 +22,9 @@
|
||||
|
||||
#include "gui-buffer.h"
|
||||
|
||||
#define gui_chat_printf(buffer, argz...) \
|
||||
gui_chat_printf_date(buffer, 0, ##argz) \
|
||||
|
||||
enum t_gui_prefix
|
||||
{
|
||||
GUI_CHAT_PREFIX_INFO = 0,
|
||||
@@ -49,7 +52,7 @@ extern int gui_chat_get_line_align (struct t_gui_buffer *,
|
||||
struct t_gui_line *, int);
|
||||
extern int gui_chat_line_search (struct t_gui_line *, char *, int);
|
||||
extern void gui_chat_line_free (struct t_gui_line *);
|
||||
extern void gui_chat_printf (struct t_gui_buffer *, char *, ...);
|
||||
extern void gui_chat_printf_date (struct t_gui_buffer *, time_t, char *, ...);
|
||||
extern void gui_chat_printf_raw_data (void *, int, int, char *);
|
||||
|
||||
/* chat functions (GUI dependent) */
|
||||
|
||||
+28
-4
@@ -30,6 +30,7 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "../weechat-plugin.h"
|
||||
#include "demo.h"
|
||||
@@ -47,6 +48,7 @@ demo_print_list (void *list, char *item_name)
|
||||
{
|
||||
char *fields, **argv;
|
||||
int i, j, argc;
|
||||
time_t date;
|
||||
|
||||
i = 1;
|
||||
while (weechat_list_next (list))
|
||||
@@ -81,10 +83,10 @@ demo_print_list (void *list, char *item_name)
|
||||
argv[j] + 2));
|
||||
break;
|
||||
case 't':
|
||||
weechat_printf (NULL, " %s: %ld",
|
||||
date = weechat_list_time (list, argv[j] + 2);
|
||||
weechat_printf (NULL, " %s: (%ld) %s",
|
||||
argv[j] + 2,
|
||||
weechat_list_time (list,
|
||||
argv[j] + 2));
|
||||
date, ctime (&date));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -114,6 +116,23 @@ demo_buffer_infos ()
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* demo_buffer_lines: display buffer lines
|
||||
*/
|
||||
|
||||
static void
|
||||
demo_buffer_lines ()
|
||||
{
|
||||
struct t_plugin_list *list;
|
||||
|
||||
list = weechat_list_get ("buffer_lines", NULL);
|
||||
if (list)
|
||||
{
|
||||
demo_print_list (list, "buffer_line");
|
||||
weechat_list_free (list);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* demo_command: demo command
|
||||
*/
|
||||
@@ -132,6 +151,11 @@ demo_command (void *data, int argc, char **argv, char **argv_eol)
|
||||
demo_buffer_infos ();
|
||||
return PLUGIN_RC_SUCCESS;
|
||||
}
|
||||
if (weechat_strcasecmp (argv[1], "buffer_lines") == 0)
|
||||
{
|
||||
demo_buffer_lines ();
|
||||
return PLUGIN_RC_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
weechat_printf (NULL,
|
||||
@@ -153,7 +177,7 @@ weechat_plugin_init (struct t_weechat_plugin *plugin)
|
||||
weechat_hook_command ("demo", "demo command", "[action]",
|
||||
"action: one of following actions:\n"
|
||||
" buffer display infos about buffers",
|
||||
"buffer", demo_command, NULL);
|
||||
"buffer|buffer_lines", demo_command, NULL);
|
||||
|
||||
return PLUGIN_RC_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -260,6 +260,28 @@ plugin_api_printf (struct t_weechat_plugin *plugin,
|
||||
gui_chat_printf ((struct t_gui_buffer *)buffer, buf);
|
||||
}
|
||||
|
||||
/*
|
||||
* plugin_api_printf_date: print a message on a buffer with a specific date
|
||||
*/
|
||||
|
||||
void
|
||||
plugin_api_printf_date (struct t_weechat_plugin *plugin,
|
||||
void *buffer, time_t date, char *format, ...)
|
||||
{
|
||||
va_list argptr;
|
||||
char buf[8192];
|
||||
|
||||
if (!plugin || !format
|
||||
|| !gui_buffer_valid ((struct t_gui_buffer *)buffer))
|
||||
return;
|
||||
|
||||
va_start (argptr, format);
|
||||
vsnprintf (buf, sizeof (buf) - 1, format, argptr);
|
||||
va_end (argptr);
|
||||
|
||||
gui_chat_printf_date ((struct t_gui_buffer *)buffer, date, buf);
|
||||
}
|
||||
|
||||
/*
|
||||
* plugin_api_prefix: return a prefix for display with printf
|
||||
*/
|
||||
@@ -835,6 +857,8 @@ plugin_api_list_get_add_buffer_line (struct t_plugin_list *list,
|
||||
|
||||
if (!plugin_list_new_var_time (ptr_item, "date", line->date))
|
||||
return 0;
|
||||
if (!plugin_list_new_var_time (ptr_item, "date_printed", line->date))
|
||||
return 0;
|
||||
if (!plugin_list_new_var_string (ptr_item, "str_time", line->str_time))
|
||||
return 0;
|
||||
if (!plugin_list_new_var_string (ptr_item, "prefix", line->prefix))
|
||||
@@ -901,13 +925,14 @@ plugin_api_list_get (struct t_weechat_plugin *plugin, char *name,
|
||||
}
|
||||
else if (string_strcasecmp (name, "buffer_lines") == 0)
|
||||
{
|
||||
/* buffer pointer is mandatory for this list */
|
||||
if (!pointer)
|
||||
return NULL;
|
||||
|
||||
/* invalid buffer pointer ? */
|
||||
if (!gui_buffer_valid ((struct t_gui_buffer *)pointer))
|
||||
return NULL;
|
||||
pointer = gui_buffers;
|
||||
else
|
||||
{
|
||||
/* invalid buffer pointer ? */
|
||||
if (!gui_buffer_valid ((struct t_gui_buffer *)pointer))
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ptr_list = plugin_list_new ();
|
||||
if (ptr_list)
|
||||
|
||||
@@ -45,6 +45,8 @@ extern void plugin_api_exec_on_files (struct t_weechat_plugin *, char *,
|
||||
/* display */
|
||||
extern void plugin_api_printf (struct t_weechat_plugin *, void *,
|
||||
char *, ...);
|
||||
extern void plugin_api_printf_date (struct t_weechat_plugin *, void *,
|
||||
time_t, char *, ...);
|
||||
extern char *plugin_api_prefix (struct t_weechat_plugin *, char *);
|
||||
extern char *plugin_api_color (struct t_weechat_plugin *, char *);
|
||||
extern void plugin_api_print_infobar (struct t_weechat_plugin *, int,
|
||||
|
||||
@@ -238,6 +238,7 @@ plugin_load (char *filename)
|
||||
new_plugin->exec_on_files = &plugin_api_exec_on_files;
|
||||
|
||||
new_plugin->printf = &plugin_api_printf;
|
||||
new_plugin->printf_date = &plugin_api_printf_date;
|
||||
new_plugin->prefix = &plugin_api_prefix;
|
||||
new_plugin->color = &plugin_api_color;
|
||||
new_plugin->print_infobar = &plugin_api_print_infobar;
|
||||
|
||||
@@ -74,6 +74,8 @@ struct t_weechat_plugin
|
||||
|
||||
/* display */
|
||||
void (*printf) (struct t_weechat_plugin *, void *, char *, ...);
|
||||
void (*printf_date) (struct t_weechat_plugin *, void *, time_t,
|
||||
char *, ...);
|
||||
char *(*prefix) (struct t_weechat_plugin *, char *);
|
||||
char *(*color) (struct t_weechat_plugin *, char *);
|
||||
void (*print_infobar) (struct t_weechat_plugin *, int, char *, ...);
|
||||
@@ -158,6 +160,9 @@ struct t_weechat_plugin
|
||||
|
||||
#define weechat_printf(buffer, argz...) \
|
||||
weechat_plugin->printf(weechat_plugin, buffer, ##argz)
|
||||
#define weechat_printf_date(buffer, datetime, argz...) \
|
||||
weechat_plugin->printf_date(weechat_plugin, buffer, datetime, \
|
||||
##argz)
|
||||
#define weechat_prefix(prefix_name) \
|
||||
weechat_plugin->prefix(weechat_plugin, prefix_name)
|
||||
#define weechat_color(color_name) \
|
||||
|
||||
Reference in New Issue
Block a user