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

Whitespace formatting

This commit is contained in:
James Booth 2014-07-16 22:03:46 +01:00
parent aa8872875f
commit 2cbe7e4ccb

View File

@ -332,34 +332,42 @@ win_print_incoming_message(ProfWin *window, GTimeVal *tv_stamp,
} }
} }
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
va_list arg; win_save_vprint(ProfWin *window, const char show_char, GTimeVal *tstamp,
va_start(arg, message); int flags, int attrs, const char * const from, const char * const message, ...)
GString *fmt_msg = g_string_new(NULL); {
g_string_vprintf(fmt_msg, message, arg); va_list arg;
win_save_print(window, show_char, tstamp, flags, attrs, from, fmt_msg->str); 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
void win_save_print(ProfWin *window, const char show_char, GTimeVal *tstamp, int flags, int attrs, const char * const from, const char * const message) { 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; gchar *date_fmt;
GDateTime *time; GDateTime *time;
if(tstamp == NULL) {
time = g_date_time_new_now_local(); if (tstamp == NULL) {
date_fmt = g_date_time_format(time, "%H:%M:%S"); time = g_date_time_new_now_local();
} date_fmt = g_date_time_format(time, "%H:%M:%S");
else { } else {
time = g_date_time_new_from_timeval_utc(tstamp); time = g_date_time_new_from_timeval_utc(tstamp);
date_fmt = g_date_time_format(time, "%H:%M:%S"); date_fmt = g_date_time_format(time, "%H:%M:%S");
} }
g_date_time_unref(time); g_date_time_unref(time);
buffer_push(window->buffer, show_char, date_fmt, flags, attrs, from, message); buffer_push(window->buffer, show_char, date_fmt, flags, attrs, from, message);
win_print(window, show_char, date_fmt, flags, attrs, from, message); win_print(window, show_char, date_fmt, flags, attrs, from, message);
g_free(date_fmt); g_free(date_fmt);
} }
void
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) { 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 // flags : 1st bit = 0/1 - me/not me
// 2nd bit = 0/1 - date/no date // 2nd bit = 0/1 - date/no date
// 3rd bit = 0/1 - eol/no eol // 3rd bit = 0/1 - eol/no eol
@ -367,48 +375,57 @@ void win_print(ProfWin *window, const char show_char, const char * const date_fm
int unattr_me = 0; int unattr_me = 0;
int offset = 0; int offset = 0;
int colour = COLOUR_ME; int colour = COLOUR_ME;
if((flags & 2) == 0) {
wattron(window->win, COLOUR_TIME); if ((flags & 2) == 0) {
wprintw(window->win, "%s %c ", date_fmt, show_char); wattron(window->win, COLOUR_TIME);
wattroff(window->win, COLOUR_TIME); wprintw(window->win, "%s %c ", date_fmt, show_char);
wattroff(window->win, COLOUR_TIME);
} }
if(strlen(from) > 0) { if (strlen(from) > 0) {
if((flags & 1) != 0) { if ((flags & 1) != 0) {
colour = COLOUR_THEM; colour = COLOUR_THEM;
} }
if((flags & 8) != 0) {
colour = 0; if((flags & 8) != 0) {
} colour = 0;
wattron(window->win, colour); }
if(strncmp(message, "/me ", 4) == 0) {
wprintw(window->win, "*%s ", from); wattron(window->win, colour);
offset = 4; if (strncmp(message, "/me ", 4) == 0) {
unattr_me = 1; wprintw(window->win, "*%s ", from);
} offset = 4;
else { unattr_me = 1;
wprintw(window->win, "%s: ", from); } else {
wattroff(window->win, colour); wprintw(window->win, "%s: ", from);
} wattroff(window->win, colour);
}
} }
wattron(window->win, attrs); wattron(window->win, attrs);
if((flags & 4) == 0)
wprintw(window->win, "%s\n", message+offset); if ((flags & 4) == 0) {
else wprintw(window->win, "%s\n", message+offset);
wprintw(window->win, "%s", message+offset); } else {
wprintw(window->win, "%s", message+offset);
}
wattroff(window->win, attrs); wattroff(window->win, attrs);
if(unattr_me) { if (unattr_me) {
wattroff(window->win, colour); wattroff(window->win, colour);
} }
} }
void win_redraw(ProfWin *window) { void
win_redraw(ProfWin *window)
{
int i, size; int i, size;
werase(window->win); werase(window->win);
size = buffer_size(window->buffer); size = buffer_size(window->buffer);
for(i = 0; i < size; i++) {
ProfBuffEntry e = buffer_yield_entry(window->buffer, i); for (i = 0; i < size; i++) {
win_print(window, e.show_char, e.date_fmt, e.flags, e.attrs, e.from, e.message); 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);
} }
} }