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

having wprintw go through win_save_(v)print.

Signed-off-by: James Booth <boothj5@gmail.com>
This commit is contained in:
Immae 2014-06-21 10:16:50 +02:00 committed by James Booth
parent 5e841febd0
commit 66ad23b35b
5 changed files with 314 additions and 593 deletions

View File

@ -54,7 +54,7 @@ static void
_cons_show_time(void)
{
ProfWin *console = wins_get_console();
win_print_time(console, '-');
win_save_print(console, '-', NULL, NO_EOL, 0, "", "");
if (wins_is_current(console)) {
win_update_virtual(console);
@ -65,7 +65,7 @@ static void
_cons_show_word(const char * const word)
{
ProfWin *console = wins_get_console();
wprintw(console->win, "%s", word);
win_save_print(console, '-', NULL, NO_EOL_DATE, 0, "", word);
if (wins_is_current(console)) {
win_update_virtual(console);
@ -81,8 +81,7 @@ _cons_debug(const char * const msg, ...)
va_start(arg, msg);
GString *fmt_msg = g_string_new(NULL);
g_string_vprintf(fmt_msg, msg, arg);
win_print_time(console, '-');
wprintw(console->win, "%s\n", fmt_msg->str);
win_save_print(console, '-', NULL, 0, 0, "", fmt_msg->str);
g_string_free(fmt_msg, TRUE);
va_end(arg);
@ -104,8 +103,7 @@ _cons_show(const char * const msg, ...)
va_start(arg, msg);
GString *fmt_msg = g_string_new(NULL);
g_string_vprintf(fmt_msg, msg, arg);
win_print_time(console, '-');
wprintw(console->win, "%s\n", fmt_msg->str);
win_save_print(console, '-', NULL, 0, 0, "", fmt_msg->str);
g_string_free(fmt_msg, TRUE);
va_end(arg);
@ -122,10 +120,7 @@ _cons_show_error(const char * const msg, ...)
va_start(arg, msg);
GString *fmt_msg = g_string_new(NULL);
g_string_vprintf(fmt_msg, msg, arg);
win_print_time(console, '-');
wattron(console->win, COLOUR_ERROR);
wprintw(console->win, "%s\n", fmt_msg->str);
wattroff(console->win, COLOUR_ERROR);
win_save_print(console, '-', NULL, 0, COLOUR_ERROR, "", fmt_msg->str);
g_string_free(fmt_msg, TRUE);
va_end(arg);
@ -148,7 +143,7 @@ _cons_show_typing(const char * const barejid)
display_usr = barejid;
}
win_vprint_line(console, '-', COLOUR_TYPING, "!! %s is typing a message...", display_usr);
win_save_vprint(console, '-', NULL, 0, COLOUR_TYPING, "", "!! %s is typing a message...", display_usr);
if (wins_is_current(console)) {
win_update_virtual(console);
@ -166,10 +161,7 @@ _cons_show_incoming_message(const char * const short_from, const int win_index)
if (ui_index == 10) {
ui_index = 0;
}
win_print_time(console, '-');
wattron(console->win, COLOUR_INCOMING);
wprintw(console->win, "<< incoming from %s (%d)\n", short_from, ui_index);
wattroff(console->win, COLOUR_INCOMING);
win_save_vprint(console, '-', NULL, 0, COLOUR_INCOMING, "", "<< incoming from %s (%d)", short_from, ui_index);
if (wins_is_current(console)) {
win_update_virtual(console);
@ -188,37 +180,26 @@ _cons_about(void)
if (prefs_get_boolean(PREF_SPLASH)) {
_cons_splash_logo();
} else {
win_print_time(console, '-');
if (strcmp(PACKAGE_STATUS, "development") == 0) {
#ifdef HAVE_GIT_VERSION
wprintw(console->win, "Welcome to Profanity, version %sdev.%s.%s\n", PACKAGE_VERSION, PROF_GIT_BRANCH, PROF_GIT_REVISION);
win_save_vprint(console, '-', NULL, 0, 0, "", "Welcome to Profanity, version %sdev.%s.%s", PACKAGE_VERSION, PROF_GIT_BRANCH, PROF_GIT_REVISION);
#else
wprintw(console->win, "Welcome to Profanity, version %sdev\n", PACKAGE_VERSION);
win_save_vprint(console, '-', NULL, 0, 0, "", "Welcome to Profanity, version %sdev", PACKAGE_VERSION);
#endif
} else {
wprintw(console->win, "Welcome to Profanity, version %s\n", PACKAGE_VERSION);
win_save_vprint(console, '-', NULL, 0, 0, "", "Welcome to Profanity, version %s", PACKAGE_VERSION);
}
}
win_print_time(console, '-');
wprintw(console->win, "Copyright (C) 2012 - 2014 James Booth <%s>.\n", PACKAGE_BUGREPORT);
win_print_time(console, '-');
wprintw(console->win, "License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\n");
win_print_time(console, '-');
wprintw(console->win, "\n");
win_print_time(console, '-');
wprintw(console->win, "This is free software; you are free to change and redistribute it.\n");
win_print_time(console, '-');
wprintw(console->win, "There is NO WARRANTY, to the extent permitted by law.\n");
win_print_time(console, '-');
wprintw(console->win, "\n");
win_print_time(console, '-');
wprintw(console->win, "Type '/help' to show complete help.\n");
win_print_time(console, '-');
wprintw(console->win, "\n");
win_save_vprint(console, '-', NULL, 0, 0, "", "Copyright (C) 2012 - 2014 James Booth <%s>.", PACKAGE_BUGREPORT);
win_save_print(console, '-', NULL, 0, 0, "", "License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>");
win_save_print(console, '-', NULL, 0, 0, "", "");
win_save_print(console, '-', NULL, 0, 0, "", "This is free software; you are free to change and redistribute it.");
win_save_print(console, '-', NULL, 0, 0, "", "There is NO WARRANTY, to the extent permitted by law.");
win_save_print(console, '-', NULL, 0, 0, "", "");
win_save_print(console, '-', NULL, 0, 0, "", "Type '/help' to show complete help.");
win_save_print(console, '-', NULL, 0, 0, "", "");
if (prefs_get_boolean(PREF_VERCHECK)) {
cons_check_version(FALSE);
@ -244,17 +225,14 @@ _cons_check_version(gboolean not_available_msg)
if (relase_valid) {
if (release_is_new(latest_release)) {
win_print_time(console, '-');
wprintw(console->win, "A new version of Profanity is available: %s", latest_release);
win_print_time(console, '-');
wprintw(console->win, "Check <http://www.profanity.im> for details.\n");
win_save_vprint(console, '-', NULL, 0, 0, "", "A new version of Profanity is available: %s", latest_release);
win_save_print(console, '-', NULL, 0, 0, "", "Check <http://www.profanity.im> for details.");
free(latest_release);
win_print_time(console, '-');
wprintw(console->win, "\n");
win_save_print(console, '-', NULL, 0, 0, "", "");
} else {
if (not_available_msg) {
cons_show("No new version available.");
cons_show("");
win_save_print(console, '-', NULL, 0, 0, "", "No new version available.");
win_save_print(console, '-', NULL, 0, 0, "", "");
}
}
@ -271,18 +249,16 @@ static void
_cons_show_login_success(ProfAccount *account)
{
ProfWin *console = wins_get_console();
win_print_time(console, '-');
wprintw(console->win, "%s logged in successfully, ", account->jid);
win_save_vprint(console, '-', NULL, NO_EOL, 0, "", "%s logged in successfully, ", account->jid);
resource_presence_t presence = accounts_get_login_presence(account->name);
const char *presence_str = string_from_resource_presence(presence);
win_presence_colour_on(console, presence_str);
wprintw(console->win, "%s", presence_str);
win_presence_colour_off(console, presence_str);
wprintw(console->win, " (priority %d)",
int presence_colour = win_presence_colour(presence_str);
win_save_vprint(console, '-', NULL, NO_EOL_DATE, presence_colour, "", "%s", presence_str);
win_save_vprint(console, '-', NULL, NO_EOL_DATE, 0, "", " (priority %d)",
accounts_get_priority_for_presence_type(account->name, presence));
wprintw(console->win, ".\n");
win_save_print(console, '-', NULL, NO_DATE, 0, "", ".");
if (wins_is_current(console)) {
win_update_virtual(console);
}
@ -299,9 +275,7 @@ _cons_show_wins(void)
GSList *curr = window_strings;
while (curr != NULL) {
win_print_time(console, '-');
wprintw(console->win, curr->data);
wprintw(console->win, "\n");
win_save_print(console, '-', NULL, 0, 0, "", curr->data);
curr = g_slist_next(curr);
}
@ -349,67 +323,61 @@ static void
_cons_show_caps(const char * const contact, Resource *resource)
{
ProfWin *console = wins_get_console();
WINDOW *win = console->win;
cons_show("");
const char *resource_presence = string_from_resource_presence(resource->presence);
win_print_time(console, '-');
win_presence_colour_on(console, resource_presence);
wprintw(console->win, "%s", contact);
win_presence_colour_off(console, resource_presence);
wprintw(win, ":\n");
int presence_colour = win_presence_colour(resource_presence);
win_save_vprint(console, '-', NULL, NO_EOL, presence_colour, "", "%s", contact);
win_save_print(console, '-', NULL, NO_DATE, 0, "", ":");
if (resource->caps_str != NULL) {
Capabilities *caps = caps_get(resource->caps_str);
if (caps != NULL) {
// show identity
if ((caps->category != NULL) || (caps->type != NULL) || (caps->name != NULL)) {
win_print_time(console, '-');
wprintw(win, "Identity: ");
win_save_print(console, '-', NULL, NO_EOL, 0, "", "Identity: ");
if (caps->name != NULL) {
wprintw(win, "%s", caps->name);
win_save_print(console, '-', NULL, NO_EOL_DATE, 0, "", caps->name);
if ((caps->category != NULL) || (caps->type != NULL)) {
wprintw(win, " ");
win_save_print(console, '-', NULL, NO_EOL_DATE, 0, "", " ");
}
}
if (caps->type != NULL) {
wprintw(win, "%s", caps->type);
win_save_print(console, '-', NULL, NO_EOL_DATE, 0, "", caps->type);
if (caps->category != NULL) {
wprintw(win, " ");
win_save_print(console, '-', NULL, NO_EOL_DATE, 0, "", " ");
}
}
if (caps->category != NULL) {
wprintw(win, "%s", caps->category);
win_save_print(console, '-', NULL, NO_EOL_DATE, 0, "", caps->category);
}
wprintw(win, "\n");
win_save_print(console, '-', NULL, NO_DATE, 0, "", "");
}
if (caps->software != NULL) {
win_print_time(console, '-');
wprintw(win, "Software: %s", caps->software);
win_save_vprint(console, '-', NULL, NO_EOL, 0, "", "Software: %s", caps->software);
}
if (caps->software_version != NULL) {
wprintw(win, ", %s", caps->software_version);
win_save_vprint(console, '-', NULL, NO_EOL_DATE, 0, "", ", %s", caps->software_version);
}
if ((caps->software != NULL) || (caps->software_version != NULL)) {
wprintw(win, "\n");
win_save_print(console, '-', NULL, NO_DATE, 0, "", "");
}
if (caps->os != NULL) {
win_print_time(console, '-');
wprintw(win, "OS: %s", caps->os);
win_save_vprint(console, '-', NULL, NO_EOL, 0, "", "OS: %s", caps->os);
}
if (caps->os_version != NULL) {
wprintw(win, ", %s", caps->os_version);
win_save_vprint(console, '-', NULL, NO_EOL_DATE, 0, "", ", %s", caps->os_version);
}
if ((caps->os != NULL) || (caps->os_version != NULL)) {
wprintw(win, "\n");
win_save_print(console, '-', NULL, NO_DATE, 0, "", "");
}
if (caps->features != NULL) {
win_print_time(console, '-');
wprintw(win, "Features:\n");
win_save_print(console, '-', NULL, 0, 0, "", "Features:");
GSList *feature = caps->features;
while (feature != NULL) {
win_print_time(console, '-');
wprintw(win, " %s\n", feature->data);
win_save_vprint(console, '-', NULL, 0, 0, "", " %s", feature->data);
feature = g_slist_next(feature);
}
}
@ -429,11 +397,9 @@ _cons_show_software_version(const char * const jid, const char * const presence
ProfWin *console = wins_get_console();
if ((name != NULL) || (version != NULL) || (os != NULL)) {
cons_show("");
win_print_time(console, '-');
win_presence_colour_on(console, presence);
wprintw(console->win, "%s", jid);
win_presence_colour_off(console, presence);
wprintw(console->win, ":\n");
int presence_colour = win_presence_colour(presence);
win_save_vprint(console, '-', NULL, NO_EOL, presence_colour, "", "%s", jid);
win_save_print(console, '-', NULL, NO_DATE, 0, "", ":");
}
if (name != NULL) {
cons_show("Name : %s", name);
@ -499,12 +465,11 @@ _cons_show_room_list(GSList *rooms, const char * const conference_node)
cons_show("Chat rooms at %s:", conference_node);
while (rooms != NULL) {
DiscoItem *room = rooms->data;
win_print_time(console, '-');
wprintw(console->win, " %s", room->jid);
win_save_vprint(console, '-', NULL, NO_EOL, 0, "", " %s", room->jid);
if (room->name != NULL) {
wprintw(console->win, ", (%s)", room->name);
win_save_vprint(console, '-', NULL, NO_EOL_DATE, 0, "", ", (%s)", room->name);
}
wprintw(console->win, "\n");
win_save_print(console, '-', NULL, NO_DATE, 0, "", "");
rooms = g_slist_next(rooms);
}
} else {
@ -532,32 +497,29 @@ _cons_show_bookmarks(const GList *list)
while (list != NULL) {
Bookmark *item = list->data;
win_print_time(console, '-');
int presence_colour = 0;
if (muc_room_is_active(item->jid)) {
wattron(console->win, COLOUR_ONLINE);
presence_colour = COLOUR_ONLINE;
}
wprintw(console->win, " %s", item->jid);
win_save_vprint(console, '-', NULL, NO_EOL, presence_colour, "", " %s", item->jid);
if (item->nick != NULL) {
wprintw(console->win, "/%s", item->nick);
win_save_vprint(console, '-', NULL, NO_EOL_DATE, presence_colour, "", "/%s", item->nick);
}
if (item->autojoin) {
wprintw(console->win, " (autojoin)");
win_save_print(console, '-', NULL, NO_EOL_DATE, presence_colour, "", " (autojoin)");
}
if (item->password != NULL) {
wprintw(console->win, " (private)");
win_save_print(console, '-', NULL, NO_EOL_DATE, presence_colour, "", " (private)");
}
if (muc_room_is_active(item->jid)) {
ProfWin *roomwin = wins_get_by_recipient(item->jid);
if (roomwin != NULL) {
int num = wins_get_num(roomwin);
wprintw(console->win, " (");
wprintw(console->win, "%d", num);
wprintw(console->win, ")");
win_save_vprint(console, '-', NULL, NO_EOL_DATE, presence_colour, "", " (%d)", num);
}
wattroff(console->win, COLOUR_ONLINE);
}
wprintw(console->win, "\n");
win_save_print(console, '-', NULL, NO_DATE, 0, "", "");
list = g_list_next(list);
}
@ -623,12 +585,11 @@ _cons_show_disco_items(GSList *items, const char * const jid)
cons_show("Service discovery items for %s:", jid);
while (items != NULL) {
DiscoItem *item = items->data;
win_print_time(console, '-');
wprintw(console->win, " %s", item->jid);
win_save_vprint(console, '-', NULL, NO_EOL, 0, "", " %s", item->jid);
if (item->name != NULL) {
wprintw(console->win, ", (%s)", item->name);
win_save_vprint(console, '-', NULL, NO_EOL_DATE, 0, "", ", (%s)", item->name);
}
wprintw(console->win, "\n");
win_save_vprint(console, '-', NULL, NO_DATE, 0, "", "");
items = g_slist_next(items);
}
} else {
@ -712,10 +673,8 @@ _cons_show_account_list(gchar **accounts)
if ((jabber_get_connection_status() == JABBER_CONNECTED) &&
(g_strcmp0(jabber_get_account_name(), accounts[i]) == 0)) {
resource_presence_t presence = accounts_get_last_presence(accounts[i]);
win_print_time(console, '-');
win_presence_colour_on(console, string_from_resource_presence(presence));
wprintw(console->win, "%s\n", accounts[i]);
win_presence_colour_off(console, string_from_resource_presence(presence));
int presence_colour = win_presence_colour(string_from_resource_presence(presence));
win_save_vprint(console, '-', NULL, 0, presence_colour, "", "%s", accounts[i]);
} else {
cons_show(accounts[i]);
}
@ -821,10 +780,8 @@ _cons_show_account(ProfAccount *account)
GList *resources = jabber_get_available_resources();
GList *ordered_resources = NULL;
WINDOW *win = console->win;
if (resources != NULL) {
win_print_time(console, '-');
wprintw(win, "Resources:\n");
win_save_print(console, '-', NULL, 0, 0, "", "Resources:");
// sort in order of availabiltiy
while (resources != NULL) {
@ -838,58 +795,54 @@ _cons_show_account(ProfAccount *account)
while (ordered_resources != NULL) {
Resource *resource = ordered_resources->data;
const char *resource_presence = string_from_resource_presence(resource->presence);
win_print_time(console, '-');
win_presence_colour_on(console, resource_presence);
wprintw(win, " %s (%d), %s", resource->name, resource->priority, resource_presence);
int presence_colour = win_presence_colour(resource_presence);
win_save_vprint(console, '-', NULL, NO_EOL, presence_colour, "", " %s (%d), %s", resource->name, resource->priority, resource_presence);
if (resource->status != NULL) {
wprintw(win, ", \"%s\"", resource->status);
win_save_vprint(console, '-', NULL, NO_EOL_DATE, presence_colour, "", ", \"%s\"", resource->status);
}
wprintw(win, "\n");
win_presence_colour_off(console, resource_presence);
win_save_vprint(console, '-', NULL, NO_DATE, 0, "", "");
if (resource->caps_str != NULL) {
Capabilities *caps = caps_get(resource->caps_str);
if (caps != NULL) {
// show identity
if ((caps->category != NULL) || (caps->type != NULL) || (caps->name != NULL)) {
win_print_time(console, '-');
wprintw(win, " Identity: ");
win_save_print(console, '-', NULL, NO_EOL, 0, "", " Identity: ");
if (caps->name != NULL) {
wprintw(win, "%s", caps->name);
win_save_print(console, '-', NULL, NO_EOL_DATE, 0, "", caps->name);
if ((caps->category != NULL) || (caps->type != NULL)) {
wprintw(win, " ");
win_save_print(console, '-', NULL, NO_EOL_DATE, 0, "", " ");
}
}
if (caps->type != NULL) {
wprintw(win, "%s", caps->type);
win_save_print(console, '-', NULL, NO_EOL_DATE, 0, "", caps->type);
if (caps->category != NULL) {
wprintw(win, " ");
win_save_print(console, '-', NULL, NO_EOL_DATE, 0, "", " ");
}
}
if (caps->category != NULL) {
wprintw(win, "%s", caps->category);
win_save_print(console, '-', NULL, NO_EOL_DATE, 0, "", caps->category);
}
wprintw(win, "\n");
win_save_print(console, '-', NULL, NO_DATE, 0, "", "");
}
if (caps->software != NULL) {
win_print_time(console, '-');
wprintw(win, " Software: %s", caps->software);
win_save_vprint(console, '-', NULL, NO_EOL, 0, "", " Software: %s", caps->software);
}
if (caps->software_version != NULL) {
wprintw(win, ", %s", caps->software_version);
win_save_vprint(console, '-', NULL, NO_EOL_DATE, 0, "", ", %s", caps->software_version);
}
if ((caps->software != NULL) || (caps->software_version != NULL)) {
wprintw(win, "\n");
win_save_print(console, '-', NULL, NO_DATE, 0, "", "");
}
if (caps->os != NULL) {
win_print_time(console, '-');
wprintw(win, " OS: %s", caps->os);
win_save_vprint(console, '-', NULL, NO_EOL, 0, "", " OS: %s", caps->os);
}
if (caps->os_version != NULL) {
wprintw(win, ", %s", caps->os_version);
win_save_vprint(console, '-', NULL, NO_EOL_DATE, 0, "", ", %s", caps->os_version);
}
if ((caps->os != NULL) || (caps->os_version != NULL)) {
wprintw(win, "\n");
win_save_print(console, '-', NULL, NO_DATE, 0, "", "");
}
}
}
@ -1568,55 +1521,25 @@ static void
_cons_splash_logo(void)
{
ProfWin *console = wins_get_console();
win_print_time(console, '-');
wprintw(console->win, "Welcome to\n");
win_save_print(console, '-', NULL, 0, 0, "", "Welcome to");
win_print_time(console, '-');
wattron(console->win, COLOUR_SPLASH);
wprintw(console->win, " ___ _ \n");
wattroff(console->win, COLOUR_SPLASH);
win_save_print(console, '-', NULL, 0, COLOUR_SPLASH, "", " ___ _ ");
win_save_print(console, '-', NULL, 0, COLOUR_SPLASH, "", " / __) (_)_ ");
win_save_print(console, '-', NULL, 0, COLOUR_SPLASH, "", " ____ ____ ___ | |__ ____ ____ _| |_ _ _ ");
win_save_print(console, '-', NULL, 0, COLOUR_SPLASH, "", "| _ \\ / ___) _ \\| __) _ | _ \\| | _) | | |");
win_save_print(console, '-', NULL, 0, COLOUR_SPLASH, "", "| | | | | | |_| | | ( ( | | | | | | |_| |_| |");
win_save_print(console, '-', NULL, 0, COLOUR_SPLASH, "", "| ||_/|_| \\___/|_| \\_||_|_| |_|_|\\___)__ |");
win_save_print(console, '-', NULL, 0, COLOUR_SPLASH, "", "|_| (____/ ");
win_save_print(console, '-', NULL, 0, COLOUR_SPLASH, "", "");
win_print_time(console, '-');
wattron(console->win, COLOUR_SPLASH);
wprintw(console->win, " / __) (_)_ \n");
wattroff(console->win, COLOUR_SPLASH);
win_print_time(console, '-');
wattron(console->win, COLOUR_SPLASH);
wprintw(console->win, " ____ ____ ___ | |__ ____ ____ _| |_ _ _ \n");
wattroff(console->win, COLOUR_SPLASH);
win_print_time(console, '-');
wattron(console->win, COLOUR_SPLASH);
wprintw(console->win, "| _ \\ / ___) _ \\| __) _ | _ \\| | _) | | |\n");
wattroff(console->win, COLOUR_SPLASH);
win_print_time(console, '-');
wattron(console->win, COLOUR_SPLASH);
wprintw(console->win, "| | | | | | |_| | | ( ( | | | | | | |_| |_| |\n");
wattroff(console->win, COLOUR_SPLASH);
win_print_time(console, '-');
wattron(console->win, COLOUR_SPLASH);
wprintw(console->win, "| ||_/|_| \\___/|_| \\_||_|_| |_|_|\\___)__ |\n");
wattroff(console->win, COLOUR_SPLASH);
win_print_time(console, '-');
wattron(console->win, COLOUR_SPLASH);
wprintw(console->win, "|_| (____/ \n");
wattroff(console->win, COLOUR_SPLASH);
win_print_time(console, '-');
wprintw(console->win, "\n");
win_print_time(console, '-');
if (strcmp(PACKAGE_STATUS, "development") == 0) {
#ifdef HAVE_GIT_VERSION
wprintw(console->win, "Version %sdev.%s.%s\n", PACKAGE_VERSION, PROF_GIT_BRANCH, PROF_GIT_REVISION);
win_save_vprint(console, '-', NULL, 0, 0, "", "Version %sdev.%s.%s\n", PACKAGE_VERSION, PROF_GIT_BRANCH, PROF_GIT_REVISION);
#else
wprintw(console->win, "Version %sdev\n", PACKAGE_VERSION);
win_save_vprint(console, '-', NULL, 0, 0, "", "Version %sdev\n", PACKAGE_VERSION);
#endif
} else {
wprintw(console->win, "Version %s\n", PACKAGE_VERSION);
win_save_vprint(console, '-', NULL, 0, 0, "", "Version %s\n", PACKAGE_VERSION);
}
}
@ -1637,21 +1560,17 @@ _show_roster_contacts(GSList *list, gboolean show_groups)
}
const char *presence = p_contact_presence(contact);
win_print_time(console, '-');
int presence_colour;
if (p_contact_subscribed(contact)) {
win_presence_colour_on(console, presence);
wprintw(console->win, "%s\n", title->str);
win_presence_colour_off(console, presence);
presence_colour = win_presence_colour(presence);
} else {
win_presence_colour_on(console, "offline");
wprintw(console->win, "%s\n", title->str);
win_presence_colour_off(console, "offline");
presence_colour = win_presence_colour("offline");
}
win_save_vprint(console, '-', NULL, 0, presence_colour, "", title->str);
g_string_free(title, TRUE);
win_print_time(console, '-');
wprintw(console->win, " Subscription : ");
win_save_print(console, '-', NULL, NO_EOL, 0, "", " Subscription : ");
GString *sub = g_string_new("");
sub = g_string_append(sub, p_contact_subscription(contact));
if (p_contact_pending_out(contact)) {
@ -1661,16 +1580,11 @@ _show_roster_contacts(GSList *list, gboolean show_groups)
sub = g_string_append(sub, ", request received");
}
if (p_contact_subscribed(contact)) {
wattron(console->win, COLOUR_SUBSCRIBED);
presence_colour = COLOUR_SUBSCRIBED;
} else {
wattron(console->win, COLOUR_UNSUBSCRIBED);
}
wprintw(console->win, "%s\n", sub->str);
if (p_contact_subscribed(contact)) {
wattroff(console->win, COLOUR_SUBSCRIBED);
} else {
wattroff(console->win, COLOUR_UNSUBSCRIBED);
presence_colour = COLOUR_UNSUBSCRIBED;
}
win_save_vprint(console, '-', NULL, NO_DATE, presence_colour, "", "%s", sub->str);
g_string_free(sub, TRUE);

View File

@ -67,8 +67,6 @@ static Display *display;
static GTimer *ui_idle_time;
static void _win_show_user(WINDOW *win, const char * const user, const int colour);
static void _win_show_message(WINDOW *win, const char * const message);
static void _win_handle_switch(const wint_t * const ch);
static void _win_handle_page(const wint_t * const ch);
static void _win_show_history(WINDOW *win, int win_index,
@ -234,13 +232,13 @@ _ui_handle_stanza(const char * const msg)
ProfWin *xmlconsole = wins_get_xmlconsole();
if (g_str_has_prefix(msg, "SENT:")) {
win_print_line_no_time(xmlconsole, 0, "SENT:");
win_print_line_no_time(xmlconsole, COLOUR_ONLINE, &msg[6]);
win_print_line_no_time(xmlconsole, COLOUR_ONLINE, "");
win_save_print(xmlconsole, '-', NULL, NO_DATE, 0, "", "SENT:");
win_save_print(xmlconsole, '-', NULL, NO_DATE, COLOUR_ONLINE, "", &msg[6]);
win_save_print(xmlconsole, '-', NULL, NO_DATE, COLOUR_ONLINE, "", "");
} else if (g_str_has_prefix(msg, "RECV:")) {
win_print_line_no_time(xmlconsole, 0, "RECV:");
win_print_line_no_time(xmlconsole, COLOUR_AWAY, &msg[6]);
win_print_line_no_time(xmlconsole, COLOUR_ONLINE, "");
win_save_print(xmlconsole, '-', NULL, NO_DATE, 0, "", "RECV:");
win_save_print(xmlconsole, '-', NULL, NO_DATE, COLOUR_AWAY, "", &msg[6]);
win_save_print(xmlconsole, '-', NULL, NO_DATE, COLOUR_AWAY, "", "");
}
if (wins_is_current(xmlconsole)) {
@ -514,13 +512,13 @@ _ui_handle_recipient_not_found(const char * const recipient, const char * const
} else if (win->type == WIN_MUC) {
g_string_printf(msg, "Room %s not found: %s", recipient, err_msg);
cons_show_error(msg->str);
win_print_line(win, '!', COLOUR_ERROR, msg->str);
win_save_print(win, '!', NULL, 0, COLOUR_ERROR, "", msg->str);
// unknown chat recipient
} else {
g_string_printf(msg, "Recipient %s not found: %s", recipient, err_msg);
cons_show_error(msg->str);
win_print_line(win, '!', COLOUR_ERROR, msg->str);
win_save_print(win, '!', NULL, 0, COLOUR_ERROR, "", msg->str);
}
ProfWin *current = wins_get_current();
@ -541,7 +539,7 @@ _ui_handle_recipient_error(const char * const recipient, const char * const err_
// show in window if exists for recipient
if (win != NULL) {
win_print_line(win, '!', COLOUR_ERROR, msg->str);
win_save_print(win, '!', NULL, 0, COLOUR_ERROR, "", msg->str);
}
ProfWin *current = wins_get_current();
@ -772,9 +770,9 @@ _ui_gone_secure(const char * const recipient, gboolean trusted)
window->is_otr = TRUE;
window->is_trusted = trusted;
if (trusted) {
win_vprint_line(window, '!', COLOUR_OTR_STARTED_TRUSTED, "OTR session started (trusted).");
win_save_print(window, '!', NULL, 0, COLOUR_OTR_STARTED_TRUSTED, "", "OTR session started (trusted).");
} else {
win_vprint_line(window, '!', COLOUR_OTR_STARTED_UNTRUSTED, "OTR session started (untrusted).");
win_save_print(window, '!', NULL, 0, COLOUR_OTR_STARTED_UNTRUSTED, "", "OTR session started (untrusted).");
}
if (wins_is_current(window)) {
@ -807,7 +805,7 @@ _ui_smp_recipient_initiated(const char * const recipient)
if (window == NULL) {
return;
} else {
win_vprint_line(window, '!', 0, "%s wants to authenticate your identity, use '/otr secret <secret>'.", recipient);
win_save_vprint(window, '!', NULL, 0, 0, "", "%s wants to authenticate your identity, use '/otr secret <secret>'.", recipient);
win_update_virtual(window);
if (wins_is_current(window)) {
ui_current_page_off();
@ -822,9 +820,9 @@ _ui_smp_recipient_initiated_q(const char * const recipient, const char *question
if (window == NULL) {
return;
} else {
win_vprint_line(window, '!', 0, "%s wants to authenticate your identity with the following question:", recipient);
win_vprint_line(window, '!', 0, " %s", question);
win_vprint_line(window, '!', 0, "use '/otr answer <answer>'.");
win_save_vprint(window, '!', NULL, 0, 0, "", "%s wants to authenticate your identity with the following question:", recipient);
win_save_vprint(window, '!', NULL, 0, 0, "", " %s", question);
win_save_print(window, '!', NULL, 0, 0, "", "use '/otr answer <answer>'.");
win_update_virtual(window);
if (wins_is_current(window)) {
ui_current_page_off();
@ -839,7 +837,7 @@ _ui_smp_unsuccessful_sender(const char * const recipient)
if (window == NULL) {
return;
} else {
win_vprint_line(window, '!', 0, "Authentication failed, the secret you entered does not match the secret entered by %s.", recipient);
win_save_vprint(window, '!', NULL, 0, 0, "", "Authentication failed, the secret you entered does not match the secret entered by %s.", recipient);
win_update_virtual(window);
if (wins_is_current(window)) {
ui_current_page_off();
@ -854,7 +852,7 @@ _ui_smp_unsuccessful_receiver(const char * const recipient)
if (window == NULL) {
return;
} else {
win_vprint_line(window, '!', 0, "Authentication failed, the secret entered by %s does not match yours.", recipient);
win_save_vprint(window, '!', NULL, 0, 0, "", "Authentication failed, the secret entered by %s does not match yours.", recipient);
win_update_virtual(window);
if (wins_is_current(window)) {
ui_current_page_off();
@ -869,7 +867,7 @@ _ui_smp_aborted(const char * const recipient)
if (window == NULL) {
return;
} else {
win_vprint_line(window, '!', 0, "SMP session aborted.");
win_save_print(window, '!', NULL, 0, 0, "", "SMP session aborted.");
win_update_virtual(window);
if (wins_is_current(window)) {
ui_current_page_off();
@ -884,7 +882,7 @@ _ui_smp_successful(const char * const recipient)
if (window == NULL) {
return;
} else {
win_vprint_line(window, '!', 0, "Authentication successful.");
win_save_print(window, '!', NULL, 0, 0, "", "Authentication successful.");
win_update_virtual(window);
if (wins_is_current(window)) {
ui_current_page_off();
@ -899,7 +897,7 @@ _ui_smp_answer_success(const char * const recipient)
if (window == NULL) {
return;
} else {
win_vprint_line(window, '!', 0, "%s successfully authenticated you.", recipient);
win_save_vprint(window, '!', NULL, 0, 0, "", "%s successfully authenticated you.", recipient);
win_update_virtual(window);
if (wins_is_current(window)) {
ui_current_page_off();
@ -914,7 +912,7 @@ _ui_smp_answer_failure(const char * const recipient)
if (window == NULL) {
return;
} else {
win_vprint_line(window, '!', 0, "%s failed to authenticated you.", recipient);
win_save_vprint(window, '!', NULL, 0, 0, "", "%s failed to authenticate you.", recipient);
win_update_virtual(window);
if (wins_is_current(window)) {
ui_current_page_off();
@ -929,7 +927,7 @@ _ui_gone_insecure(const char * const recipient)
if (window != NULL) {
window->is_otr = FALSE;
window->is_trusted = FALSE;
win_vprint_line(window, '!', COLOUR_OTR_ENDED, "OTR session ended.");
win_save_print(window, '!', NULL, 0, COLOUR_OTR_ENDED, "", "OTR session ended.");
if (wins_is_current(window)) {
GString *recipient_str = _get_recipient_string(window);
@ -948,7 +946,7 @@ _ui_trust(const char * const recipient)
if (window != NULL) {
window->is_otr = TRUE;
window->is_trusted = TRUE;
win_vprint_line(window, '!', COLOUR_OTR_TRUSTED, "OTR session trusted.");
win_save_print(window, '!', NULL, 0, COLOUR_OTR_TRUSTED, "", "OTR session trusted.");
if (wins_is_current(window)) {
GString *recipient_str = _get_recipient_string(window);
@ -967,7 +965,7 @@ _ui_untrust(const char * const recipient)
if (window != NULL) {
window->is_otr = TRUE;
window->is_trusted = FALSE;
win_vprint_line(window, '!', COLOUR_OTR_UNTRUSTED, "OTR session untrusted.");
win_save_print(window, '!', NULL, 0, COLOUR_OTR_UNTRUSTED, "", "OTR session untrusted.");
if (wins_is_current(window)) {
GString *recipient_str = _get_recipient_string(window);
@ -1124,7 +1122,7 @@ _ui_otr_authenticating(const char * const recipient)
if (window == NULL) {
return;
} else {
win_vprint_line(window, '!', 0, "Authenticating %s...", recipient);
win_save_vprint(window, '!', NULL, 0, 0, "", "Authenticating %s...", recipient);
win_update_virtual(window);
if (wins_is_current(window)) {
ui_current_page_off();
@ -1139,7 +1137,7 @@ _ui_otr_authetication_waiting(const char * const recipient)
if (window == NULL) {
return;
} else {
win_vprint_line(window, '!', 0, "Awaiting authentication from %s...", recipient);
win_save_vprint(window, '!', NULL, 0, 0, "", "Awaiting authentication from %s...", recipient);
win_update_virtual(window);
if (wins_is_current(window)) {
ui_current_page_off();
@ -1182,7 +1180,7 @@ _ui_current_print_line(const char * const msg, ...)
va_start(arg, msg);
GString *fmt_msg = g_string_new(NULL);
g_string_vprintf(fmt_msg, msg, arg);
win_print_line(current, '-', 0, fmt_msg->str);
win_save_print(current, '-', NULL, 0, 0, "", fmt_msg->str);
va_end(arg);
g_string_free(fmt_msg, TRUE);
win_update_virtual(current);
@ -1196,7 +1194,7 @@ _ui_current_print_formatted_line(const char show_char, int attrs, const char * c
va_start(arg, msg);
GString *fmt_msg = g_string_new(NULL);
g_string_vprintf(fmt_msg, msg, arg);
win_print_line(current, show_char, attrs, fmt_msg->str);
win_save_print(current, show_char, NULL, 0, attrs, "", fmt_msg->str);
va_end(arg);
g_string_free(fmt_msg, TRUE);
win_update_virtual(current);
@ -1206,7 +1204,7 @@ static void
_ui_current_error_line(const char * const msg)
{
ProfWin *current = wins_get_current();
win_print_line(current, '-', COLOUR_ERROR, msg);
win_save_print(current, '-', NULL, 0, COLOUR_ERROR, "", msg);
win_update_virtual(current);
}
@ -1240,8 +1238,7 @@ _ui_print_system_msg_from_recipient(const char * const from, const char *message
}
}
win_print_time(window, '-');
wprintw(window->win, "*%s %s\n", jid->barejid, message);
win_save_vprint(window, '-', NULL, 0, 0, "", "*%s %s", jid->barejid, message);
// this is the current window
if (wins_is_current(window)) {
@ -1267,7 +1264,7 @@ _ui_recipient_gone(const char * const barejid)
ProfWin *window = wins_get_by_recipient(barejid);
if (window != NULL) {
win_vprint_line(window, '!', COLOUR_GONE, "<- %s has left the conversation.", display_usr);
win_save_vprint(window, '!', NULL, 0, COLOUR_GONE, "", "<- %s has left the conversation.", display_usr);
if (wins_is_current(window)) {
win_update_virtual(window);
}
@ -1319,7 +1316,7 @@ _ui_create_duck_win(void)
ProfWin *window = wins_new("DuckDuckGo search", WIN_DUCK);
int num = wins_get_num(window);
ui_switch_win(num);
win_print_line(window, '-', 0, "Type ':help' to find out more.");
win_save_print(window, '-', NULL, 0, 0, "", "Type ':help' to find out more.");
}
static void
@ -1355,14 +1352,9 @@ _ui_duck(const char * const query)
{
ProfWin *window = wins_get_by_recipient("DuckDuckGo search");
if (window != NULL) {
win_print_time(window, '-');
wprintw(window->win, "\n");
win_print_time(window, '-');
wattron(window->win, COLOUR_ME);
wprintw(window->win, "Query : ");
wattroff(window->win, COLOUR_ME);
wprintw(window->win, query);
wprintw(window->win, "\n");
win_save_print(window, '-', NULL, 0, 0, "", "");
win_save_print(window, '-', NULL, NO_EOL, COLOUR_ME, "", "Query : ");
win_save_print(window, '-', NULL, NO_DATE, 0, "", query);
}
}
@ -1372,22 +1364,19 @@ _ui_duck_result(const char * const result)
ProfWin *window = wins_get_by_recipient("DuckDuckGo search");
if (window != NULL) {
win_print_time(window, '-');
wattron(window->win, COLOUR_THEM);
wprintw(window->win, "Result : ");
wattroff(window->win, COLOUR_THEM);
win_save_print(window, '-', NULL, NO_EOL, COLOUR_THEM, "", "Result : ");
glong offset = 0;
while (offset < g_utf8_strlen(result, -1)) {
gchar *ptr = g_utf8_offset_to_pointer(result, offset);
gunichar unichar = g_utf8_get_char(ptr);
if (unichar == '\n') {
wprintw(window->win, "\n");
win_print_time(window, '-');
win_save_print(window, '-', NULL, NO_DATE, 0, "", "");
win_save_print(window, '-', NULL, NO_EOL, 0, "", "");
} else {
gchar *string = g_ucs4_to_utf8(&unichar, 1, NULL, NULL, NULL);
if (string != NULL) {
wprintw(window->win, string);
win_save_print(window, '-', NULL, NO_EOL_DATE, 0, "", string);
g_free(string);
}
}
@ -1395,7 +1384,7 @@ _ui_duck_result(const char * const result)
offset++;
}
wprintw(window->win, "\n");
win_save_print(window, '-', NULL, NO_DATE, 0, "", "");
}
}
@ -1442,17 +1431,7 @@ _ui_outgoing_msg(const char * const from, const char * const to,
num = wins_get_num(window);
}
win_print_time(window, '-');
if (strncmp(message, "/me ", 4) == 0) {
wattron(window->win, COLOUR_ME);
wprintw(window->win, "*%s ", from);
wprintw(window->win, "%s", message + 4);
wprintw(window->win, "\n");
wattroff(window->win, COLOUR_ME);
} else {
_win_show_user(window->win, from, 0);
_win_show_message(window->win, message);
}
win_save_print(window, '-', NULL, 0, 0, from, message);
ui_switch_win(num);
}
@ -1475,7 +1454,7 @@ _ui_room_join(const char * const room, gboolean focus)
status_bar_active(num);
ProfWin *console = wins_get_console();
char *nick = muc_get_room_nick(room);
win_vprint_line(console, '!', COLOUR_TYPING, "-> Autojoined %s as %s (%d).", room, nick, num);
win_save_vprint(window, '!', NULL, 0, COLOUR_TYPING, "", "-> Autojoined %s as %s (%d).", room, nick, num);
win_update_virtual(console);
}
}
@ -1485,29 +1464,20 @@ _ui_room_roster(const char * const room, GList *roster, const char * const prese
{
ProfWin *window = wins_get_by_recipient(room);
win_print_time(window, '!');
if ((roster == NULL) || (g_list_length(roster) == 0)) {
wattron(window->win, COLOUR_ROOMINFO);
if (presence == NULL) {
wprintw(window->win, "Room is empty.\n");
win_save_print(window, '!', NULL, 0, COLOUR_ROOMINFO, "", "Room is empty.");
} else {
wprintw(window->win, "No participants %s.\n", presence);
win_save_vprint(window, '!', NULL, 0, COLOUR_ROOMINFO, "", "No participants %s.", presence);
}
wattroff(window->win, COLOUR_ROOMINFO);
} else {
int length = g_list_length(roster);
wattron(window->win, COLOUR_ROOMINFO);
if (presence == NULL) {
length++;
wprintw(window->win, "%d participants: ", length);
wattroff(window->win, COLOUR_ROOMINFO);
wattron(window->win, COLOUR_ONLINE);
wprintw(window->win, "%s", muc_get_room_nick(room));
wprintw(window->win, ", ");
win_save_vprint(window, '!', NULL, NO_EOL, COLOUR_ROOMINFO, "", "%d participants: ", length);
win_save_vprint(window, '!', NULL, NO_EOL_DATE, COLOUR_ONLINE, "", "%s, ", muc_get_room_nick(room));
} else {
wprintw(window->win, "%d %s: ", length, presence);
wattroff(window->win, COLOUR_ROOMINFO);
wattron(window->win, COLOUR_ONLINE);
win_save_vprint(window, '!', NULL, NO_EOL, COLOUR_ROOMINFO, "", "%d %s: ", length, presence);
}
while (roster != NULL) {
@ -1515,19 +1485,17 @@ _ui_room_roster(const char * const room, GList *roster, const char * const prese
const char *nick = p_contact_barejid(member);
const char *show = p_contact_presence(member);
win_presence_colour_on(window, show);
wprintw(window->win, "%s", nick);
win_presence_colour_off(window, show);
int presence_colour = win_presence_colour(show);
win_save_vprint(window, '!', NULL, NO_EOL_DATE, COLOUR_ONLINE|presence_colour, "", "%s", nick);
if (roster->next != NULL) {
wprintw(window->win, ", ");
win_save_print(window, '!', NULL, NO_EOL_DATE, COLOUR_ONLINE, "", ", ");
}
roster = g_list_next(roster);
}
win_save_print(window, '!', NULL, NO_DATE, COLOUR_ONLINE, "", "");
wprintw(window->win, "\n");
wattroff(window->win, COLOUR_ONLINE);
}
if (wins_is_current(window)) {
@ -1546,10 +1514,7 @@ _ui_room_member_offline(const char * const room, const char * const nick)
{
ProfWin *window = wins_get_by_recipient(room);
win_print_time(window, '!');
wattron(window->win, COLOUR_OFFLINE);
wprintw(window->win, "<- %s has left the room.\n", nick);
wattroff(window->win, COLOUR_OFFLINE);
win_save_vprint(window, '!', NULL, 0, COLOUR_OFFLINE, "", "<- %s has left the room.", nick);
if (wins_is_current(window)) {
win_update_virtual(window);
@ -1562,10 +1527,7 @@ _ui_room_member_online(const char * const room, const char * const nick,
{
ProfWin *window = wins_get_by_recipient(room);
win_print_time(window, '!');
wattron(window->win, COLOUR_ONLINE);
wprintw(window->win, "-> %s has joined the room.\n", nick);
wattroff(window->win, COLOUR_ONLINE);
win_save_vprint(window, '!', NULL, 0, COLOUR_ONLINE, "", "-> %s has joined the room.", nick);
if (wins_is_current(window)) {
win_update_virtual(window);
@ -1593,10 +1555,7 @@ _ui_room_member_nick_change(const char * const room,
{
ProfWin *window = wins_get_by_recipient(room);
win_print_time(window, '!');
wattron(window->win, COLOUR_THEM);
wprintw(window->win, "** %s is now known as %s\n", old_nick, nick);
wattroff(window->win, COLOUR_THEM);
win_save_vprint(window, '!', NULL, 0, COLOUR_THEM, "", "** %s is now known as %s", old_nick, nick);
if (wins_is_current(window)) {
win_update_virtual(window);
@ -1608,10 +1567,7 @@ _ui_room_nick_change(const char * const room, const char * const nick)
{
ProfWin *window = wins_get_by_recipient(room);
win_print_time(window, '!');
wattron(window->win, COLOUR_ME);
wprintw(window->win, "** You are now known as %s\n", nick);
wattroff(window->win, COLOUR_ME);
win_save_vprint(window, '!', NULL, 0, COLOUR_ME, "", "** You are now known as %s", nick);
if (wins_is_current(window)) {
win_update_virtual(window);
@ -1624,20 +1580,7 @@ _ui_room_history(const char * const room_jid, const char * const nick,
{
ProfWin *window = wins_get_by_recipient(room_jid);
GDateTime *time = g_date_time_new_from_timeval_utc(&tv_stamp);
gchar *date_fmt = g_date_time_format(time, "%H:%M:%S");
wprintw(window->win, "%s - ", date_fmt);
g_date_time_unref(time);
g_free(date_fmt);
if (strncmp(message, "/me ", 4) == 0) {
wprintw(window->win, "*%s ", nick);
waddstr(window->win, message + 4);
wprintw(window->win, "\n");
} else {
wprintw(window->win, "%s: ", nick);
_win_show_message(window->win, message);
}
win_save_vprint(window, '-', (&tv_stamp), 8, 0, nick, message);
if (wins_is_current(window)) {
win_update_virtual(window);
@ -1651,30 +1594,10 @@ _ui_room_message(const char * const room_jid, const char * const nick,
ProfWin *window = wins_get_by_recipient(room_jid);
int num = wins_get_num(window);
win_print_time(window, '-');
if (strcmp(nick, muc_get_room_nick(room_jid)) != 0) {
if (strncmp(message, "/me ", 4) == 0) {
wattron(window->win, COLOUR_THEM);
wprintw(window->win, "*%s ", nick);
waddstr(window->win, message + 4);
wprintw(window->win, "\n");
wattroff(window->win, COLOUR_THEM);
} else {
_win_show_user(window->win, nick, 1);
_win_show_message(window->win, message);
}
win_save_print(window, '-', NULL, 1, 0, nick, message);
} else {
if (strncmp(message, "/me ", 4) == 0) {
wattron(window->win, COLOUR_ME);
wprintw(window->win, "*%s ", nick);
waddstr(window->win, message + 4);
wprintw(window->win, "\n");
wattroff(window->win, COLOUR_ME);
} else {
_win_show_user(window->win, nick, 0);
_win_show_message(window->win, message);
}
win_save_print(window, '-', NULL, 0, 0, nick, message);
}
// currently in groupchat window
@ -1753,11 +1676,8 @@ _ui_room_subject(const char * const room_jid, const char * const subject)
ProfWin *window = wins_get_by_recipient(room_jid);
int num = wins_get_num(window);
win_print_time(window, '!');
wattron(window->win, COLOUR_ROOMINFO);
wprintw(window->win, "Room subject: ");
wattroff(window->win, COLOUR_ROOMINFO);
wprintw(window->win, "%s\n", subject);
win_save_vprint(window, '!', NULL, NO_EOL, COLOUR_ROOMINFO, "", "Room subject: ");
win_save_vprint(window, '!', NULL, NO_DATE, 0, "", "%s", subject);
// currently in groupchat window
if (wins_is_current(window)) {
@ -1776,11 +1696,8 @@ _ui_room_broadcast(const char * const room_jid, const char * const message)
ProfWin *window = wins_get_by_recipient(room_jid);
int num = wins_get_num(window);
win_print_time(window, '!');
wattron(window->win, COLOUR_ROOMINFO);
wprintw(window->win, "Room message: ");
wattroff(window->win, COLOUR_ROOMINFO);
wprintw(window->win, "%s\n", message);
win_save_vprint(window, '!', NULL, NO_EOL, COLOUR_ROOMINFO, "", "Room message: ");
win_save_vprint(window, '!', NULL, NO_DATE, 0, "", "%s", message);
// currently in groupchat window
if (wins_is_current(window)) {
@ -1803,7 +1720,7 @@ _ui_status(void)
if (pcontact != NULL) {
win_show_contact(current, pcontact);
} else {
win_print_line(current, '-', 0, "Error getting contact info.");
win_save_print(current, '-', NULL, 0, 0, "", "Error getting contact info.");
}
}
@ -1817,7 +1734,7 @@ _ui_info(void)
if (pcontact != NULL) {
win_show_info(current, pcontact);
} else {
win_print_line(current, '-', 0, "Error getting contact info.");
win_save_print(current, '-', NULL, 0, 0, "", "Error getting contact info.");
}
}
@ -1831,7 +1748,7 @@ _ui_status_private(void)
if (pcontact != NULL) {
win_show_contact(current, pcontact);
} else {
win_print_line(current, '-', 0, "Error getting contact info.");
win_save_print(current, '-', NULL, 0, 0, "", "Error getting contact info.");
}
jid_destroy(jid);
@ -1847,7 +1764,7 @@ _ui_info_private(void)
if (pcontact != NULL) {
win_show_info(current, pcontact);
} else {
win_print_line(current, '-', 0, "Error getting contact info.");
win_save_print(current, '-', NULL, 0, 0, "", "Error getting contact info.");
}
jid_destroy(jid);
@ -1862,7 +1779,7 @@ _ui_status_room(const char * const contact)
if (pcontact != NULL) {
win_show_contact(current, pcontact);
} else {
win_vprint_line(current, '-', 0, "No such participant \"%s\" in room.", contact);
win_save_vprint(current, '-', NULL, 0, 0, "", "No such participant \"%s\" in room.", contact);
}
}
@ -1875,7 +1792,7 @@ _ui_info_room(const char * const contact)
if (pcontact != NULL) {
win_show_info(current, pcontact);
} else {
win_vprint_line(current, '-', 0, "No such participant \"%s\" in room.", contact);
win_save_vprint(current, '-', NULL, 0, 0, "", "No such participant \"%s\" in room.", contact);
}
}
@ -1996,27 +1913,6 @@ _ui_draw_term_title(void)
}
}
static void
_win_show_user(WINDOW *win, const char * const user, const int colour)
{
if (colour)
wattron(win, COLOUR_THEM);
else
wattron(win, COLOUR_ME);
wprintw(win, "%s: ", user);
if (colour)
wattroff(win, COLOUR_THEM);
else
wattroff(win, COLOUR_ME);
}
static void
_win_show_message(WINDOW *win, const char * const message)
{
waddstr(win, message);
wprintw(win, "\n");
}
static void
_win_handle_switch(const wint_t * const ch)
{
@ -2163,7 +2059,7 @@ _win_show_history(WINDOW *win, int win_index, const char * const contact)
history = chat_log_get_previous(jid->barejid, contact, history);
jid_destroy(jid);
while (history != NULL) {
wprintw(win, "%s\n", history->data);
win_save_print(window, '-', NULL, NO_DATE, 0, "", history->data);
history = g_slist_next(history);
}
window->history_shown = 1;

View File

@ -37,9 +37,6 @@
#include "ui/window.h"
#include "xmpp/xmpp.h"
static void _win_chat_print_incoming_message(ProfWin *window, GTimeVal *tv_stamp,
const char * const from, const char * const message);
ProfWin*
win_create(const char * const title, int cols, win_type_t type)
{
@ -68,52 +65,6 @@ win_free(ProfWin* window)
free(window);
}
void
win_print_time(ProfWin* window, char show_char)
{
GDateTime *time = g_date_time_new_now_local();
gchar *date_fmt = g_date_time_format(time, "%H:%M:%S");
wattron(window->win, COLOUR_TIME);
wprintw(window->win, "%s %c ", date_fmt, show_char);
wattroff(window->win, COLOUR_TIME);
g_date_time_unref(time);
g_free(date_fmt);
}
void
win_print_line(ProfWin *window, const char show_char, int attrs,
const char * const msg)
{
win_print_time(window, show_char);
wattron(window->win, attrs);
wprintw(window->win, "%s\n", msg);
wattroff(window->win, attrs);
}
void
win_print_line_no_time(ProfWin *window, int attrs, const char * const msg)
{
wattron(window->win, attrs);
wprintw(window->win, "%s\n", msg);
wattroff(window->win, attrs);
}
void
win_vprint_line(ProfWin *window, const char show_char, int attrs,
const char * const msg, ...)
{
va_list arg;
va_start(arg, msg);
GString *fmt_msg = g_string_new(NULL);
g_string_vprintf(fmt_msg, msg, arg);
win_print_time(window, show_char);
wattron(window->win, attrs);
wprintw(window->win, "%s\n", fmt_msg->str);
wattroff(window->win, attrs);
g_string_free(fmt_msg, TRUE);
va_end(arg);
}
void
win_update_virtual(ProfWin *window)
{
@ -138,39 +89,21 @@ win_move_to_end(ProfWin *window)
}
}
void
win_presence_colour_on(ProfWin *window, const char * const presence)
int
win_presence_colour(const char * const presence)
{
if (g_strcmp0(presence, "online") == 0) {
wattron(window->win, COLOUR_ONLINE);
return COLOUR_ONLINE;
} else if (g_strcmp0(presence, "away") == 0) {
wattron(window->win, COLOUR_AWAY);
return COLOUR_AWAY;
} else if (g_strcmp0(presence, "chat") == 0) {
wattron(window->win, COLOUR_CHAT);
return COLOUR_CHAT;
} else if (g_strcmp0(presence, "dnd") == 0) {
wattron(window->win, COLOUR_DND);
return COLOUR_DND;
} else if (g_strcmp0(presence, "xa") == 0) {
wattron(window->win, COLOUR_XA);
return COLOUR_XA;
} else {
wattron(window->win, COLOUR_OFFLINE);
}
}
void
win_presence_colour_off(ProfWin *window, const char * const presence)
{
if (g_strcmp0(presence, "online") == 0) {
wattroff(window->win, COLOUR_ONLINE);
} else if (g_strcmp0(presence, "away") == 0) {
wattroff(window->win, COLOUR_AWAY);
} else if (g_strcmp0(presence, "chat") == 0) {
wattroff(window->win, COLOUR_CHAT);
} else if (g_strcmp0(presence, "dnd") == 0) {
wattroff(window->win, COLOUR_DND);
} else if (g_strcmp0(presence, "xa") == 0) {
wattroff(window->win, COLOUR_XA);
} else {
wattroff(window->win, COLOUR_OFFLINE);
return COLOUR_OFFLINE;
}
}
@ -183,43 +116,39 @@ win_show_contact(ProfWin *window, PContact contact)
const char *status = p_contact_status(contact);
GDateTime *last_activity = p_contact_last_activity(contact);
win_print_time(window, '-');
win_presence_colour_on(window, presence);
int presence_colour = win_presence_colour(presence);
if (name != NULL) {
wprintw(window->win, "%s", name);
win_save_print(window, '-', NULL, NO_EOL, presence_colour, "", name);
} else {
wprintw(window->win, "%s", barejid);
win_save_print(window, '-', NULL, NO_EOL, presence_colour, "", barejid);
}
wprintw(window->win, " is %s", presence);
win_save_vprint(window, '-', NULL, NO_EOL_DATE, presence_colour, "", " is %s", presence);
if (last_activity != NULL) {
GDateTime *now = g_date_time_new_now_local();
GTimeSpan span = g_date_time_difference(now, last_activity);
wprintw(window->win, ", idle ");
int hours = span / G_TIME_SPAN_HOUR;
span = span - hours * G_TIME_SPAN_HOUR;
if (hours > 0) {
wprintw(window->win, "%dh", hours);
}
int minutes = span / G_TIME_SPAN_MINUTE;
span = span - minutes * G_TIME_SPAN_MINUTE;
wprintw(window->win, "%dm", minutes);
int seconds = span / G_TIME_SPAN_SECOND;
wprintw(window->win, "%ds", seconds);
if (hours > 0) {
win_save_vprint(window, '-', NULL, NO_EOL_DATE, presence_colour, "", ", idle %dh%dm%ds", hours, minutes, seconds);
}
else {
win_save_vprint(window, '-', NULL, NO_EOL_DATE, presence_colour, "", ", idle %dm%ds", minutes, seconds);
}
}
if (status != NULL) {
wprintw(window->win, ", \"%s\"", p_contact_status(contact));
win_save_vprint(window, '-', NULL, NO_EOL_DATE, presence_colour, "", ", \"%s\"", p_contact_status(contact));
}
wprintw(window->win, "\n");
win_presence_colour_off(window, presence);
win_save_print(window, '-', NULL, NO_DATE, presence_colour, "", "");
}
void
@ -232,52 +161,42 @@ win_show_info(ProfWin *window, PContact contact)
GList *resources = p_contact_get_available_resources(contact);
GList *ordered_resources = NULL;
GDateTime *last_activity = p_contact_last_activity(contact);
WINDOW *win = window->win;
win_print_time(window, '-');
wprintw(win, "\n");
win_print_time(window, '-');
win_presence_colour_on(window, presence);
wprintw(win, "%s", barejid);
int presence_colour = win_presence_colour(presence);
win_save_print(window, '-', NULL, 0, 0, "", "");
win_save_print(window, '-', NULL, NO_EOL, presence_colour, "", barejid);
if (name != NULL) {
wprintw(win, " (%s)", name);
win_save_vprint(window, '-', NULL, NO_EOL_DATE, presence_colour, "", " (%s)", name);
}
win_presence_colour_off(window, presence);
wprintw(win, ":\n");
win_save_print(window, '-', NULL, NO_DATE, 0, "", ":");
if (sub != NULL) {
win_print_time(window, '-');
wprintw(win, "Subscription: %s\n", sub);
win_save_vprint(window, '-', NULL, 0, 0, "", "Subscription: %s", sub);
}
if (last_activity != NULL) {
GDateTime *now = g_date_time_new_now_local();
GTimeSpan span = g_date_time_difference(now, last_activity);
win_print_time(window, '-');
wprintw(win, "Last activity: ");
int hours = span / G_TIME_SPAN_HOUR;
span = span - hours * G_TIME_SPAN_HOUR;
if (hours > 0) {
wprintw(win, "%dh", hours);
}
int minutes = span / G_TIME_SPAN_MINUTE;
span = span - minutes * G_TIME_SPAN_MINUTE;
wprintw(win, "%dm", minutes);
int seconds = span / G_TIME_SPAN_SECOND;
wprintw(win, "%ds", seconds);
wprintw(win, "\n");
if (hours > 0) {
win_save_vprint(window, '-', NULL, 0, 0, "", "Last activity: %dh%dm%ds", hours, minutes, seconds);
}
else {
win_save_vprint(window, '-', NULL, 0, 0, "", "Last activity: %dm%ds", minutes, seconds);
}
g_date_time_unref(now);
}
if (resources != NULL) {
win_print_time(window, '-');
wprintw(win, "Resources:\n");
win_save_print(window, '-', NULL, 0, 0, "", "Resources:");
// sort in order of availabiltiy
while (resources != NULL) {
@ -291,58 +210,53 @@ win_show_info(ProfWin *window, PContact contact)
while (ordered_resources != NULL) {
Resource *resource = ordered_resources->data;
const char *resource_presence = string_from_resource_presence(resource->presence);
win_print_time(window, '-');
win_presence_colour_on(window, resource_presence);
wprintw(win, " %s (%d), %s", resource->name, resource->priority, resource_presence);
int presence_colour = win_presence_colour(resource_presence);
win_save_vprint(window, '-', NULL, NO_EOL, presence_colour, "", " %s (%d), %s", resource->name, resource->priority, resource_presence);
if (resource->status != NULL) {
wprintw(win, ", \"%s\"", resource->status);
win_save_vprint(window, '-', NULL, NO_EOL_DATE, presence_colour, "", ", \"%s\"", resource->status);
}
wprintw(win, "\n");
win_presence_colour_off(window, resource_presence);
win_save_print(window, '-', NULL, NO_DATE, 0, "", "");
if (resource->caps_str != NULL) {
Capabilities *caps = caps_get(resource->caps_str);
if (caps != NULL) {
// show identity
if ((caps->category != NULL) || (caps->type != NULL) || (caps->name != NULL)) {
win_print_time(window, '-');
wprintw(win, " Identity: ");
win_save_print(window, '-', NULL, NO_EOL, 0, "", " Identity: ");
if (caps->name != NULL) {
wprintw(win, "%s", caps->name);
win_save_print(window, '-', NULL, NO_EOL_DATE, 0, "", caps->name);
if ((caps->category != NULL) || (caps->type != NULL)) {
wprintw(win, " ");
win_save_print(window, '-', NULL, NO_EOL_DATE, 0, "", " ");
}
}
if (caps->type != NULL) {
wprintw(win, "%s", caps->type);
win_save_print(window, '-', NULL, NO_EOL_DATE, 0, "", caps->type);
if (caps->category != NULL) {
wprintw(win, " ");
win_save_print(window, '-', NULL, NO_EOL_DATE, 0, "", " ");
}
}
if (caps->category != NULL) {
wprintw(win, "%s", caps->category);
win_save_print(window, '-', NULL, NO_EOL_DATE, 0, "", caps->category);
}
wprintw(win, "\n");
win_save_print(window, '-', NULL, NO_DATE, 0, "", "");
}
if (caps->software != NULL) {
win_print_time(window, '-');
wprintw(win, " Software: %s", caps->software);
win_save_vprint(window, '-', NULL, NO_EOL, 0, "", " Software: %s", caps->software);
}
if (caps->software_version != NULL) {
wprintw(win, ", %s", caps->software_version);
win_save_vprint(window, '-', NULL, NO_EOL_DATE, 0, "", ", %s", caps->software_version);
}
if ((caps->software != NULL) || (caps->software_version != NULL)) {
wprintw(win, "\n");
win_save_print(window, '-', NULL, NO_DATE, 0, "", "");
}
if (caps->os != NULL) {
win_print_time(window, '-');
wprintw(win, " OS: %s", caps->os);
win_save_vprint(window, '-', NULL, NO_EOL, 0, "", " OS: %s", caps->os);
}
if (caps->os_version != NULL) {
wprintw(win, ", %s", caps->os_version);
win_save_vprint(window, '-', NULL, NO_EOL_DATE, 0, "", ", %s", caps->os_version);
}
if ((caps->os != NULL) || (caps->os_version != NULL)) {
wprintw(win, "\n");
win_save_print(window, '-', NULL, NO_DATE, 0, "", "");
}
}
}
@ -357,81 +271,47 @@ win_show_status_string(ProfWin *window, const char * const from,
GDateTime *last_activity, const char * const pre,
const char * const default_show)
{
WINDOW *win = window->win;
win_print_time(window, '-');
int presence_colour;
if (show != NULL) {
if (strcmp(show, "away") == 0) {
wattron(win, COLOUR_AWAY);
} else if (strcmp(show, "chat") == 0) {
wattron(win, COLOUR_CHAT);
} else if (strcmp(show, "dnd") == 0) {
wattron(win, COLOUR_DND);
} else if (strcmp(show, "xa") == 0) {
wattron(win, COLOUR_XA);
} else if (strcmp(show, "online") == 0) {
wattron(win, COLOUR_ONLINE);
} else {
wattron(win, COLOUR_OFFLINE);
}
presence_colour = win_presence_colour(show);
} else if (strcmp(default_show, "online") == 0) {
wattron(win, COLOUR_ONLINE);
presence_colour = COLOUR_ONLINE;
} else {
wattron(win, COLOUR_OFFLINE);
presence_colour = COLOUR_OFFLINE;
}
wprintw(win, "%s %s", pre, from);
win_save_vprint(window, '-', NULL, NO_EOL, presence_colour, "", "%s %s", pre, from);
if (show != NULL)
wprintw(win, " is %s", show);
win_save_vprint(window, '-', NULL, NO_EOL_DATE, presence_colour, "", " is %s", show);
else
wprintw(win, " is %s", default_show);
win_save_vprint(window, '-', NULL, NO_EOL_DATE, presence_colour, "", " is %s", default_show);
if (last_activity != NULL) {
GDateTime *now = g_date_time_new_now_local();
GTimeSpan span = g_date_time_difference(now, last_activity);
wprintw(win, ", idle ");
int hours = span / G_TIME_SPAN_HOUR;
span = span - hours * G_TIME_SPAN_HOUR;
if (hours > 0) {
wprintw(win, "%dh", hours);
}
int minutes = span / G_TIME_SPAN_MINUTE;
span = span - minutes * G_TIME_SPAN_MINUTE;
wprintw(win, "%dm", minutes);
int seconds = span / G_TIME_SPAN_SECOND;
wprintw(win, "%ds", seconds);
if (hours > 0) {
win_save_vprint(window, '-', NULL, NO_EOL_DATE, presence_colour, "", ", idle %dh%dm%ds", hours, minutes, seconds);
}
else {
win_save_vprint(window, '-', NULL, NO_EOL_DATE, presence_colour, "", ", idle %dm%ds", minutes, seconds);
}
}
if (status != NULL)
wprintw(win, ", \"%s\"", status);
win_save_vprint(window, '-', NULL, NO_EOL_DATE, presence_colour, "", ", \"%s\"", status);
wprintw(win, "\n");
win_save_print(window, '-', NULL, NO_DATE, presence_colour, "", "");
if (show != NULL) {
if (strcmp(show, "away") == 0) {
wattroff(win, COLOUR_AWAY);
} else if (strcmp(show, "chat") == 0) {
wattroff(win, COLOUR_CHAT);
} else if (strcmp(show, "dnd") == 0) {
wattroff(win, COLOUR_DND);
} else if (strcmp(show, "xa") == 0) {
wattroff(win, COLOUR_XA);
} else if (strcmp(show, "online") == 0) {
wattroff(win, COLOUR_ONLINE);
} else {
wattroff(win, COLOUR_OFFLINE);
}
} else if (strcmp(default_show, "online") == 0) {
wattroff(win, COLOUR_ONLINE);
} else {
wattroff(win, COLOUR_OFFLINE);
}
}
void
@ -442,7 +322,7 @@ win_print_incoming_message(ProfWin *window, GTimeVal *tv_stamp,
{
case WIN_CHAT:
case WIN_PRIVATE:
_win_chat_print_incoming_message(window, tv_stamp, from, message);
win_save_print(window, '-', tv_stamp, 1, 0, from, message);
break;
default:
assert(FALSE);
@ -450,33 +330,67 @@ win_print_incoming_message(ProfWin *window, GTimeVal *tv_stamp,
}
}
static void
_win_chat_print_incoming_message(ProfWin *window, GTimeVal *tv_stamp,
const char * const from, const char * const message)
{
if (tv_stamp == NULL) {
win_print_time(window, '-');
} else {
GDateTime *time = g_date_time_new_from_timeval_utc(tv_stamp);
gchar *date_fmt = g_date_time_format(time, "%H:%M:%S");
wattron(window->win, COLOUR_TIME);
wprintw(window->win, "%s - ", date_fmt);
wattroff(window->win, COLOUR_TIME);
g_date_time_unref(time);
g_free(date_fmt);
}
void win_save_vprint(ProfWin *window, const char show_char, GTimeVal *tstamp, int flags, int attrs, const char * const from, const char * const message, ...) {
va_list arg;
va_start(arg, message);
GString *fmt_msg = g_string_new(NULL);
g_string_vprintf(fmt_msg, message, arg);
win_save_print(window, show_char, tstamp, flags, attrs, from, fmt_msg->str);
}
if (strncmp(message, "/me ", 4) == 0) {
wattron(window->win, COLOUR_THEM);
void win_save_print(ProfWin *window, const char show_char, GTimeVal *tstamp, int flags, int attrs, const char * const from, const char * const message) {
// flags : 1st bit = 0/1 - me/not me
// 2nd bit = 0/1 - date/no date
// 3rd bit = 0/1 - eol/no eol
// 4th bit = 0/1 - color from/no color from
int unattr_me = 0;
int offset = 0;
int colour = COLOUR_ME;
gchar *date_fmt;
GDateTime *time;
if(tstamp == NULL) {
time = g_date_time_new_now_local();
date_fmt = g_date_time_format(time, "%H:%M:%S");
}
else {
time = g_date_time_new_from_timeval_utc(tstamp);
date_fmt = g_date_time_format(time, "%H:%M:%S");
}
g_date_time_unref(time);
// buffer_push(window->buffer, time, from, message, attrs);
if((flags & 2) == 0) {
wattron(window->win, COLOUR_TIME);
wprintw(window->win, "%s %c ", date_fmt, show_char);
wattroff(window->win, COLOUR_TIME);
}
g_free(date_fmt);
if(strlen(from) > 0) {
if((flags & 1) != 0) {
colour = COLOUR_THEM;
}
if((flags & 8) != 0) {
colour = 0;
}
wattron(window->win, colour);
if(strncmp(message, "/me ", 4) == 0) {
wprintw(window->win, "*%s ", from);
waddstr(window->win, message + 4);
wprintw(window->win, "\n");
wattroff(window->win, COLOUR_THEM);
} else {
wattron(window->win, COLOUR_THEM);
offset = 4;
unattr_me = 1;
}
else {
wprintw(window->win, "%s: ", from);
wattroff(window->win, COLOUR_THEM);
waddstr(window->win, message);
wprintw(window->win, "\n");
wattroff(window->win, colour);
}
}
wattron(window->win, attrs);
if((flags & 4) == 0)
wprintw(window->win, "%s\n", message+offset);
else
wprintw(window->win, "%s", message+offset);
wattroff(window->win, attrs);
if(unattr_me) {
wattroff(window->win, colour);
}
}

View File

@ -33,6 +33,11 @@
#include "contact.h"
#define NO_ME 1
#define NO_EOL 4
#define NO_DATE 2
#define NO_EOL_DATE 6
#define PAD_SIZE 1000
typedef enum {
@ -60,16 +65,9 @@ typedef struct prof_win_t {
ProfWin* win_create(const char * const title, int cols, win_type_t type);
void win_free(ProfWin *window);
void win_vprint_line(ProfWin *self, const char show_char, int attrs,
const char * const msg, ...);
void win_print_line(ProfWin *self, const char show_char, int attrs,
const char * const msg);
void win_print_line_no_time(ProfWin *window, int attrs, const char * const msg);
void win_update_virtual(ProfWin *window);
void win_move_to_end(ProfWin *window);
void win_print_time(ProfWin *window, char show_char);
void win_presence_colour_on(ProfWin *window, const char * const presence);
void win_presence_colour_off(ProfWin *window, const char * const presence);
int win_presence_colour(const char * const presence);
void win_show_contact(ProfWin *window, PContact contact);
void win_show_status_string(ProfWin *window, const char * const from,
const char * const show, const char * const status,
@ -78,5 +76,7 @@ void win_show_status_string(ProfWin *window, const char * const from,
void win_print_incoming_message(ProfWin *window, GTimeVal *tv_stamp,
const char * const from, const char * const message);
void win_show_info(ProfWin *window, PContact contact);
void win_save_vprint(ProfWin *window, const char show_char, GTimeVal *tstamp, int flags, int attrs, const char * const from, const char * const message, ...);
void win_save_print(ProfWin *window, const char show_char, GTimeVal *tstamp, int flags, int attrs, const char * const from, const char * const message);
#endif

View File

@ -394,10 +394,7 @@ wins_lost_connection(void)
while (curr != NULL) {
ProfWin *window = curr->data;
if (window->type != WIN_CONSOLE) {
win_print_time(window, '-');
wattron(window->win, COLOUR_ERROR);
wprintw(window->win, "%s\n", "Lost connection.");
wattroff(window->win, COLOUR_ERROR);
win_save_print(window, '-', NULL, 0, COLOUR_ERROR, "", "Lost connection.");
// if current win, set current_win_dirty
if (wins_is_current(window)) {