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

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

@ -370,10 +370,10 @@ _mucwin_print_mention(ProfWin *window, const char *const message, const char *co
pos = GPOINTER_TO_INT(curr->data);
char *before_str = g_strndup(message + last_pos, pos - last_pos);
win_printf(window, '-', 0, NULL, NO_DATE | NO_ME | NO_EOL, THEME_ROOMMENTION, "", "%s", before_str);
win_append_highlight(window, THEME_ROOMMENTION, "%s", before_str);
g_free(before_str);
char *nick_str = g_strndup(message + pos, strlen(nick));
win_printf(window, '-', 0, NULL, NO_DATE | NO_ME | NO_EOL, THEME_ROOMMENTION_TERM, "", "%s", nick_str);
win_append_highlight(window, THEME_ROOMMENTION_TERM, "%s", nick_str);
g_free(nick_str);
last_pos = pos + strlen(nick);
@ -381,9 +381,9 @@ _mucwin_print_mention(ProfWin *window, const char *const message, const char *co
curr = g_slist_next(curr);
}
if (last_pos < strlen(message)) {
win_printf(window, '-', 0, NULL, NO_DATE | NO_ME, THEME_ROOMMENTION, "", "%s", &message[last_pos]);
win_appendln_highlight(window, THEME_ROOMMENTION, "%s", &message[last_pos]);
} else {
win_printf(window, '-', 0, NULL, NO_DATE | NO_ME, THEME_ROOMMENTION, "", "");
win_appendln_highlight(window, THEME_ROOMMENTION, "");
}
}
@ -441,7 +441,7 @@ _mucwin_print_triggers(ProfWin *window, const char *const message, GList *trigge
// no triggers found
if (first_trigger_pos == -1) {
win_printf(window, '-', 0, NULL, NO_DATE | NO_ME, THEME_ROOMTRIGGER, "", "%s", message);
win_appendln_highlight(window, THEME_ROOMTRIGGER, "%s", message);
} else {
if (first_trigger_pos > 0) {
char message_section[strlen(message) + 1];
@ -451,7 +451,7 @@ _mucwin_print_triggers(ProfWin *window, const char *const message, GList *trigge
i++;
}
message_section[i] = '\0';
win_printf(window, '-', 0, NULL, NO_DATE | NO_ME | NO_EOL, THEME_ROOMTRIGGER, "", "%s", message_section);
win_append_highlight(window, THEME_ROOMTRIGGER, "%s", message_section);
}
char trigger_section[first_trigger_len + 1];
int i = 0;
@ -462,10 +462,10 @@ _mucwin_print_triggers(ProfWin *window, const char *const message, GList *trigge
trigger_section[i] = '\0';
if (first_trigger_pos + first_trigger_len < strlen(message)) {
win_printf(window, '-', 0, NULL, NO_DATE | NO_ME | NO_EOL, THEME_ROOMTRIGGER_TERM, "", "%s", trigger_section);
win_append_highlight(window, THEME_ROOMTRIGGER_TERM, "%s", trigger_section);
_mucwin_print_triggers(window, &message[first_trigger_pos + first_trigger_len], triggers);
} else {
win_printf(window, '-', 0, NULL, NO_DATE | NO_ME, THEME_ROOMTRIGGER_TERM, "", "%s", trigger_section);
win_appendln_highlight(window, THEME_ROOMTRIGGER_TERM, "%s", trigger_section);
}
}
}
@ -480,16 +480,16 @@ mucwin_message(ProfMucWin *mucwin, const char *const nick, const char *const mes
if (g_strcmp0(nick, mynick) != 0) {
if (g_slist_length(mentions) > 0) {
win_printf(window, '-', 0, NULL, NO_ME | NO_EOL, THEME_ROOMMENTION, nick, "");
win_print_them(window, THEME_ROOMMENTION, nick);
_mucwin_print_mention(window, message, mynick, mentions);
} else if (triggers) {
win_printf(window, '-', 0, NULL, NO_ME | NO_EOL, THEME_ROOMTRIGGER, nick, "");
win_print_them(window, THEME_ROOMTRIGGER, nick);
_mucwin_print_triggers(window, message, triggers);
} else {
win_printf(window, '-', 0, NULL, NO_ME, THEME_TEXT_THEM, nick, "%s", message);
win_println_them_message(window, nick, "%s", message);
}
} else {
win_printf(window, '-', 0, NULL, 0, THEME_TEXT_ME, nick, "%s", message);
win_println_me_message(window, mynick, "%s", message);
}
}

View File

@ -356,9 +356,6 @@ void win_show_subwin(ProfWin *window);
void win_refresh_without_subwin(ProfWin *window);
void win_refresh_with_subwin(ProfWin *window);
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, ...);
void win_print(ProfWin *window, theme_item_t theme_item, const char ch, const char *const message, ...);
void win_println(ProfWin *window, theme_item_t theme_item, const char ch, const char *const message, ...);
void win_println_indent(ProfWin *window, int pad, const char *const message, ...);
@ -366,6 +363,9 @@ void win_println_indent(ProfWin *window, int pad, const char *const message, ...
void win_append(ProfWin *window, theme_item_t theme_item, const char *const message, ...);
void win_appendln(ProfWin *window, theme_item_t theme_item, const char *const message, ...);
void win_append_highlight(ProfWin *window, theme_item_t theme_item, const char *const message, ...);
void win_appendln_highlight(ProfWin *window, theme_item_t theme_item, const char *const message, ...);
char* win_get_title(ProfWin *window);
void win_show_occupant(ProfWin *window, Occupant *occupant);
void win_show_occupant_info(ProfWin *window, const char *const room, Occupant *occupant);

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)

View File

@ -60,6 +60,10 @@ void win_show_status_string(ProfWin *window, const char *const from,
GDateTime *last_activity, const char *const pre,
const char *const default_show);
void win_print_them(ProfWin *window, theme_item_t theme_item, const char *const them);
void win_println_them_message(ProfWin *window, const char *const them, const char *const message, ...);
void win_println_me_message(ProfWin *window, const char *const me, const char *const message, ...);
void win_print_outgoing(ProfWin *window, const char ch, const char *const message, ...);
void win_print_incoming(ProfWin *window, GDateTime *timestamp,
const char *const from, const char *const message, prof_enc_t enc_mode);