diff options
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/buffer.c | 129 | ||||
-rw-r--r-- | src/ui/buffer.h | 31 | ||||
-rw-r--r-- | src/ui/console.c | 304 | ||||
-rw-r--r-- | src/ui/core.c | 282 | ||||
-rw-r--r-- | src/ui/window.c | 364 | ||||
-rw-r--r-- | src/ui/window.h | 21 | ||||
-rw-r--r-- | src/ui/windows.c | 26 |
7 files changed, 543 insertions, 614 deletions
diff --git a/src/ui/buffer.c b/src/ui/buffer.c new file mode 100644 index 00000000..6fc6394f --- /dev/null +++ b/src/ui/buffer.c @@ -0,0 +1,129 @@ +#include "config.h" + +#include <stdlib.h> +#include <string.h> +#include <assert.h> +#include <stdlib.h> + +#include <glib.h> +#ifdef HAVE_NCURSESW_NCURSES_H +#include <ncursesw/ncurses.h> +#elif HAVE_NCURSES_H +#include <ncurses.h> +#endif + +#include "ui/window.h" +#include "ui/buffer.h" + +ProfBuff* +buffer_create() { + ProfBuff* new_buff = malloc(sizeof(struct prof_buff_t)); + new_buff->wrap = 0; + new_buff->current = 0; + return new_buff; +} + +int buffer_size(ProfBuff* buffer) { + if(buffer->wrap == 1) { + return BUFF_SIZE; + } + else { + return buffer->current; + } +} + +void +buffer_free(ProfBuff* buffer) { + int i = 0; + int imax = buffer->current; + if(buffer->wrap == 1) { + imax = BUFF_SIZE; + } + for(i = 0; i < imax; i++) { + free(buffer->entry[i].message); + free(buffer->entry[i].from); + free(buffer->entry[i].date_fmt); + } + free(buffer); +} + +void +buffer_push(ProfBuff* buffer, const char show_char, const char * const date_fmt, int flags, int attrs, const char * const from, const char * const message) { + int *current = &(buffer->current); + ProfBuffEntry* e = &(buffer->entry[buffer->current]); + + if(buffer->wrap == 1) { + free(e->message); + free(e->from); + } + e->show_char = show_char; + e->flags = flags; + e->attrs = attrs; + + e->date_fmt = malloc(strlen(date_fmt)+1); + strcpy(e->date_fmt, date_fmt); + + e->from = malloc(strlen(from)+1); + strcpy(e->from, from); + + e->message = malloc(strlen(message)+1); + strcpy(e->message, message); + + *current += 1; + if(*current >= BUFF_SIZE) { + *current = 0; + buffer->wrap = 1; + } +} + +ProfBuffEntry +buffer_yield_entry(ProfBuff* buffer, int entry) { + return (buffer->entry)[entry]; + if(buffer->wrap == 1) { + return buffer->entry[(buffer->current + entry) % BUFF_SIZE]; + } + else { + return buffer->entry[entry % (buffer->current)]; + } +} + +int +buffer_yield(ProfBuff* buffer, int line, ProfBuffEntry** list) { + //Returns the size of the (line+1)-th last line, and list contains the line + //e.g. if line == 0, returns the last line + //bug if the wrap happens in the middle of a line + int current = buffer->current; + int imax = current; + if(buffer->wrap == 1) { + imax = BUFF_SIZE; + } + int i = 1; + int j = 0; + while(i <= imax) { + ProfBuffEntry e = buffer->entry[(current - i) % BUFF_SIZE]; + if(j == line && (e.flags & NO_EOL) == 0) { + //We found our line and we are at its last entry + int nb_entries = 1; + while(i + nb_entries <= imax) { + e = buffer->entry[(current - i - nb_entries) % BUFF_SIZE]; + if((e.flags & NO_EOL) == 0) { + break; + } + nb_entries += 1; + } + if((buffer->wrap == 1) && (i + nb_entries > imax)) { + //The line is at the top of the buffer, we don't know if it's complete + return 0; + } + else { + *list = &(buffer->entry[(current - i - nb_entries + 1) % BUFF_SIZE]); + return nb_entries; + } + } + if((e.flags & NO_EOL) == 0) { + j++; + } + i++; + } + return 0; +} diff --git a/src/ui/buffer.h b/src/ui/buffer.h new file mode 100644 index 00000000..3523f4bc --- /dev/null +++ b/src/ui/buffer.h @@ -0,0 +1,31 @@ +#ifndef UI_BUFFER_H +#define UI_BUFFER_H + +#include "config.h" + +//#include "ui/window.h" +#define BUFF_SIZE 1000 + +typedef struct prof_buff_entry_t { + char show_char; + char *date_fmt; + int flags; + int attrs; + char *from; + char *message; +} ProfBuffEntry; + +typedef struct prof_buff_t { + ProfBuffEntry entry[BUFF_SIZE]; + int wrap; + int current; +} ProfBuff; + + +ProfBuff* buffer_create(); +void buffer_free(ProfBuff* buffer); +void buffer_push(ProfBuff* buffer, const char show_char, const char * const date_fmt, int flags, int attrs, const char * const from, const char * const message); +int buffer_size(ProfBuff* buffer); +int buffer_yield(ProfBuff* buffer, int line, ProfBuffEntry** list); +ProfBuffEntry buffer_yield_entry(ProfBuff* buffer, int entry); +#endif diff --git a/src/ui/console.c b/src/ui/console.c index 3c0f6828..d295d840 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -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_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, '-'); - 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, '-'); + win_save_print(console, '-', NULL, 0, 0, "", "Welcome to"); + + 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, "", ""); + 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); - } else { - wattron(console->win, COLOUR_UNSUBSCRIBED); - } - wprintw(console->win, "%s\n", sub->str); - if (p_contact_subscribed(contact)) { - wattroff(console->win, COLOUR_SUBSCRIBED); + presence_colour = 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); diff --git a/src/ui/core.c b/src/ui/core.c index 5688caa8..53a36f2d 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -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, @@ -236,13 +234,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)) { @@ -516,13 +514,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(); @@ -543,7 +541,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(); @@ -774,9 +772,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)) { @@ -809,7 +807,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(); @@ -824,9 +822,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(); @@ -841,7 +839,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(); @@ -856,7 +854,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(); @@ -871,7 +869,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(); @@ -886,7 +884,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(); @@ -901,7 +899,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(); @@ -916,7 +914,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(); @@ -931,7 +929,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); @@ -950,7 +948,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); @@ -969,7 +967,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); @@ -1126,7 +1124,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(); @@ -1141,7 +1139,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(); @@ -1184,7 +1182,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); @@ -1198,7 +1196,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); @@ -1208,7 +1206,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); } @@ -1242,8 +1240,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)) { @@ -1269,7 +1266,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); } @@ -1321,7 +1318,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 @@ -1357,14 +1354,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); } } @@ -1374,22 +1366,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); } } @@ -1397,7 +1386,7 @@ _ui_duck_result(const char * const result) offset++; } - wprintw(window->win, "\n"); + win_save_print(window, '-', NULL, NO_DATE, 0, "", ""); } } @@ -1444,17 +1433,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); } @@ -1477,7 +1456,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(console, '!', NULL, 0, COLOUR_TYPING, "", "-> Autojoined %s as %s (%d).", room, nick, num); win_update_virtual(console); } } @@ -1487,29 +1466,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) { @@ -1517,19 +1487,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)) { @@ -1548,10 +1516,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); @@ -1564,10 +1529,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); @@ -1595,10 +1557,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); @@ -1610,10 +1569,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); @@ -1626,20 +1582,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); @@ -1654,36 +1597,14 @@ _ui_room_message(const char * const room_jid, const char * const nick, int num = wins_get_num(window); char *my_nick = muc_get_room_nick(room_jid); - win_print_time(window, '-'); if (strcmp(nick, my_nick) != 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); + if (g_strrstr(message, my_nick) != NULL) { + win_save_print(window, '-', NULL, 1, COLOUR_ROOMMENTION, nick, message); } else { - _win_show_user(window->win, nick, 1); - if (g_strrstr(message, my_nick) != NULL) { - wattron(window->win, COLOUR_ROOMMENTION); - _win_show_message(window->win, message); - wattroff(window->win, COLOUR_ROOMMENTION); - } else { - _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 @@ -1762,11 +1683,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)) { @@ -1785,11 +1703,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)) { @@ -1812,7 +1727,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."); } } @@ -1826,7 +1741,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."); } } @@ -1840,7 +1755,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); @@ -1856,7 +1771,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); @@ -1871,7 +1786,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); } } @@ -1884,7 +1799,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); } } @@ -2006,27 +1921,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) { if (*ch == KEY_F(1)) { @@ -2057,10 +1951,14 @@ _win_handle_page(const wint_t * const ch) { ProfWin *current = wins_get_current(); int rows = getmaxy(stdscr); + int cols = getmaxx(stdscr); + int x = getmaxx(current->win); int y = getcury(current->win); int page_space = rows - 4; + int horiz_page_space = cols; int *page_start = &(current->y_pos); + int *horiz_page_start = &(current->x_pos); if (prefs_get_boolean(PREF_MOUSE)) { MEVENT mouse_event; @@ -2099,8 +1997,34 @@ _win_handle_page(const wint_t * const ch) } } + // ctrl+P + if (*ch == 16) { + *horiz_page_start -= horiz_page_space; + + // went past beginning, show first page + if (*horiz_page_start < 0) + *horiz_page_start = 0; + + current->paged = 1; + win_update_virtual(current); + + // ctrl+N + } else if (*ch == 14) { + *horiz_page_start += horiz_page_space; + + // only got half a screen, show full screen + if ((x - (*horiz_page_start)) < horiz_page_space) + *horiz_page_start = x - horiz_page_space; + + // went past end, show full screen + else if (*horiz_page_start >= x) + *horiz_page_start = x - horiz_page_space; + + current->paged = 1; + win_update_virtual(current); + // page up - if (*ch == KEY_PPAGE) { + } else if (*ch == KEY_PPAGE) { *page_start -= page_space; // went past beginning, show first page @@ -2127,7 +2051,7 @@ _win_handle_page(const wint_t * const ch) } // switch off page if last line visible - if ((y-1) - *page_start == page_space) { + if ((y-1) - *page_start == page_space && *horiz_page_start == 0) { current->paged = 0; } } @@ -2142,7 +2066,7 @@ _win_show_history(WINDOW *win, int win_index, const char * const contact) jid_destroy(jid); GSList *curr = history; while (curr != NULL) { - wprintw(win, "%s\n", curr->data); + win_save_print(window, '-', NULL, NO_DATE, 0, "", curr->data); curr = g_slist_next(curr); } window->history_shown = 1; diff --git a/src/ui/window.c b/src/ui/window.c index 11559421..c65d79d7 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -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) { @@ -47,7 +44,9 @@ win_create(const char * const title, int cols, win_type_t type) new_win->from = strdup(title); new_win->win = newpad(PAD_SIZE, cols); wbkgd(new_win->win, COLOUR_TEXT); + new_win->buffer = buffer_create(); new_win->y_pos = 0; + new_win->x_pos = 0; new_win->paged = 0; new_win->unread = 0; new_win->history_shown = 0; @@ -62,63 +61,18 @@ win_create(const char * const title, int cols, win_type_t type) void win_free(ProfWin* window) { + buffer_free(window->buffer); delwin(window->win); free(window->from); 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) { int rows, cols; getmaxyx(stdscr, rows, cols); - pnoutrefresh(window->win, window->y_pos, 0, 1, 0, rows-3, cols-1); + pnoutrefresh(window->win, window->y_pos, window->x_pos, 1, 0, rows-3, cols-1); } void @@ -131,44 +85,27 @@ win_move_to_end(ProfWin *window) int size = rows - 3; window->y_pos = y - (size - 1); + window->x_pos = 0; if (window->y_pos < 0) { window->y_pos = 0; } } -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; } } @@ -181,43 +118,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 @@ -230,52 +163,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) { @@ -289,58 +212,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, "", ""); } } } @@ -355,81 +273,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 @@ -440,7 +324,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); @@ -448,33 +332,83 @@ 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); +} + + +void win_save_print(ProfWin *window, const char show_char, GTimeVal *tstamp, int flags, int attrs, const char * const from, const char * const message) { + 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, show_char, date_fmt, flags, attrs, from, message); + win_print(window, show_char, date_fmt, flags, attrs, from, message); + g_free(date_fmt); +} + - if (strncmp(message, "/me ", 4) == 0) { - wattron(window->win, COLOUR_THEM); +void win_print(ProfWin *window, const char show_char, const char * const date_fmt, 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; + if((flags & 2) == 0) { + wattron(window->win, COLOUR_TIME); + wprintw(window->win, "%s %c ", date_fmt, show_char); + wattroff(window->win, COLOUR_TIME); + } + + 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); + } +} + +void win_redraw(ProfWin *window) { + int i, size; + werase(window->win); + size = buffer_size(window->buffer); + for(i = 0; i < size; i++) { + ProfBuffEntry e = buffer_yield_entry(window->buffer, i); + win_print(window, e.show_char, e.date_fmt, e.flags, e.attrs, e.from, e.message); } } diff --git a/src/ui/window.h b/src/ui/window.h index 4d10874c..f3e26495 100644 --- a/src/ui/window.h +++ b/src/ui/window.h @@ -32,6 +32,12 @@ #endif #include "contact.h" +#include "ui/buffer.h" + +#define NO_ME 1 +#define NO_EOL 4 +#define NO_DATE 2 +#define NO_EOL_DATE 6 #define PAD_SIZE 1000 @@ -48,9 +54,11 @@ typedef enum { typedef struct prof_win_t { char *from; WINDOW *win; + ProfBuff *buffer; win_type_t type; gboolean is_otr; gboolean is_trusted; + int x_pos; int y_pos; int paged; int unread; @@ -59,16 +67,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, @@ -77,5 +78,9 @@ 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); +void win_print(ProfWin *window, const char show_char, const char * const date_fmt, int flags, int attrs, const char * const from, const char * const message); +void win_redraw(ProfWin *window); #endif diff --git a/src/ui/windows.c b/src/ui/windows.c index 85345693..bbee696e 100644 --- a/src/ui/windows.c +++ b/src/ui/windows.c @@ -274,20 +274,15 @@ wins_resize_all(void) int rows, cols; getmaxyx(stdscr, rows, cols); - // only make the pads bigger, to avoid data loss on cropping - if (cols > max_cols) { - max_cols = cols; - - GList *values = g_hash_table_get_values(windows); - GList *curr = values; - - while (curr != NULL) { - ProfWin *window = curr->data; - wresize(window->win, PAD_SIZE, cols); - curr = g_list_next(curr); - } - g_list_free(values); + GList *values = g_hash_table_get_values(windows); + GList *curr = values; + while (curr != NULL) { + ProfWin *window = curr->data; + wresize(window->win, PAD_SIZE, cols); + win_redraw(window); + curr = g_list_next(curr); } + g_list_free(values); ProfWin *current_win = wins_get_current(); @@ -396,10 +391,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)) { |