From: Richard Russon Date: Mon, 21 Oct 2019 10:45:27 +0000 (+0100) Subject: eliminate MuttIndexWindow from deep functions X-Git-Tag: 2019-10-25~1^2~3 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=60ce0c0478c8b6c91ea861c88bf7cccbf2ae3883;p=neomutt eliminate MuttIndexWindow from deep functions These functions needed an extra parameter: - `mutt_help()` - `dump_unbound()` - `dump_menu()` - `format_line()` These functions used the new `State.wraplen` member: - `quote_width()` - `text_enriched_handler()` --- diff --git a/enriched.c b/enriched.c index 6cf6ad043..abd715ba8 100644 --- a/enriched.c +++ b/enriched.c @@ -477,10 +477,9 @@ int text_enriched_handler(struct Body *a, struct State *s) wchar_t tag[1024 + 1]; stte.s = s; - stte.wrap_margin = - ((s->flags & MUTT_DISPLAY) ? - (MuttIndexWindow->cols - 4) : - ((MuttIndexWindow->cols - 4) < 72) ? (MuttIndexWindow->cols - 4) : 72); + stte.wrap_margin = ((s->flags & MUTT_DISPLAY) ? + (s->wraplen - 4) : + ((s->wraplen - 4) < 72) ? (s->wraplen - 4) : 72); stte.line_max = stte.wrap_margin * 4; stte.line = mutt_mem_calloc((stte.line_max + 1), sizeof(wchar_t)); stte.param = mutt_mem_calloc(256, sizeof(wchar_t)); diff --git a/help.c b/help.c index 1df2e77d6..a3b12115f 100644 --- a/help.c +++ b/help.c @@ -274,6 +274,7 @@ static int pad(FILE *fp, int col, int i) * @param t1 Text part 1 * @param t2 Text part 2 * @param t3 Text part 3 + * @param wraplen Width to wrap to * * Assemble the three columns of text. * @@ -282,7 +283,8 @@ static int pad(FILE *fp, int col, int i) * * 0 : Non-macro * * -1 : Macro with no description */ -static void format_line(FILE *fp, int ismacro, const char *t1, const char *t2, const char *t3) +static void format_line(FILE *fp, int ismacro, const char *t1, const char *t2, + const char *t3, int wraplen) { int col; int col_b; @@ -290,7 +292,7 @@ static void format_line(FILE *fp, int ismacro, const char *t1, const char *t2, c fputs(t1, fp); /* don't try to press string into one line with less than 40 characters. */ - bool split = (MuttIndexWindow->cols < 40); + bool split = (wraplen < 40); if (split) { col = 0; @@ -299,9 +301,8 @@ static void format_line(FILE *fp, int ismacro, const char *t1, const char *t2, c } else { - const int col_a = - (MuttIndexWindow->cols > 83) ? (MuttIndexWindow->cols - 32) >> 2 : 12; - col_b = (MuttIndexWindow->cols > 49) ? (MuttIndexWindow->cols - 10) >> 1 : 19; + const int col_a = (wraplen > 83) ? (wraplen - 32) >> 2 : 12; + col_b = (wraplen > 49) ? (wraplen - 10) >> 1 : 19; col = pad(fp, mutt_strwidth(t1), col_a); } @@ -335,7 +336,7 @@ static void format_line(FILE *fp, int ismacro, const char *t1, const char *t2, c { while (*t3) { - int n = MuttIndexWindow->cols - col; + int n = wraplen - col; if (ismacro >= 0) { @@ -354,7 +355,7 @@ static void format_line(FILE *fp, int ismacro, const char *t1, const char *t2, c } else { - n += col - MuttIndexWindow->cols; + n += col - wraplen; if (C_Markers) n++; } @@ -368,10 +369,11 @@ static void format_line(FILE *fp, int ismacro, const char *t1, const char *t2, c /** * dump_menu - Write all the key bindings to a file - * @param fp File to write to - * @param menu Current Menu, e.g. #MENU_PAGER + * @param fp File to write to + * @param menu Current Menu, e.g. #MENU_PAGER + * @param wraplen Width to wrap to */ -static void dump_menu(FILE *fp, enum MenuType menu) +static void dump_menu(FILE *fp, enum MenuType menu, int wraplen) { struct Keymap *map = NULL; const struct Binding *b = NULL; @@ -387,15 +389,15 @@ static void dump_menu(FILE *fp, enum MenuType menu) if (map->op == OP_MACRO) { if (map->desc) - format_line(fp, 1, buf, map->macro, map->desc); + format_line(fp, 1, buf, map->macro, map->desc, wraplen); else - format_line(fp, -1, buf, "macro", map->macro); + format_line(fp, -1, buf, "macro", map->macro, wraplen); } else { b = help_lookup_function(map->op, menu); format_line(fp, 0, buf, b ? b->name : "UNKNOWN", - b ? _(HelpStrings[b->op]) : _("ERROR: please report this bug")); + b ? _(HelpStrings[b->op]) : _("ERROR: please report this bug"), wraplen); } } } @@ -417,26 +419,28 @@ static bool is_bound(struct Keymap *map, int op) /** * dump_unbound - Write out all the operations with no key bindings - * @param fp File to write to - * @param funcs All the bindings for the current menu - * @param map First key map to consider - * @param aux Second key map to consider + * @param fp File to write to + * @param funcs All the bindings for the current menu + * @param map First key map to consider + * @param aux Second key map to consider + * @param wraplen Width to wrap to */ static void dump_unbound(FILE *fp, const struct Binding *funcs, - struct Keymap *map, struct Keymap *aux) + struct Keymap *map, struct Keymap *aux, int wraplen) { for (int i = 0; funcs[i].name; i++) { if (!is_bound(map, funcs[i].op) && (!aux || !is_bound(aux, funcs[i].op))) - format_line(fp, 0, funcs[i].name, "", _(HelpStrings[funcs[i].op])); + format_line(fp, 0, funcs[i].name, "", _(HelpStrings[funcs[i].op]), wraplen); } } /** * mutt_help - Display the help menu - * @param menu Current Menu + * @param menu Current Menu + * @param wraplen Width to wrap to */ -void mutt_help(enum MenuType menu) +void mutt_help(enum MenuType menu, int wraplen) { char buf[128]; FILE *fp = NULL; @@ -459,18 +463,18 @@ void mutt_help(enum MenuType menu) goto cleanup; } - dump_menu(fp, menu); + dump_menu(fp, menu, wraplen); if ((menu != MENU_EDITOR) && (menu != MENU_PAGER)) { fprintf(fp, "\n%s\n\n", _("Generic bindings:")); - dump_menu(fp, MENU_GENERIC); + dump_menu(fp, MENU_GENERIC, wraplen); } fprintf(fp, "\n%s\n\n", _("Unbound functions:")); if (funcs) - dump_unbound(fp, funcs, Keymaps[menu], NULL); + dump_unbound(fp, funcs, Keymaps[menu], NULL, wraplen); if (menu != MENU_PAGER) - dump_unbound(fp, OpGeneric, Keymaps[MENU_GENERIC], Keymaps[menu]); + dump_unbound(fp, OpGeneric, Keymaps[MENU_GENERIC], Keymaps[menu], wraplen); mutt_file_fclose(&fp); diff --git a/index.c b/index.c index 132fbfcb8..e93992680 100644 --- a/index.c +++ b/index.c @@ -1632,7 +1632,7 @@ int mutt_index_menu(void) } case OP_HELP: - mutt_help(MENU_MAIN); + mutt_help(MENU_MAIN, MuttIndexWindow->cols); menu->redraw = REDRAW_FULL; break; diff --git a/menu.c b/menu.c index dc948f003..d32418f38 100644 --- a/menu.c +++ b/menu.c @@ -1573,7 +1573,7 @@ int mutt_menu_loop(struct Menu *menu) break; case OP_HELP: - mutt_help(menu->type); + mutt_help(menu->type, menu->indexwin->cols); menu->redraw = REDRAW_FULL; break; diff --git a/pager.c b/pager.c index c617cdc19..70f6bd3b6 100644 --- a/pager.c +++ b/pager.c @@ -2833,7 +2833,7 @@ int mutt_pager(const char *banner, const char *fname, PagerFlags flags, struct P if (!InHelp) { InHelp = true; - mutt_help(MENU_PAGER); + mutt_help(MENU_PAGER, MuttIndexWindow->cols); pager_menu->redraw = REDRAW_FULL; InHelp = false; } diff --git a/protos.h b/protos.h index 9ad5b65bb..58b5ea71b 100644 --- a/protos.h +++ b/protos.h @@ -63,7 +63,7 @@ int mutt_ev_message(struct Mailbox *m, struct EmailList *el, enum EvMessage acti int mutt_system(const char *cmd); int mutt_set_xdg_path(enum XdgType type, char *buf, size_t bufsize); -void mutt_help(enum MenuType menu); +void mutt_help(enum MenuType menu, int wraplan); void mutt_make_help(char *d, size_t dlen, const char *txt, enum MenuType menu, int op); void mutt_set_flag_update(struct Mailbox *m, struct Email *e, int flag, bool bf, bool upd_mbox); #define mutt_set_flag(m, e, flag, bf) mutt_set_flag_update(m, e, flag, bf, true) diff --git a/rfc3676.c b/rfc3676.c index 65186f568..325dee14d 100644 --- a/rfc3676.c +++ b/rfc3676.c @@ -191,7 +191,8 @@ static void flush_par(struct State *s, struct FlowedState *fst) */ static int quote_width(struct State *s, int ql) { - int width = mutt_window_wrap_cols(MuttIndexWindow->cols, C_ReflowWrap); + const int screen_width = (s->flags & MUTT_DISPLAY) ? s->wraplen : 80; + int width = mutt_window_wrap_cols(screen_width, C_ReflowWrap); if (C_TextFlowed && (s->flags & MUTT_REPLYING)) { /* When replying, force a wrap at FLOWED_MAX to comply with RFC3676