1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-07-21 18:24:14 -04:00

Highlight room trigger terms

This commit is contained in:
James Booth 2016-02-13 22:46:25 +00:00
parent 2f82f50a35
commit 1a3dc91e11
24 changed files with 93 additions and 9 deletions

View File

@ -109,6 +109,7 @@ theme_init(const char *const theme_name)
g_hash_table_insert(defaults, strdup("roommention"), strdup("yellow"));
g_hash_table_insert(defaults, strdup("roommention.term"), strdup("yellow"));
g_hash_table_insert(defaults, strdup("roomtrigger"), strdup("yellow"));
g_hash_table_insert(defaults, strdup("roomtrigger.term"), strdup("yellow"));
g_hash_table_insert(defaults, strdup("online"), strdup("green"));
g_hash_table_insert(defaults, strdup("offline"), strdup("red"));
g_hash_table_insert(defaults, strdup("away"), strdup("cyan"));
@ -754,6 +755,7 @@ theme_attrs(theme_item_t attrs)
case THEME_ROOMMENTION: _theme_prep_fgnd("roommention", lookup_str, &bold); break;
case THEME_ROOMMENTION_TERM: _theme_prep_fgnd("roommention.term", lookup_str, &bold); break;
case THEME_ROOMTRIGGER: _theme_prep_fgnd("roomtrigger", lookup_str, &bold); break;
case THEME_ROOMTRIGGER_TERM: _theme_prep_fgnd("roomtrigger.term", lookup_str, &bold); break;
case THEME_ONLINE: _theme_prep_fgnd("online", lookup_str, &bold); break;
case THEME_OFFLINE: _theme_prep_fgnd("offline", lookup_str, &bold); break;
case THEME_AWAY: _theme_prep_fgnd("away", lookup_str, &bold); break;

View File

