1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Add win_appendln

This commit is contained in:
James Booth 2016-10-15 19:19:44 +01:00
parent 8f1d3ab55c
commit 711c5b8e45
8 changed files with 82 additions and 64 deletions

View File

@ -3940,7 +3940,7 @@ cmd_subject(ProfWin *window, const char *const command, gchar **args)
char *subject = muc_subject(mucwin->roomjid);
if (subject) {
win_print(window, THEME_ROOMINFO, '!', "Room subject: ");
win_printf(window, '!', 0, NULL, NO_DATE, THEME_DEFAULT, "", "%s", subject);
win_appendln(window, THEME_DEFAULT, "%s", subject);
} else {
win_println(window, THEME_ROOMINFO, '!', "Room has no subject");
}

View File

@ -130,7 +130,7 @@ cons_show_help(const char *const cmd, CommandHelp *help)
for (i = 0; i < strlen(cmd) - 1 ; i++) {
win_printf(console, '-', 0, NULL, NO_EOL | NO_DATE, THEME_WHITE_BOLD, "", "-");
}
win_printf(console, '-', 0, NULL, NO_DATE, THEME_WHITE_BOLD, "", "");
win_appendln(console, THEME_WHITE_BOLD, "");
cons_show("");
win_println(console, THEME_WHITE_BOLD, '-', "Synopsis");
@ -484,7 +484,7 @@ cons_show_login_success(ProfAccount *account, gboolean secured)
win_printf(console, '-', 0, NULL, NO_DATE | NO_EOL, presence_colour, "", "%s", presence_str);
win_printf(console, '-', 0, NULL, NO_DATE | NO_EOL, THEME_DEFAULT, "", " (priority %d)",
accounts_get_priority_for_presence_type(account->name, presence));
win_printf(console, '-', 0, NULL, NO_DATE, THEME_DEFAULT, "", ".");
win_appendln(console, THEME_DEFAULT, ".");
if (!secured) {
cons_show_error("TLS connection not established");
}
@ -555,7 +555,7 @@ cons_show_caps(const char *const fulljid, resource_presence_t presence)
theme_item_t presence_colour = theme_main_presence_attrs(resource_presence);
win_print(console, presence_colour, '-', "%s", fulljid);
win_printf(console, '-', 0, NULL, NO_DATE, THEME_DEFAULT, "", ":");
win_appendln(console, THEME_DEFAULT, ":");
// show identity
if (caps->identity) {
@ -788,7 +788,7 @@ cons_show_disco_items(GSList *items, const char *const jid)
if (item->name) {
win_printf(console, '-', 0, NULL, NO_DATE | NO_EOL, THEME_DEFAULT, "", ", (%s)", item->name);
}
win_printf(console, '-', 0, NULL, NO_DATE, THEME_DEFAULT, "", "");
win_appendln(console, THEME_DEFAULT, "");
items = g_slist_next(items);
}
} else {
@ -1005,7 +1005,7 @@ cons_show_account(ProfAccount *account)
if (resource->status) {
win_printf(console, '-', 0, NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", resource->status);
}
win_printf(console, '-', 0, NULL, NO_DATE, THEME_DEFAULT, "", "");
win_appendln(console, THEME_DEFAULT, "");
Jid *jidp = jid_create_from_bare_and_resource(account->jid, resource->name);
EntityCapabilities *caps = caps_lookup(jidp->fulljid);
jid_destroy(jidp);
@ -2192,7 +2192,7 @@ _cons_theme_bar_prop(theme_item_t theme, char *prop)
g_string_append_printf(valstr, "%s ", setting);
theme_free_string(setting);
win_printf(console, '-', 0, NULL, NO_DATE | NO_EOL, theme, "", "%s", valstr->str);
win_printf(console, '-', 0, NULL, NO_DATE, THEME_TEXT, "", "");
win_appendln(console, THEME_TEXT, "");
g_string_free(valstr, TRUE);
}
@ -2210,7 +2210,7 @@ _cons_theme_prop(theme_item_t theme, char *prop)
char *setting = theme_get_string(prop);
g_string_append_printf(valstr, "%s", setting);
theme_free_string(setting);
win_printf(console, '-', 0, NULL, NO_DATE, theme, "", "%s", valstr->str);
win_appendln(console, theme, "%s", valstr->str);
g_string_free(valstr, TRUE);
}
@ -2326,29 +2326,29 @@ cons_theme_colours(void)
ProfWin *console = wins_get_console();
cons_show("Available colours:");
win_print(console, THEME_WHITE, '-', " white ");
win_printf(console, '-', 0, NULL, NO_DATE, THEME_WHITE_BOLD, "", " bold_white");
win_print(console, THEME_WHITE, '-', " white ");
win_appendln(console, THEME_WHITE_BOLD, " bold_white");
win_print(console, THEME_GREEN, '-', " green ");
win_printf(console, '-', 0, NULL, NO_DATE, THEME_GREEN_BOLD, "", " bold_green");
win_print(console, THEME_GREEN, '-', " green ");
win_appendln(console, THEME_GREEN_BOLD, " bold_green");
win_print(console, THEME_RED, '-', " red ");
win_printf(console, '-', 0, NULL, NO_DATE, THEME_RED_BOLD, "", " bold_red");
win_print(console, THEME_RED, '-', " red ");
win_appendln(console, THEME_RED_BOLD, " bold_red");
win_print(console, THEME_YELLOW, '-', " yellow ");
win_printf(console, '-', 0, NULL, NO_DATE, THEME_YELLOW_BOLD, "", " bold_yellow");
win_print(console, THEME_YELLOW, '-', " yellow ");
win_appendln(console, THEME_YELLOW_BOLD, " bold_yellow");
win_print(console, THEME_BLUE, '-', " blue ");
win_printf(console, '-', 0, NULL, NO_DATE, THEME_BLUE_BOLD, "", " bold_blue");
win_print(console, THEME_BLUE, '-', " blue ");
win_appendln(console, THEME_BLUE_BOLD, " bold_blue");
win_print(console, THEME_CYAN, '-', " cyan ");
win_printf(console, '-', 0, NULL, NO_DATE, THEME_CYAN_BOLD, "", " bold_cyan");
win_print(console, THEME_CYAN, '-', " cyan ");
win_appendln(console, THEME_CYAN_BOLD, " bold_cyan");
win_print(console, THEME_MAGENTA, '-', " magenta ");
win_printf(console, '-', 0, NULL, NO_DATE, THEME_MAGENTA_BOLD, "", " bold_magenta");
win_print(console, THEME_MAGENTA, '-', " magenta ");
win_appendln(console, THEME_MAGENTA_BOLD, " bold_magenta");
win_print(console, THEME_BLACK, '-', " black ");
win_printf(console, '-', 0, NULL, NO_DATE, THEME_BLACK_BOLD, "", " bold_black");
win_print(console, THEME_BLACK, '-', " black ");
win_appendln(console, THEME_BLACK_BOLD, " bold_black");
cons_show("");
}
@ -2424,7 +2424,7 @@ _show_roster_contacts(GSList *list, gboolean show_groups)
if (show_groups) {
win_printf(console, '-', 0, NULL, NO_DATE | NO_EOL, presence_colour, "", "%s", sub->str);
} else {
win_printf(console, '-', 0, NULL, NO_DATE, presence_colour, "", "%s", sub->str);
win_appendln(console, presence_colour, "%s", sub->str);
}
g_string_free(sub, TRUE);
@ -2440,10 +2440,10 @@ _show_roster_contacts(GSList *list, gboolean show_groups)
}
groups = g_slist_next(groups);
}
win_printf(console, '-', 0, NULL, NO_DATE, THEME_DEFAULT, "", "%s", groups_str->str);
win_appendln(console, THEME_DEFAULT, "%s", groups_str->str);
g_string_free(groups_str, TRUE);
} else {
win_printf(console, '-', 0, NULL, NO_DATE, THEME_DEFAULT, "", " ");
win_appendln(console, THEME_DEFAULT, " ");
}
}

