void win_sub_print(WINDOW *win, char *msg, gboolean newline, gboolean wrap, int indent) { int maxx = getmaxx(win); int curx = getcurx(win); int cury = getcury(win); if (wrap) { _win_print_wrapped(win, msg, 1, indent); } else { waddnstr(win, msg, maxx - curx); } if (newline) { wmove(win, cury+1, 0); } }
static void _win_print(ProfWin *window, const char show_char, int pad_indent, GDateTime *time, int flags, theme_item_t theme_item, const char *const from, const char *const message, DeliveryReceipt *receipt) { // 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 // 5th bit = 0/1 - color date/no date gboolean me_message = FALSE; int offset = 0; int colour = theme_attrs(THEME_ME); size_t indent = 0; char *time_pref = NULL; switch (window->type) { case WIN_CHAT: time_pref = prefs_get_string(PREF_TIME_CHAT); break; case WIN_MUC: time_pref = prefs_get_string(PREF_TIME_MUC); break; case WIN_MUC_CONFIG: time_pref = prefs_get_string(PREF_TIME_MUCCONFIG); break; case WIN_PRIVATE: time_pref = prefs_get_string(PREF_TIME_PRIVATE); break; case WIN_XML: time_pref = prefs_get_string(PREF_TIME_XMLCONSOLE); break; default: time_pref = prefs_get_string(PREF_TIME_CONSOLE); break; } gchar *date_fmt = NULL; if (g_strcmp0(time_pref, "off") == 0) { date_fmt = g_strdup(""); } else { date_fmt = g_date_time_format(time, time_pref); } prefs_free_string(time_pref); assert(date_fmt != NULL); if(strlen(date_fmt) != 0){ indent = 3 + strlen(date_fmt); } if ((flags & NO_DATE) == 0) { if (date_fmt && strlen(date_fmt)) { if ((flags & NO_COLOUR_DATE) == 0) { wbkgdset(window->layout->win, theme_attrs(THEME_TIME)); wattron(window->layout->win, theme_attrs(THEME_TIME)); } wprintw(window->layout->win, "%s %c ", date_fmt, show_char); if ((flags & NO_COLOUR_DATE) == 0) { wattroff(window->layout->win, theme_attrs(THEME_TIME)); } } } if (from && strlen(from) > 0) { if (flags & NO_ME) { colour = theme_attrs(THEME_THEM); } if (flags & NO_COLOUR_FROM) { colour = 0; } if (receipt && !receipt->received) { colour = theme_attrs(THEME_RECEIPT_SENT); } wbkgdset(window->layout->win, colour); wattron(window->layout->win, colour); if (strncmp(message, "/me ", 4) == 0) { wprintw(window->layout->win, "*%s ", from); offset = 4; me_message = TRUE; } else { wprintw(window->layout->win, "%s: ", from); wattroff(window->layout->win, colour); } } if (!me_message) { if (receipt && !receipt->received) { wbkgdset(window->layout->win, theme_attrs(THEME_RECEIPT_SENT)); wattron(window->layout->win, theme_attrs(THEME_RECEIPT_SENT)); } else { wbkgdset(window->layout->win, theme_attrs(theme_item)); wattron(window->layout->win, theme_attrs(theme_item)); } } if (prefs_get_boolean(PREF_WRAP)) { _win_print_wrapped(window->layout->win, message+offset, indent, pad_indent); } else { wprintw(window->layout->win, "%s", message+offset); } if ((flags & NO_EOL) == 0) { int curx = getcurx(window->layout->win); if (curx != 0) { wprintw(window->layout->win, "\n"); } } if (me_message) { wattroff(window->layout->win, colour); } else { if (receipt && !receipt->received) { wattroff(window->layout->win, theme_attrs(THEME_RECEIPT_SENT)); } else { wattroff(window->layout->win, theme_attrs(theme_item)); } } g_free(date_fmt); }
static void _win_print(ProfWin *window, const char show_char, GDateTime *time, int flags, theme_item_t theme_item, 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 // 5th bit = 0/1 - color date/no date gboolean me_message = FALSE; int offset = 0; int colour = theme_attrs(THEME_ME); if ((flags & NO_DATE) == 0) { gchar *date_fmt = NULL; char *time_pref = prefs_get_string(PREF_TIME); if (g_strcmp0(time_pref, "minutes") == 0) { date_fmt = g_date_time_format(time, "%H:%M"); } else if (g_strcmp0(time_pref, "seconds") == 0) { date_fmt = g_date_time_format(time, "%H:%M:%S"); } free(time_pref); if (date_fmt) { if ((flags & NO_COLOUR_DATE) == 0) { wattron(window->win, theme_attrs(THEME_TIME)); } wprintw(window->win, "%s %c ", date_fmt, show_char); if ((flags & NO_COLOUR_DATE) == 0) { wattroff(window->win, theme_attrs(THEME_TIME)); } } g_free(date_fmt); } if (strlen(from) > 0) { if (flags & NO_ME) { colour = theme_attrs(THEME_THEM); } if (flags & NO_COLOUR_FROM) { colour = 0; } wattron(window->win, colour); if (strncmp(message, "/me ", 4) == 0) { wprintw(window->win, "*%s ", from); offset = 4; me_message = TRUE; } else { wprintw(window->win, "%s: ", from); wattroff(window->win, colour); } } if (!me_message) { wattron(window->win, theme_attrs(theme_item)); } if (prefs_get_boolean(PREF_WRAP)) { _win_print_wrapped(window->win, message+offset); } else { wprintw(window->win, "%s", message+offset); } if ((flags & NO_EOL) == 0) { wprintw(window->win, "\n"); } if (me_message) { wattroff(window->win, colour); } else { wattroff(window->win, theme_attrs(theme_item)); } }