@ -72,6 +72,7 @@ typedef enum {
THEME_ROOMMENTION,
THEME_ROOMMENTION_TERM,
THEME_ROOMTRIGGER,
THEME_ROOMTRIGGER_TERM,
THEME_ONLINE,
THEME_OFFLINE,
THEME_AWAY,

View File

@ -256,7 +256,7 @@ sv_ev_room_message(const char *const room_jid, const char *const nick, const cha
GList *triggers = prefs_message_get_triggers(message);
mucwin_message(mucwin, nick, message, mention, triggers != NULL);
mucwin_message(mucwin, nick, message, mention, triggers);
ProfWin *window = (ProfWin*)mucwin;
int num = wins_get_num(window);

View File

@ -2217,6 +2217,7 @@ cons_theme_properties(void)
_cons_theme_prop(THEME_ROOMMENTION, "roommention");
_cons_theme_prop(THEME_ROOMMENTION_TERM, "roommention.term");
_cons_theme_prop(THEME_ROOMTRIGGER, "roomtrigger");
_cons_theme_prop(THEME_ROOMTRIGGER_TERM, "roomtrigger.term");
_cons_theme_prop(THEME_ROSTER_HEADER, "roster.header");
_cons_theme_prop(THEME_ROSTER_CHAT, "roster.chat");

View File

@ -385,9 +385,71 @@ _mucwin_print_mention(ProfWin *window, const char *const message, const char *co
g_free(message_lower);
}
static void
_mucwin_print_triggers(ProfWin *window, const char *const message, GList *triggers)
{
char *message_lower = g_utf8_strdown(message, -1);
// find earliest trigger in message
int first_trigger_pos = -1;
int first_trigger_len = -1;
GList *curr = triggers;
while (curr) {
char *trigger_lower = g_utf8_strdown(curr->data, -1);
char *trigger_ptr = g_strstr_len(message_lower, -1, trigger_lower);
// not found, try next
if (trigger_ptr == NULL) {
curr = g_list_next(curr);
continue;
}
// found, repace vars if earlier than previous
int trigger_pos = trigger_ptr - message_lower;
if (first_trigger_pos == -1 || trigger_pos < first_trigger_pos) {
first_trigger_pos = trigger_pos;
first_trigger_len = strlen(trigger_lower);
}
g_free(trigger_lower);
curr = g_list_next(curr);
}
g_free(message_lower);
// no triggers found
if (first_trigger_pos == -1) {
win_print(window, '-', 0, NULL, NO_DATE | NO_ME, THEME_ROOMTRIGGER, "", message);
} else {
if (first_trigger_pos > 0) {
char message_section[strlen(message) + 1];
int i = 0;
while (i < first_trigger_pos) {
message_section[i] = message[i];
i++;
}
message_section[i] = '\0';
win_print(window, '-', 0, NULL, NO_DATE | NO_ME | NO_EOL, THEME_ROOMTRIGGER, "", message_section);
}
char trigger_section[first_trigger_len + 1];
int i = 0;
while (i < first_trigger_len) {
trigger_section[i] = message[first_trigger_pos + i];
i++;
}
trigger_section[i] = '\0';
if (first_trigger_pos + first_trigger_len < strlen(message)) {
win_print(window, '-', 0, NULL, NO_DATE | NO_ME | NO_EOL, THEME_ROOMTRIGGER_TERM, "", trigger_section);
_mucwin_print_triggers(window, &message[first_trigger_pos + first_trigger_len], triggers);
} else {
win_print(window, '-', 0, NULL, NO_DATE | NO_ME, THEME_ROOMTRIGGER_TERM, "", trigger_section);
}
}
}
void
mucwin_message(ProfMucWin *mucwin, const char *const nick, const char *const message, gboolean mention,
gboolean trigger_found)
mucwin_message(ProfMucWin *mucwin, const char *const nick, const char *const message, gboolean mention, GList *triggers)
{
assert(mucwin != NULL);
@ -398,8 +460,9 @@ mucwin_message(ProfMucWin *mucwin, const char *const nick, const char *const mes
if (mention) {
win_print(window, '-', 0, NULL, NO_ME | NO_EOL, THEME_ROOMMENTION, nick, "");
_mucwin_print_mention(window, message, my_nick);
} else if (trigger_found) {
win_print(window, '-', 0, NULL, NO_ME, THEME_ROOMTRIGGER, nick, message);
} else if (triggers) {
win_print(window, '-', 0, NULL, NO_ME | NO_EOL, THEME_ROOMTRIGGER, nick, "");
_mucwin_print_triggers(window, message, triggers);
} else {
win_print(window, '-', 0, NULL, NO_ME, THEME_TEXT_THEM, nick, message);
}

View File

@ -158,7 +158,7 @@ void mucwin_occupant_role_and_affiliation_change(ProfMucWin *mucwin, const char
const char *const role, const char *const affiliation, const char *const actor, const char *const reason);
void mucwin_roster(ProfMucWin *mucwin, GList *occupants, const char *const presence);
void mucwin_history(ProfMucWin *mucwin, const char *const nick, GDateTime *timestamp, const char *const message);
void mucwin_message(ProfMucWin *mucwin, const char *const nick, const char *const message, gboolean mention, gboolean trigger_found);
void mucwin_message(ProfMucWin *mucwin, const char *const nick, const char *const message, gboolean mention, GList *triggers);
void mucwin_subject(ProfMucWin *mucwin, const char *const nick, const char *const subject);
void mucwin_requires_config(ProfMucWin *mucwin);
void mucwin_info(ProfMucWin *mucwin);

View File

@ -193,7 +193,7 @@ void mucwin_occupant_role_and_affiliation_change(ProfMucWin *mucwin, const char
const char * const affiliation, const char * const actor, const char * const reason) {}
void mucwin_roster(ProfMucWin *mucwin, GList *occupants, const char * const presence) {}
void mucwin_history(ProfMucWin *mucwin, const char * const nick, GDateTime *timestamp, const char * const message) {}
void mucwin_message(ProfMucWin *mucwin, const char * const nick, const char * const message, gboolean mention, gboolean trigger_found) {}
void mucwin_message(ProfMucWin *mucwin, const char * const nick, const char * const message, gboolean mention, GList *triggers) {}
void mucwin_subject(ProfMucWin *mucwin, const char * const nick, const char * const subject) {}
void mucwin_requires_config(ProfMucWin *mucwin) {}
void ui_room_destroy(const char * const roomjid) {}

View File

@ -47,6 +47,7 @@ roominfo=
roommention=
roommention.term=
roomtrigger=
roomtrigger.term=
me=
them=
roster.header=

View File

@ -47,6 +47,7 @@ roominfo=white
roommention=bold_blue
roommention.term=bold_blue
roomtrigger=bold_blue
roomtrigger.term=bold_blue
me=cyan
them=white
roster.header=bold_white

View File

@ -49,6 +49,7 @@ unsubscribed=black_bold
roommention=cyan
roommention.term=cyan
roomtrigger=cyan
roomtrigger.term=cyan
roster.header=yellow
roster.chat=green
roster.online=green

View File

@ -47,6 +47,7 @@ roominfo=bold_yellow
roommention=bold_green
roommention.term=bold_green
roomtrigger=bold_green
roomtrigger.term=bold_green
me=bold_cyan
them=bold_magenta
roster.header=bold_magenta

View File

@ -46,7 +46,8 @@ error=red
roominfo=yellow
roommention=bold_white
roommention.term=bold_cyan
roomtrigger=bold_blue
roomtrigger=bold_white
roomtrigger.term=bold_blue
me=blue
them=bold_green
roster.header=bold_yellow

View File

@ -46,7 +46,8 @@ error=red
roominfo=yellow
roommention=bold_white
roommention.term=bold_cyan
roomtrigger=bold_blue
roomtrigger=bold_white
roomtrigger.term=bold_blue
me=blue
them=bold_green
roster.header=bold_yellow

View File

@ -47,6 +47,7 @@ roominfo=yellow
roommention=bold_cyan
roommention.term=bold_cyan
roomtrigger=bold_cyan
roomtrigger.term=bold_cyan
me=blue
them=bold_blue
roster.header=bold_green

View File

@ -47,6 +47,7 @@ roominfo=green
roommention=bold_green
roommention.term=bold_green
roomtrigger=bold_green
roomtrigger.term=bold_green
me=green
them=bold_green
roster.header=bold_green

View File

@ -47,6 +47,7 @@ roominfo=white
roommention=bold_green
roommention.term=bold_green
roomtrigger=bold_green
roomtrigger.term=bold_green
me=white
them=white
roster.header=bold_cyan

View File

@ -47,6 +47,7 @@ roominfo=green
roommention=green
roommention.term=green
roomtrigger=green
roomtrigger.term=green
me=magenta
them=green
roster.header=magenta

View File

@ -47,6 +47,7 @@ roominfo=white
roommention=white
roommention.term=white
roomtrigger=white
roomtrigger.term=white
me=white
them=white
roster.header=white

View File

@ -47,6 +47,7 @@ roominfo=blue
roommention=blue
roommention.term=blue
roomtrigger=blue
roomtrigger.term=blue
me=black
them=black
roster.header=black

View File

@ -47,6 +47,7 @@ roominfo=yellow
roommention=yellow
roommention.term=yellow
roomtrigger=yellow
roomtrigger.term=yellow
me=yellow
them=green
roster.header=yellow

View File

@ -47,6 +47,7 @@ roominfo=bold_yellow
roommention=bold_yellow
roommention.term=bold_yellow
roomtrigger=bold_yellow
roomtrigger.term=bold_yellow
me=bold_yellow
them=bold_green
roster.header=bold_yellow

View File

@ -47,6 +47,7 @@ roominfo=green
roommention=green
roommention.term=green
roomtrigger=green
roomtrigger.term=green
me=bold_black
them=magenta
roster.header=magenta

View File

@ -47,6 +47,7 @@ roominfo=green
roommention=red
roommention.term=red
roomtrigger=red
roomtrigger.term=red
me=green
them=yellow
roster.header=white

View File

@ -47,6 +47,7 @@ roominfo=yellow
roommention=yellow
roommention.term=yellow
roomtrigger=yellow
roomtrigger.term=yellow
me=black
them=black
roster.header=black