Add win highlight fuctions

This commit is contained in:
James Booth
2016-10-15 22:12:07 +01:00
parent f3aebd547c
commit bb6540f7d8
4 changed files with 135 additions and 43 deletions

View File

@@ -61,6 +61,8 @@
#define CEILING(X) (X-(int)(X) > 0 ? (int)(X+1) : (int)(X))
static void _win_printf(ProfWin *window, const char show_char, int pad_indent, GDateTime *timestamp,
int flags, theme_item_t theme_item, const char *const from, const char *const message, ...);
static void _win_print(ProfWin *window, const char show_char, int pad_indent, GDateTime *time,
int flags, theme_item_t theme_item, const char *const from, const char *const message, DeliveryReceipt *receipt);
static void _win_print_wrapped(WINDOW *win, const char *const message, size_t indent, int pad_indent);
@@ -997,10 +999,10 @@ win_print_incoming(ProfWin *window, GDateTime *timestamp,
} else if (enc_mode == PROF_MSG_PGP) {
enc_char = prefs_get_pgp_char();
}
win_printf(window, enc_char, 0, timestamp, NO_ME, THEME_TEXT_THEM, from, "%s", message);
_win_printf(window, enc_char, 0, timestamp, NO_ME, THEME_TEXT_THEM, from, "%s", message);
break;
case WIN_PRIVATE:
win_printf(window, '-', 0, timestamp, NO_ME, THEME_TEXT_THEM, from, "%s", message);
_win_printf(window, '-', 0, timestamp, NO_ME, THEME_TEXT_THEM, from, "%s", message);
break;
default:
assert(FALSE);
@@ -1008,6 +1010,52 @@ win_print_incoming(ProfWin *window, GDateTime *timestamp,
}
}
void
win_print_them(ProfWin *window, theme_item_t theme_item, const char *const them)
{
_win_printf(window, '-', 0, NULL, NO_ME | NO_EOL, theme_item, them, "");
}
void
win_println_them_message(ProfWin *window, const char *const them, const char *const message, ...)
{
GDateTime *timestamp = g_date_time_new_now_local();
va_list arg;
va_start(arg, message);
GString *fmt_msg = g_string_new(NULL);
g_string_vprintf(fmt_msg, message, arg);
buffer_push(window->layout->buffer, '-', 0, timestamp, NO_ME, THEME_TEXT_THEM, them, fmt_msg->str, NULL);
_win_print(window, '-', 0, timestamp, NO_ME, THEME_TEXT_THEM, them, fmt_msg->str, NULL);
inp_nonblocking(TRUE);
g_date_time_unref(timestamp);
g_string_free(fmt_msg, TRUE);
va_end(arg);
}
void
win_println_me_message(ProfWin *window, const char *const me, const char *const message, ...)
{
GDateTime *timestamp = g_date_time_new_now_local();
va_list arg;
va_start(arg, message);
GString *fmt_msg = g_string_new(NULL);
g_string_vprintf(fmt_msg, message, arg);
buffer_push(window->layout->buffer, '-', 0, timestamp, 0, THEME_TEXT_ME, me, fmt_msg->str, NULL);
_win_print(window, '-', 0, timestamp, 0, THEME_TEXT_ME, me, fmt_msg->str, NULL);
inp_nonblocking(TRUE);
g_date_time_unref(timestamp);
g_string_free(fmt_msg, TRUE);
va_end(arg);
}
void
win_print_outgoing(ProfWin *window, const char ch, const char *const message, ...)
{
@@ -1048,31 +1096,6 @@ win_print_history(ProfWin *window, GDateTime *timestamp, const char *const messa
va_end(arg);
}
void
win_printf(ProfWin *window, const char show_char, int pad_indent, GDateTime *timestamp,
int flags, theme_item_t theme_item, const char *const from, const char *const message, ...)
{
if (timestamp == NULL) {
timestamp = g_date_time_new_now_local();
} else {
g_date_time_ref(timestamp);
}
va_list arg;
va_start(arg, message);
GString *fmt_msg = g_string_new(NULL);
g_string_vprintf(fmt_msg, message, arg);
buffer_push(window->layout->buffer, show_char, pad_indent, timestamp, flags, theme_item, from, fmt_msg->str, NULL);
_win_print(window, show_char, pad_indent, timestamp, flags, theme_item, from, fmt_msg->str, NULL);
inp_nonblocking(TRUE);
g_date_time_unref(timestamp);
g_string_free(fmt_msg, TRUE);
va_end(arg);
}
void
win_print(ProfWin *window, theme_item_t theme_item, const char ch, const char *const message, ...)
{
@@ -1163,7 +1186,7 @@ win_appendln(ProfWin *window, theme_item_t theme_item, const char *const message
GString *fmt_msg = g_string_new(NULL);
g_string_vprintf(fmt_msg, message, arg);
buffer_push(window->layout->buffer, '-', 0, timestamp, NO_EOL, theme_item, "", fmt_msg->str, NULL);
buffer_push(window->layout->buffer, '-', 0, timestamp, NO_DATE, theme_item, "", fmt_msg->str, NULL);
_win_print(window, '-', 0, timestamp, NO_DATE, theme_item, "", fmt_msg->str, NULL);
inp_nonblocking(TRUE);
@@ -1173,6 +1196,46 @@ win_appendln(ProfWin *window, theme_item_t theme_item, const char *const message
va_end(arg);
}
void
win_append_highlight(ProfWin *window, theme_item_t theme_item, const char *const message, ...)
{
GDateTime *timestamp = g_date_time_new_now_local();
va_list arg;
va_start(arg, message);
GString *fmt_msg = g_string_new(NULL);
g_string_vprintf(fmt_msg, message, arg);
buffer_push(window->layout->buffer, '-', 0, timestamp, NO_DATE | NO_ME | NO_EOL, theme_item, "", fmt_msg->str, NULL);
_win_print(window, '-', 0, timestamp, NO_DATE | NO_ME | NO_EOL, theme_item, "", fmt_msg->str, NULL);
inp_nonblocking(TRUE);
g_date_time_unref(timestamp);
g_string_free(fmt_msg, TRUE);
va_end(arg);
}
void
win_appendln_highlight(ProfWin *window, theme_item_t theme_item, const char *const message, ...)
{
GDateTime *timestamp = g_date_time_new_now_local();
va_list arg;
va_start(arg, message);
GString *fmt_msg = g_string_new(NULL);
g_string_vprintf(fmt_msg, message, arg);
buffer_push(window->layout->buffer, '-', 0, timestamp, NO_DATE | NO_ME, theme_item, "", fmt_msg->str, NULL);
_win_print(window, '-', 0, timestamp, NO_DATE | NO_ME, theme_item, "", fmt_msg->str, NULL);
inp_nonblocking(TRUE);
g_date_time_unref(timestamp);
g_string_free(fmt_msg, TRUE);
va_end(arg);
}
void
win_print_http_upload(ProfWin *window, const char *const message, char *url)
{
@@ -1232,6 +1295,31 @@ win_newline(ProfWin *window)
win_appendln(window, THEME_DEFAULT, "");
}
static void
_win_printf(ProfWin *window, const char show_char, int pad_indent, GDateTime *timestamp,
int flags, theme_item_t theme_item, const char *const from, const char *const message, ...)
{
if (timestamp == NULL) {
timestamp = g_date_time_new_now_local();
} else {
g_date_time_ref(timestamp);
}
va_list arg;
va_start(arg, message);
GString *fmt_msg = g_string_new(NULL);
g_string_vprintf(fmt_msg, message, arg);
buffer_push(window->layout->buffer, show_char, pad_indent, timestamp, flags, theme_item, from, fmt_msg->str, NULL);
_win_print(window, show_char, pad_indent, timestamp, flags, theme_item, from, fmt_msg->str, NULL);
inp_nonblocking(TRUE);
g_date_time_unref(timestamp);
g_string_free(fmt_msg, TRUE);
va_end(arg);
}
static void
_win_print(ProfWin *window, const char show_char, int pad_indent, GDateTime *time,
int flags, theme_item_t theme_item, const char *const from, const char *const message, DeliveryReceipt *receipt)