30 |
#include <string.h> |
#include <string.h> |
31 |
#include <signal.h> |
#include <signal.h> |
32 |
#include <time.h> |
#include <time.h> |
33 |
|
#include <ctype.h> |
34 |
#include <ncurses.h> |
#include <ncurses.h> |
35 |
|
|
36 |
#include "../../common/weechat.h" |
#include "../../common/weechat.h" |
1315 |
t_gui_window *ptr_win; |
t_gui_window *ptr_win; |
1316 |
time_t time_seconds; |
time_t time_seconds; |
1317 |
struct tm *local_time; |
struct tm *local_time; |
1318 |
char text[1024 + 1]; |
char text_time[1024 + 1]; |
1319 |
|
|
1320 |
/* make gcc happy */ |
/* make gcc happy */ |
1321 |
(void) buffer; |
(void) buffer; |
1340 |
local_time = localtime (&time_seconds); |
local_time = localtime (&time_seconds); |
1341 |
if (local_time) |
if (local_time) |
1342 |
{ |
{ |
1343 |
strftime (text, 1024, cfg_look_infobar_timestamp, local_time); |
strftime (text_time, 1024, cfg_look_infobar_timestamp, local_time); |
1344 |
gui_window_set_color (ptr_win->win_infobar, COLOR_WIN_INFOBAR); |
gui_window_set_color (ptr_win->win_infobar, COLOR_WIN_INFOBAR); |
1345 |
wprintw (ptr_win->win_infobar, "%s", text); |
wprintw (ptr_win->win_infobar, "%s", text_time); |
1346 |
} |
} |
1347 |
if (gui_infobar) |
if (gui_infobar) |
1348 |
{ |
{ |
2425 |
gui_printf_type_color (t_gui_buffer *buffer, int type, int color, char *message, ...) |
gui_printf_type_color (t_gui_buffer *buffer, int type, int color, char *message, ...) |
2426 |
{ |
{ |
2427 |
static char buf[8192]; |
static char buf[8192]; |
2428 |
char timestamp[16]; |
char text_time[1024 + 1]; |
2429 |
|
char text_time_char[2]; |
2430 |
|
time_t time_seconds; |
2431 |
|
struct tm *local_time; |
2432 |
|
int time_first_digit, time_last_digit; |
2433 |
char *pos, *buf2, *buf3; |
char *pos, *buf2, *buf3; |
2434 |
int i, j; |
int i, j; |
2435 |
va_list argptr; |
va_list argptr; |
2508 |
pos = buf3 - 1; |
pos = buf3 - 1; |
2509 |
while (pos) |
while (pos) |
2510 |
{ |
{ |
|
/* TODO: read timestamp format from config! */ |
|
2511 |
if ((!buffer->last_line) || (buffer->line_complete)) |
if ((!buffer->last_line) || (buffer->line_complete)) |
2512 |
{ |
{ |
2513 |
gui_add_message (buffer, MSG_TYPE_TIME, COLOR_WIN_CHAT_DARK, "["); |
time_seconds = time (NULL); |
2514 |
snprintf (timestamp, 16, "%02d", date_tmp->tm_hour); |
local_time = localtime (&time_seconds); |
2515 |
gui_add_message (buffer, MSG_TYPE_TIME, COLOR_WIN_CHAT_TIME, timestamp); |
strftime (text_time, 1024, cfg_look_buffer_timestamp, local_time); |
2516 |
gui_add_message (buffer, MSG_TYPE_TIME, COLOR_WIN_CHAT_TIME_SEP, ":"); |
|
2517 |
snprintf (timestamp, 16, "%02d", date_tmp->tm_min); |
time_first_digit = -1; |
2518 |
gui_add_message (buffer, MSG_TYPE_TIME, COLOR_WIN_CHAT_TIME, timestamp); |
time_last_digit = -1; |
2519 |
gui_add_message (buffer, MSG_TYPE_TIME, COLOR_WIN_CHAT_TIME_SEP, ":"); |
i = 0; |
2520 |
snprintf (timestamp, 16, "%02d", date_tmp->tm_sec); |
while (text_time[i]) |
2521 |
gui_add_message (buffer, MSG_TYPE_TIME, COLOR_WIN_CHAT_TIME, timestamp); |
{ |
2522 |
gui_add_message (buffer, MSG_TYPE_TIME, COLOR_WIN_CHAT_DARK, "] "); |
if (isdigit (text_time[i])) |
2523 |
|
{ |
2524 |
|
if (time_first_digit == -1) |
2525 |
|
time_first_digit = i; |
2526 |
|
time_last_digit = i; |
2527 |
|
} |
2528 |
|
i++; |
2529 |
|
} |
2530 |
|
|
2531 |
|
text_time_char[1] = '\0'; |
2532 |
|
i = 0; |
2533 |
|
while (text_time[i]) |
2534 |
|
{ |
2535 |
|
text_time_char[0] = text_time[i]; |
2536 |
|
if (time_first_digit < 0) |
2537 |
|
gui_add_message (buffer, MSG_TYPE_TIME, COLOR_WIN_CHAT_TIME, |
2538 |
|
text_time_char); |
2539 |
|
else |
2540 |
|
{ |
2541 |
|
if ((i < time_first_digit) || (i > time_last_digit)) |
2542 |
|
gui_add_message (buffer, MSG_TYPE_TIME, COLOR_WIN_CHAT_DARK, |
2543 |
|
text_time_char); |
2544 |
|
else |
2545 |
|
{ |
2546 |
|
if (isdigit (text_time[i])) |
2547 |
|
gui_add_message (buffer, MSG_TYPE_TIME, COLOR_WIN_CHAT_TIME, |
2548 |
|
text_time_char); |
2549 |
|
else |
2550 |
|
gui_add_message (buffer, MSG_TYPE_TIME, COLOR_WIN_CHAT_TIME_SEP, |
2551 |
|
text_time_char); |
2552 |
|
} |
2553 |
|
} |
2554 |
|
i++; |
2555 |
|
} |
2556 |
|
gui_add_message (buffer, MSG_TYPE_TIME, COLOR_WIN_CHAT_DARK, " "); |
2557 |
} |
} |
2558 |
gui_add_message (buffer, type, color, pos + 1); |
gui_add_message (buffer, type, color, pos + 1); |
2559 |
pos = strchr (pos + 1, '\n'); |
pos = strchr (pos + 1, '\n'); |