View File

@ -800,8 +800,7 @@ ui_room_join(const char *const roomjid, gboolean focus)
win_printf(window, '!', 0, NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", affiliation: %s", affiliation);
}
}
win_printf(window, '!', 0, NULL, NO_DATE, THEME_ROOMINFO, "", "");
win_appendln(window, THEME_ROOMINFO, "");
if (focus) {
ui_focus_win(window);
@ -1304,7 +1303,7 @@ ui_show_software_version(const char *const jid, const char *const presence,
win_println(window, THEME_DEFAULT, '-', "");
theme_item_t presence_colour = theme_main_presence_attrs(presence);
win_print(window, presence_colour, '-', "%s", jid);
win_printf(window, '-', 0, NULL, NO_DATE, 0, "", ":");
win_appendln(window, THEME_DEFAULT, ":");
}
if (name) {
win_println(window, THEME_DEFAULT, '-', "Name : %s", name);

View File

@ -48,7 +48,7 @@ mucconfwin_show_form(ProfMucConfWin *confwin)
ProfWin *window = (ProfWin*) confwin;
if (confwin->form->title) {
win_print(window, THEME_DEFAULT, '-', "Form title: ");
win_printf(window, '-', 0, NULL, NO_DATE, THEME_DEFAULT, "", "%s", confwin->form->title);
win_appendln(window, THEME_DEFAULT, "%s", confwin->form->title);
} else {
win_println(window, THEME_DEFAULT, '-', "Configuration for room %s.", confwin->roomjid);
}
@ -113,9 +113,9 @@ mucconfwin_field_help(ProfMucConfWin *confwin, char *tag)
if (field) {
win_print(window, THEME_DEFAULT, '-', "%s", field->label);
if (field->required) {
win_printf(window, '-', 0, NULL, NO_DATE, THEME_DEFAULT, "", " (Required):");
win_appendln(window, THEME_DEFAULT, " (Required):");
} else {
win_printf(window, '-', 0, NULL, NO_DATE, THEME_DEFAULT, "", ":");
win_appendln(window, THEME_DEFAULT, ":");
}
if (field->description) {
win_println(window, THEME_DEFAULT, '-', " Description : %s", field->description);
@ -252,16 +252,16 @@ _mucconfwin_form_field(ProfWin *window, char *tag, FormField *field)
break;
case FIELD_BOOLEAN:
if (curr_value == NULL) {
win_printf(window, '-', 0, NULL, NO_DATE, THEME_OFFLINE, "", "FALSE");
win_appendln(window, THEME_OFFLINE, "FALSE");
} else {
char *value = curr_value->data;
if (value == NULL) {
win_printf(window, '-', 0, NULL, NO_DATE, THEME_OFFLINE, "", "FALSE");
win_appendln(window, THEME_OFFLINE, "FALSE");
} else {
if (g_strcmp0(value, "0") == 0) {
win_printf(window, '-', 0, NULL, NO_DATE, THEME_OFFLINE, "", "FALSE");
win_appendln(window, THEME_OFFLINE, "FALSE");
} else {
win_printf(window, '-', 0, NULL, NO_DATE, THEME_ONLINE, "", "TRUE");
win_appendln(window, THEME_ONLINE, "TRUE");
}
}
}

View File

@ -58,7 +58,7 @@ mucwin_role_change(ProfMucWin *mucwin, const char *const role, const char *const
if (reason) {
win_printf(window, '!', 0, NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", reason: %s", reason);
}
win_printf(window, '!', 0, NULL, NO_DATE, THEME_ROOMINFO, "", "");
win_appendln(window, THEME_ROOMINFO, "");
}
void
@ -75,7 +75,7 @@ mucwin_affiliation_change(ProfMucWin *mucwin, const char *const affiliation, con
if (reason) {
win_printf(window, '!', 0, NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", reason: %s", reason);
}
win_printf(window, '!', 0, NULL, NO_DATE, THEME_ROOMINFO, "", "");
win_appendln(window, THEME_ROOMINFO, "");
}
void
@ -92,7 +92,7 @@ mucwin_role_and_affiliation_change(ProfMucWin *mucwin, const char *const role, c
if (reason) {
win_printf(window, '!', 0, NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", reason: %s", reason);
}
win_printf(window, '!', 0, NULL, NO_DATE, THEME_ROOMINFO, "", "");
win_appendln(window, THEME_ROOMINFO, "");
}
@ -110,7 +110,7 @@ mucwin_occupant_role_change(ProfMucWin *mucwin, const char *const nick, const ch
if (reason) {
win_printf(window, '!', 0, NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", reason: %s", reason);
}
win_printf(window, '!', 0, NULL, NO_DATE, THEME_ROOMINFO, "", "");
win_appendln(window, THEME_ROOMINFO, "");
}
void
@ -127,7 +127,7 @@ mucwin_occupant_affiliation_change(ProfMucWin *mucwin, const char *const nick, c
if (reason) {
win_printf(window, '!', 0, NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", reason: %s", reason);
}
win_printf(window, '!', 0, NULL, NO_DATE, THEME_ROOMINFO, "", "");
win_appendln(window, THEME_ROOMINFO, "");
}
void
@ -144,7 +144,7 @@ mucwin_occupant_role_and_affiliation_change(ProfMucWin *mucwin, const char *cons
if (reason) {
win_printf(window, '!', 0, NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", reason: %s", reason);
}
win_printf(window, '!', 0, NULL, NO_DATE, THEME_ROOMINFO, "", "");
win_appendln(window, THEME_ROOMINFO, "");
}
void
@ -231,8 +231,7 @@ mucwin_roster(ProfMucWin *mucwin, GList *roster, const char *const presence)
roster = g_list_next(roster);
}
win_printf(window, '!', 0, NULL, NO_DATE, THEME_ONLINE, "", "");
win_appendln(window, THEME_ONLINE, "");
}
}
@ -305,7 +304,7 @@ mucwin_occupant_online(ProfMucWin *mucwin, const char *const nick, const char *c
win_printf(window, '!', 0, NULL, NO_DATE | NO_EOL, THEME_ONLINE, "", ", affiliation: %s", affiliation);
}
}
win_printf(window, '!', 0, NULL, NO_DATE, THEME_ROOMINFO, "", "");
win_appendln(window, THEME_ROOMINFO, "");
}
void
@ -534,10 +533,10 @@ mucwin_subject(ProfMucWin *mucwin, const char *const nick, const char *const sub
if (subject) {
if (nick) {
win_print(window, THEME_ROOMINFO, '!', "*%s has set the room subject: ", nick);
win_printf(window, '!', 0, NULL, NO_DATE, THEME_DEFAULT, "", "%s", subject);
win_appendln(window, THEME_DEFAULT, "%s", subject);
} else {
win_print(window, THEME_ROOMINFO, '!', "Room subject: ");
win_printf(window, '!', 0, NULL, NO_DATE, THEME_DEFAULT, "", "%s", subject);
win_appendln(window, THEME_DEFAULT, "%s", subject);
}
} else {
if (nick) {
@ -575,7 +574,7 @@ mucwin_broadcast(ProfMucWin *mucwin, const char *const message)
int num = wins_get_num(window);
win_print(window, THEME_ROOMINFO, '!', "Room message: ");
win_printf(window, '!', 0, NULL, NO_DATE, THEME_DEFAULT, "", "%s", message);
win_appendln(window, THEME_DEFAULT, "%s", message);
// currently in groupchat window
if (wins_is_current(window)) {

View File

@ -359,6 +359,7 @@ void win_printf(ProfWin *window, const char show_char, int pad_indent, GDateTime
theme_item_t theme_item, const char *const from, const char *const message, ...);
void win_print(ProfWin *window, theme_item_t theme_item, const char ch, const char *const message, ...);
void win_println(ProfWin *window, theme_item_t theme_item, const char ch, const char *const message, ...);
void win_appendln(ProfWin *window, theme_item_t theme_item, const char *const message, ...);
void win_println_indent(ProfWin *window, int pad, const char *const message);
char* win_get_title(ProfWin *window);
void win_show_occupant(ProfWin *window, Occupant *occupant);

View File

@ -689,7 +689,7 @@ win_show_occupant(ProfWin *window, Occupant *occupant)
win_printf(window, '-', 0, NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", occupant->status);
}
win_printf(window, '-', 0, NULL, NO_DATE, presence_colour, "", "");
win_appendln(window, presence_colour, "");
}
void
@ -734,7 +734,7 @@ win_show_contact(ProfWin *window, PContact contact)
win_printf(window, '-', 0, NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", p_contact_status(contact));
}
win_printf(window, '-', 0, NULL, NO_DATE, presence_colour, "", "");
win_appendln(window, presence_colour, "");
}
void
@ -792,7 +792,7 @@ win_show_occupant_info(ProfWin *window, const char *const room, Occupant *occupa
if (caps->software_version) {
SoftwareVersion *software_version = caps->software_version;
if (software_version->software) {
win_printf(window, '!', 0, NULL, NO_EOL, THEME_DEFAULT, "", " Software: %s", software_version->software);
win_print(window, THEME_DEFAULT, '!', " Software: %s", software_version->software);
}
if (software_version->software_version) {
win_printf(window, '!', 0, NULL, NO_DATE | NO_EOL, THEME_DEFAULT, "", ", %s", software_version->software_version);
@ -801,7 +801,7 @@ win_show_occupant_info(ProfWin *window, const char *const room, Occupant *occupa
win_newline(window);
}
if (software_version->os) {
win_printf(window, '!', 0, NULL, NO_EOL, THEME_DEFAULT, "", " OS: %s", software_version->os);
win_print(window, THEME_DEFAULT, '!', " OS: %s", software_version->os);
}
if (software_version->os_version) {
win_printf(window, '!', 0, NULL, NO_DATE | NO_EOL, THEME_DEFAULT, "", ", %s", software_version->os_version);
@ -829,11 +829,11 @@ win_show_info(ProfWin *window, PContact contact)
theme_item_t presence_colour = theme_main_presence_attrs(presence);
win_println(window, THEME_DEFAULT, '-', "");
win_printf(window, '-', 0, NULL, NO_EOL, presence_colour, "", "%s", barejid);
win_print(window, presence_colour, '-', "%s", barejid);
if (name) {
win_printf(window, '-', 0, NULL, NO_DATE | NO_EOL, presence_colour, "", " (%s)", name);
}
win_printf(window, '-', 0, NULL, NO_DATE, THEME_DEFAULT, "", ":");
win_appendln(window, THEME_DEFAULT, ":");
if (sub) {
win_println(window, THEME_DEFAULT, '-', "Subscription: %s", sub);
@ -880,7 +880,7 @@ win_show_info(ProfWin *window, PContact contact)
Resource *resource = curr->data;
const char *resource_presence = string_from_resource_presence(resource->presence);
theme_item_t presence_colour = theme_main_presence_attrs(resource_presence);
win_printf(window, '-', 0, NULL, NO_EOL, presence_colour, "", " %s (%d), %s", resource->name, resource->priority, resource_presence);
win_print(window, presence_colour, '-', " %s (%d), %s", resource->name, resource->priority, resource_presence);
if (resource->status) {
win_printf(window, '-', 0, NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", resource->status);
}
@ -894,7 +894,7 @@ win_show_info(ProfWin *window, PContact contact)
// show identity
if (caps->identity) {
DiscoIdentity *identity = caps->identity;
win_printf(window, '-', 0, NULL, NO_EOL, THEME_DEFAULT, "", " Identity: ");
win_print(window, THEME_DEFAULT, '-', " Identity: ");
if (identity->name) {
win_printf(window, '-', 0, NULL, NO_DATE | NO_EOL, THEME_DEFAULT, "", "%s", identity->name);
if (identity->category || identity->type) {
@ -916,7 +916,7 @@ win_show_info(ProfWin *window, PContact contact)
if (caps->software_version) {
SoftwareVersion *software_version = caps->software_version;
if (software_version->software) {
win_printf(window, '-', 0, NULL, NO_EOL, THEME_DEFAULT, "", " Software: %s", software_version->software);
win_print(window, THEME_DEFAULT, '-', " Software: %s", software_version->software);
}
if (software_version->software_version) {
win_printf(window, '-', 0, NULL, NO_DATE | NO_EOL, THEME_DEFAULT, "", ", %s", software_version->software_version);
@ -925,7 +925,7 @@ win_show_info(ProfWin *window, PContact contact)
win_newline(window);
}
if (software_version->os) {
win_printf(window, '-', 0, NULL, NO_EOL, THEME_DEFAULT, "", " OS: %s", software_version->os);
win_print(window, THEME_DEFAULT, '-', " OS: %s", software_version->os);
}
if (software_version->os_version) {
win_printf(window, '-', 0, NULL, NO_DATE | NO_EOL, THEME_DEFAULT, "", ", %s", software_version->os_version);
@ -959,8 +959,7 @@ win_show_status_string(ProfWin *window, const char *const from,
presence_colour = THEME_OFFLINE;
}
win_printf(window, '-', 0, NULL, NO_EOL, presence_colour, "", "%s %s", pre, from);
win_print(window, presence_colour, '-', "%s %s", pre, from);
if (show)
win_printf(window, '-', 0, NULL, NO_DATE | NO_EOL, presence_colour, "", " is %s", show);
@ -982,8 +981,7 @@ win_show_status_string(ProfWin *window, const char *const from,
if (status)
win_printf(window, '-', 0, NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", status);
win_printf(window, '-', 0, NULL, NO_DATE, presence_colour, "", "");
win_appendln(window, presence_colour, "");
}
void
@ -1076,6 +1074,26 @@ win_println(ProfWin *window, theme_item_t theme_item, const char ch, const char
va_end(arg);
}
void
win_appendln(ProfWin *window, theme_item_t theme_item, const char *const message, ...)
{
GDateTime *timestamp = g_date_time_new_now_local();
va_list arg;
va_start(arg, message);
GString *fmt_msg = g_string_new(NULL);
g_string_vprintf(fmt_msg, message, arg);
buffer_push(window->layout->buffer, '-', 0, timestamp, NO_EOL, theme_item, "", fmt_msg->str, NULL);
_win_print(window, '-', 0, timestamp, NO_DATE, theme_item, "", fmt_msg->str, NULL);
inp_nonblocking(TRUE);
g_date_time_unref(timestamp);
g_string_free(fmt_msg, TRUE);
va_end(arg);
}
void
win_print_http_upload(ProfWin *window, const char *const message, char *url)
{
@ -1138,7 +1156,7 @@ win_println_indent(ProfWin *window, int pad, const char *const message)
void
win_newline(ProfWin *window)
{
win_printf(window, '-', 0, NULL, NO_DATE, THEME_DEFAULT, "", "");
win_appendln(window, THEME_DEFAULT, "");
}
static void

View File

@ -520,6 +520,7 @@ void win_refresh_with_subwin(ProfWin *window) {}
void win_printf(ProfWin *window, const char show_char, int pad_indent, GDateTime *timestamp, int flags, theme_item_t theme_item, const char * const from, const char * const message, ...) {}
void win_print(ProfWin *window, theme_item_t theme_item, const char ch, const char *const message, ...) {}
void win_println(ProfWin *window, theme_item_t theme_item, const char ch, const char *const message, ...) {}
void win_appendln(ProfWin *window, theme_item_t theme_item, const char *const message, ...) {}
char* win_get_title(ProfWin *window)
{