/* fmtext should already be initialized */ void owl_errqueue_to_fmtext(const owl_errqueue *eq, owl_fmtext *fm) { int i, j; j=owl_list_get_size(&(eq->errlist)); for (i=0; i<j; i++) { owl_fmtext_append_normal(fm, owl_list_get_element(&(eq->errlist), i)); owl_fmtext_append_normal(fm, "\n"); } }
static void _owl_keymap_format_bindings(const owl_keymap *km, owl_fmtext *fm) { int i, nbindings; const owl_keybinding *kb; nbindings = owl_list_get_size(&km->bindings); for (i=0; i<nbindings; i++) { char *kbstr; const owl_cmd *cmd; const char *tmpdesc, *desc = ""; kb = owl_list_get_element(&km->bindings, i); kbstr = owl_keybinding_tostring(kb); owl_fmtext_append_normal(fm, OWL_TABSTR); owl_fmtext_append_normal(fm, kbstr); owl_fmtext_append_spaces(fm, 11-strlen(kbstr)); g_free(kbstr); owl_fmtext_append_normal(fm, " - "); if (kb->desc && *kb->desc) { desc = kb->desc; } else if ((cmd=owl_function_get_cmd(kb->command)) && (tmpdesc = owl_cmd_get_summary(cmd))) { desc = tmpdesc; } owl_fmtext_append_normal(fm, desc); if (kb->command && *(kb->command)) { owl_fmtext_append_normal(fm, " ["); owl_fmtext_append_normal(fm, kb->command); owl_fmtext_append_normal(fm, "]"); } owl_fmtext_append_normal(fm, "\n"); } }
/* Append 'nspaces' number of spaces to the end of 'f' */ void owl_fmtext_append_spaces(owl_fmtext *f, int nspaces) { int i; for (i=0; i<nspaces; i++) { owl_fmtext_append_normal(f, " "); } }
/* fmtext should already be initialized */ void owl_view_to_fmtext(const owl_view *v, owl_fmtext *fm) { owl_fmtext_append_normal(fm, "Name: "); owl_fmtext_append_normal(fm, v->name); owl_fmtext_append_normal(fm, "\n"); owl_fmtext_append_normal(fm, "Filter: "); owl_fmtext_append_normal(fm, owl_filter_get_name(v->filter)); owl_fmtext_append_normal(fm, "\n"); owl_fmtext_append_normal(fm, "Style: "); owl_fmtext_append_normal(fm, owl_style_get_name(v->style)); owl_fmtext_append_normal(fm, "\n"); }
/* Create a viewwin. 'win' is an already initialized owl_window that * will be used by the viewwin */ owl_viewwin *owl_viewwin_new_text(owl_window *win, const char *text) { owl_viewwin *v = g_new0(owl_viewwin, 1); owl_fmtext_init_null(&(v->fmtext)); if (text) { owl_fmtext_append_normal(&(v->fmtext), text); if (text[0] != '\0' && text[strlen(text) - 1] != '\n') { owl_fmtext_append_normal(&(v->fmtext), "\n"); } v->textlines=owl_fmtext_num_lines(&(v->fmtext)); } v->topline=0; v->rightshift=0; v->onclose_hook = NULL; owl_viewwin_set_window(v, win); return v; }
/* requires that the list values are strings or NULL. * joins the elements together with join_with. * If format_fn is specified, passes it the list element value * and it will return a string which this needs to free. */ void owl_fmtext_append_list(owl_fmtext *f, const owl_list *l, const char *join_with, char *(format_fn)(const char *)) { int i, size; const char *elem; char *text; size = owl_list_get_size(l); for (i=0; i<size; i++) { elem = owl_list_get_element(l,i); if (elem && format_fn) { text = format_fn(elem); if (text) { owl_fmtext_append_normal(f, text); owl_free(text); } } else if (elem) { owl_fmtext_append_normal(f, elem); } if ((i < size-1) && join_with) { owl_fmtext_append_normal(f, join_with); } } }
void owl_variable_describe(owl_vardict *d, char *name, owl_fmtext *fm) { char defaultbuf[50]; char buf[1024]; int buflen = 1023; owl_variable *v; if (!name || (v = owl_dict_find_element(d, name)) == NULL || !v->get_fn) { snprintf(buf, buflen, " No such variable '%s'\n", name); owl_fmtext_append_normal(fm, buf); return; } if (v->type == OWL_VARIABLE_INT || v->type == OWL_VARIABLE_BOOL) { v->get_tostring_fn(v, defaultbuf, 50, &(v->ival_default)); } else { v->get_tostring_fn(v, defaultbuf, 50, v->pval_default); } snprintf(buf, buflen, OWL_TABSTR "%-20s - %s (default: '%s')\n", v->name, owl_variable_get_summary(v), defaultbuf); owl_fmtext_append_normal(fm, buf); }
/* Create a viewwin. 'win' is an already initialized owl_window that * will be used by the viewwin */ owl_viewwin *owl_viewwin_new_fmtext(owl_window *win, const owl_fmtext *fmtext) { char *text; owl_viewwin *v = g_new0(owl_viewwin, 1); owl_fmtext_copy(&(v->fmtext), fmtext); text = owl_fmtext_print_plain(fmtext); if (text[0] != '\0' && text[strlen(text) - 1] != '\n') { owl_fmtext_append_normal(&(v->fmtext), "\n"); } g_free(text); v->textlines=owl_fmtext_num_lines(&(v->fmtext)); v->topline=0; v->rightshift=0; owl_viewwin_set_window(v, win); return v; }
void owl_help(void) { const owl_variable *v; owl_fmtext fm; const char *varname; GPtrArray *varnames; int i; owl_fmtext_init_null(&fm); owl_fmtext_append_bold (&fm, "OWL HELP\n\n"); owl_fmtext_append_normal (&fm, " If you're new to BarnOwl, the first thing you should type is\n\n" " :show quickstart\n\n" " For help on a specific command use 'help <command>'\n" " For information on advanced keys, use 'show keymaps'.\n" " For information on advanced commands, use 'show commands'.\n" " For information on variables, use 'show variables'.\n\n"); owl_fmtext_append_bold (&fm, " Basic Keys:\n" ); owl_fmtext_append_normal (&fm, " n Move to next non-deleted message\n" " p Move to previous non-deleted message\n" " C-n , down Move to next message\n" " C-p , up Move to previous message\n" " < , > Move to first, last message\n" " right , left Scroll screen left or right\n" " C-v Page down\n" " M-v Page up\n" " i Print more information about a message\n" " P Move to the next personal message\n" " M-P Move to the previous personal message\n" " C-space Move the mark (asterisk) to the current message\n" " C-x C-x Move the mark to the current message while moving to previous mark\n" "\n" " d Mark message for deletion\n" " u Undelete a message marked for deletion\n" " x Expunge deleted messages\n" " X Expunge deleted messages and switch to home view\n" " T Mark all 'trash' messages for deletion\n" " M-D Mark all messages in current view for deletion\n" " M-u Unmark all messages in the current view for deletion\n" "\n" " z Start a zwrite command\n" " a Start an aimwrite command\n" " r Reply to the current message\n" " R Reply to sender\n" " C-r Reply but allow editing of reply line\n" "\n" " M-n View zephyrs in selected conversation\n" " M-N View zephyrs in selected conversation of instance\n" " M-p View only personal zephyrs\n" " V Change to back to home view ('all' by default)\n" " v Start a view command\n" " ! Invert the current view\n" "\n" " l Print a zephyr/AIM buddy listing\n" " A Toggle away\n" " o Toggle one-line display mode\n" " w Open a URL in the current message\n" " C-l Refresh the screen\n" " C-z Suspend BarnOwl\n" " h Print this help message\n" " : , M-x Enter command mode\n" "\n" " / Forward search\n" " ? Reverse search\n" "\n\n" ); owl_fmtext_append_bold (&fm, " Basic Commands:\n" ); owl_fmtext_append_normal (&fm, " quit, exit Exit BarnOwl\n" " help Get help about commands\n" " show Show information about BarnOwl (see detailed help)\n" "\n" " zwrite Send a zephyr\n" " aimlogin Login to AIM\n" " aimwrite Send an AIM message\n" "\n" " addbuddy Add a zephyr or AIM buddy\n" " zaway Turn zaway on or off, or set the message\n" " zlocate Locate a user\n" " subscribe Subscribe to a zephyr class or instance\n" " unsubscribe Unsubscribe to a zephyr class or instance\n" " blist Print a list of zephyr and AIM buddies logged in\n" " search Search for a text string\n" "\n" " set Set a variable (see list below)\n" " print Print a variable's value (variables listed below)\n" " startup Set a command to be run at every BarnOwl startup\n" " unstartup Remove a command to be run at every BarnOwl startup\n" "\n" " getsubs Print a list of current subscriptions\n" " unsuball Unsubscribe from all zephyr classes\n" " load-subs Load zephyr subscriptions from a file\n" " zpunt Suppress messages from a zephyr triplet\n" " zlog Send a login or logout notification\n" " zlist Print a list of zephyr buddies logged in\n" " alist Print a list of AIM buddies logged in\n" " info Print detailed information about the current message\n" " filter Create a message filter\n" " view View messages matching a filter\n" " viewuser View messages to or from a particular user\n" " viewclass View messages to a particular class\n" " expunge Expunge messages marked for deletion\n" " bindkey Create a new key binding\n" " alias Create a command alias\n" " dump Dump messagelist as text to a file\n" "\n" " about Print information about BarnOwl\n" " status Print status information about the running BarnOwl\n" " version Print the version number of BarnOwl\n" "\n"); /* help for variables */ owl_fmtext_append_bold(&fm, "Variables:\n"); varnames = owl_variable_dict_get_names(owl_global_get_vardict(&g)); for (i = 0; i < varnames->len; i++) { varname = varnames->pdata[i]; if (varname && varname[0]!='_') { v = owl_variable_get_var(owl_global_get_vardict(&g), varname); owl_variable_describe(v, &fm); } } owl_ptr_array_free(varnames, g_free); owl_fmtext_append_normal(&fm, "\n"); owl_function_popless_fmtext(&fm); owl_fmtext_cleanup(&fm); }
void owl_variable_get_help(const owl_variable *v, owl_fmtext *fm) { char *tostring; const char *default_str; owl_fmtext_append_bold(fm, "OWL VARIABLE\n\n"); owl_fmtext_append_normal(fm, OWL_TABSTR); owl_fmtext_append_normal(fm, owl_variable_get_name(v)); owl_fmtext_append_normal(fm, " - "); owl_fmtext_append_normal(fm, owl_variable_get_summary(v)); owl_fmtext_append_normal(fm, "\n\n"); owl_fmtext_append_normal(fm, "Current: "); tostring = owl_variable_get_tostring(v); owl_fmtext_append_normal(fm, (tostring ? tostring : "<null>")); g_free(tostring); owl_fmtext_append_normal(fm, "\n\n"); default_str = owl_variable_get_default_tostring(v); owl_fmtext_append_normal(fm, "Default: "); owl_fmtext_append_normal(fm, (default_str ? default_str : "<null>")); owl_fmtext_append_normal(fm, "\n\n"); owl_fmtext_append_normal(fm, "Valid Settings: "); owl_fmtext_append_normal(fm, owl_variable_get_validsettings(v)); owl_fmtext_append_normal(fm, "\n\n"); if (v->description && *v->description) { owl_fmtext_append_normal(fm, "Description:\n"); owl_fmtext_append_normal(fm, owl_variable_get_description(v)); owl_fmtext_append_normal(fm, "\n\n"); } }
/* Truncate the message so that each line begins at column 'acol' and * ends at 'bcol' or sooner. The first column is number 0. The new * message is placed in 'out'. The message is expected to end in a * new line for now. * * NOTE: This needs to be modified to deal with backing up if we find * a SPACING COMBINING MARK at the end of a line. If that happens, we * should back up to the last non-mark character and stop there. * * NOTE: If a line ends at bcol, we omit the newline. This is so printing * to ncurses works. */ void owl_fmtext_truncate_cols(const owl_fmtext *in, int acol, int bcol, owl_fmtext *out) { const char *ptr_s, *ptr_e, *ptr_c, *last; int col, st, padding, chwidth; /* copy the default attributes */ out->default_attrs = in->default_attrs; out->default_fgcolor = in->default_fgcolor; out->default_bgcolor = in->default_bgcolor; last=in->textbuff+in->textlen-1; ptr_s=in->textbuff; while (ptr_s <= last) { ptr_e=strchr(ptr_s, '\n'); if (!ptr_e) { /* but this shouldn't happen if we end in a \n */ break; } if (ptr_e == ptr_s) { owl_fmtext_append_normal(out, "\n"); ++ptr_s; continue; } col = 0; st = 0; padding = 0; chwidth = 0; ptr_c = ptr_s; while(ptr_c < ptr_e) { gunichar c = g_utf8_get_char(ptr_c); if (!owl_fmtext_is_format_char(c)) { chwidth = mk_wcwidth(c); if (col + chwidth > bcol) break; if (col >= acol) { if (st == 0) { ptr_s = ptr_c; padding = col - acol; ++st; } } col += chwidth; chwidth = 0; } ptr_c = g_utf8_next_char(ptr_c); } if (st) { /* lead padding */ owl_fmtext_append_spaces(out, padding); if (ptr_c == ptr_e) { /* We made it to the newline. */ _owl_fmtext_append_fmtext(out, in, ptr_s - in->textbuff, ptr_c - in->textbuff); } else if (chwidth > 1) { /* Last char is wide, truncate. */ _owl_fmtext_append_fmtext(out, in, ptr_s - in->textbuff, ptr_c - in->textbuff - 1); owl_fmtext_append_normal(out, "\n"); } else { /* Last char fits perfectly, We skip to the next char and back * up a byte to make sure we get it all. */ ptr_c = g_utf8_next_char(ptr_c); _owl_fmtext_append_fmtext(out, in, ptr_s - in->textbuff, ptr_c - in->textbuff - 1); } } else { owl_fmtext_append_normal(out, "\n"); } ptr_s = g_utf8_next_char(ptr_e); } }
void owl_variable_get_help(owl_vardict *d, char *name, owl_fmtext *fm) { char buff[1024]; int bufflen = 1023; owl_variable *v; if (!name || (v = owl_dict_find_element(d, name)) == NULL || !v->get_fn) { owl_fmtext_append_normal(fm, "No such variable...\n"); return; } owl_fmtext_append_bold(fm, "OWL VARIABLE\n\n"); owl_fmtext_append_normal(fm, OWL_TABSTR); owl_fmtext_append_normal(fm, name); owl_fmtext_append_normal(fm, " - "); owl_fmtext_append_normal(fm, v->summary); owl_fmtext_append_normal(fm, "\n\n"); owl_fmtext_append_normal(fm, "Current: "); owl_variable_get_tostring(d, name, buff, bufflen); owl_fmtext_append_normal(fm, buff); owl_fmtext_append_normal(fm, "\n\n"); if (v->type == OWL_VARIABLE_INT || v->type == OWL_VARIABLE_BOOL) { v->get_tostring_fn(v, buff, bufflen, &(v->ival_default)); } else { v->get_tostring_fn(v, buff, bufflen, v->pval_default); } owl_fmtext_append_normal(fm, "Default: "); owl_fmtext_append_normal(fm, buff); owl_fmtext_append_normal(fm, "\n\n"); owl_fmtext_append_normal(fm, "Valid Settings: "); owl_fmtext_append_normal(fm, owl_variable_get_validsettings(v)); owl_fmtext_append_normal(fm, "\n\n"); if (v->description && *v->description) { owl_fmtext_append_normal(fm, "Description:\n"); owl_fmtext_append_normal(fm, owl_variable_get_description(v)); owl_fmtext_append_normal(fm, "\n\n"); } }
void owl_cmd_get_help(const owl_cmddict *d, const char *name, owl_fmtext *fm) { const char *s; char *indent; owl_cmd *cmd; if (!name || (cmd = owl_dict_find_element(d, name)) == NULL) { owl_fmtext_append_bold(fm, "OWL HELP\n\n"); owl_fmtext_append_normal(fm, "No such command...\n"); return; } owl_fmtext_append_bold(fm, "OWL HELP\n\n"); owl_fmtext_append_bold(fm, "NAME\n\n"); owl_fmtext_append_normal(fm, OWL_TABSTR); owl_fmtext_append_normal(fm, cmd->name); if (cmd->summary && *cmd->summary) { owl_fmtext_append_normal(fm, " - "); owl_fmtext_append_normal(fm, cmd->summary); } owl_fmtext_append_normal(fm, "\n"); if (cmd->usage && *cmd->usage) { s = cmd->usage; indent = owl_text_indent(s, OWL_TAB, true); owl_fmtext_append_bold(fm, "\nSYNOPSIS\n"); owl_fmtext_append_normal(fm, indent); owl_fmtext_append_normal(fm, "\n"); g_free(indent); } else { owl_fmtext_append_bold(fm, "\nSYNOPSIS\n"); owl_fmtext_append_normal(fm, OWL_TABSTR); owl_fmtext_append_normal(fm, cmd->name); owl_fmtext_append_normal(fm, "\n"); } if (cmd->description && *cmd->description) { s = cmd->description; indent = owl_text_indent(s, OWL_TAB, true); owl_fmtext_append_bold(fm, "\nDESCRIPTION\n"); owl_fmtext_append_normal(fm, indent); owl_fmtext_append_normal(fm, "\n"); g_free(indent); } owl_fmtext_append_normal(fm, "\n\n"); }
/* Appends details about the keymap to fm */ void owl_keymap_get_details(const owl_keymap *km, owl_fmtext *fm, int recurse) { owl_fmtext_append_bold(fm, "KEYMAP - "); owl_fmtext_append_bold(fm, km->name); owl_fmtext_append_normal(fm, "\n"); if (km->desc) { owl_fmtext_append_normal(fm, OWL_TABSTR "Purpose: "); owl_fmtext_append_normal(fm, km->desc); owl_fmtext_append_normal(fm, "\n"); } if (km->parent) { owl_fmtext_append_normal(fm, OWL_TABSTR "Has parent: "); owl_fmtext_append_normal(fm, km->parent->name); owl_fmtext_append_normal(fm, "\n"); } owl_fmtext_append_normal(fm, "\n"); if (km->default_fn) { owl_fmtext_append_normal(fm, OWL_TABSTR "Has a default keypress handler (default_fn).\n"); } if (km->prealways_fn) { owl_fmtext_append_normal(fm, OWL_TABSTR "Executes a function (prealways_fn) on every keypress.\n"); } if (km->postalways_fn) { owl_fmtext_append_normal(fm, OWL_TABSTR "Executes a function (postalways_fn) after handling every keypress.\n"); } owl_fmtext_append_bold(fm, "\nKey bindings:\n\n"); if (recurse) { _owl_keymap_format_with_parents(km, fm); } else { _owl_keymap_format_bindings(km, fm); } }
void owl_viewwin_append_text(owl_viewwin *v, const char *text) { owl_fmtext_append_normal(&(v->fmtext), text); v->textlines=owl_fmtext_num_lines(&(v->fmtext)); owl_viewwin_dirty(v); }