Help text for certain config options is very extensive (the text includes the names of all other options the option in question depends on). Long lines are not wrapped, making it impossible to see the list without scrolling horizontally. This patch adds some logic which wraps help screen lines at word boundaries to prevent truncating. Tested by running ARCH=powerpc make menuconfig O=/tmp/build which shows that the long lines are now wrapped, and ARCH=powerpc make xconfig O=/tmp/build to demonstrate that it still compiles and operates as expected.
Unified · Split
| @@ -1097,9 +1097,32 @@ void expr_fprint(struct expr *e, FILE *out) · 1096 unmodified lines | |||
| 1097 | 1097 | ||
| 1098 | static void expr_print_gstr_helper(void *data, struct symbol *sym, const char *str) | 1098 | static void expr_print_gstr_helper(void *data, struct symbol *sym, const char *str) |
| 1099 | { | 1099 | { |
| 1100 | str_append((struct gstr*)data, str); | 1100 | struct gstr *gs = (struct gstr*)data; |
| 1101 | const char *sym_str = NULL; | ||
| 1102 | |||
| 1103 | if (sym) | ||
| 1104 | sym_str = sym_get_string_value(sym); | ||
| 1105 | |||
| 1106 | if (gs->max_width) { | ||
| 1107 | unsigned extra_length = strlen(str); | ||
| 1108 | const char *last_cr = strrchr(gs->s, '\n'); | ||
| 1109 | unsigned last_line_length; | ||
| 1110 | |||
| 1111 | if (sym_str) | ||
| 1112 | extra_length += 4 + strlen(sym_str); | ||
| 1113 | |||
| 1114 | if (!last_cr) | ||
| 1115 | last_cr = gs->s; | ||
| 1116 | |||
| 1117 | last_line_length = strlen(gs->s) - (last_cr - gs->s); | ||
| 1118 | |||
| 1119 | if ((last_line_length + extra_length) > gs->max_width) | ||
| 1120 | str_append(gs, "\\\n"); | ||
| 1121 | } | ||
| 1122 | |||
| 1123 | str_append(gs, str); | ||
| 1101 | if (sym) | 1124 | if (sym) |
| 1102 | str_printf((struct gstr*)data, " [=%s]", sym_get_string_value(sym)); | 1125 | str_printf(gs, " [=%s]", sym_str); |
| 1103 | } | 1126 | } |
| 1104 | 1127 | ||
| 1105 | void expr_gstr_print(struct expr *e, struct gstr *gs) | 1128 | void expr_gstr_print(struct expr *e, struct gstr *gs) |
| @@ -106,6 +106,11 @@ int file_write_dep(const char *name); · 105 unmodified lines | |||
| 106 | struct gstr { | 106 | struct gstr { |
| 107 | size_t len; | 107 | size_t len; |
| 108 | char *s; | 108 | char *s; |
| 109 | /* | ||
| 110 | * when max_width is not zero long lines in string s (if any) get | ||
| 111 | * wrapped not to exceed the max_width value | ||
| 112 | */ | ||
| 113 | int max_width; | ||
| 109 | }; | 114 | }; |
| 110 | struct gstr str_new(void); | 115 | struct gstr str_new(void); |
| 111 | struct gstr str_assign(const char *s); | 116 | struct gstr str_assign(const char *s); |
| @@ -638,6 +638,7 @@ static void show_help(struct menu *menu) · 637 unmodified lines | |||
| 638 | { | 638 | { |
| 639 | struct gstr help = str_new(); | 639 | struct gstr help = str_new(); |
| 640 | 640 | ||
| 641 | help.max_width = getmaxx(stdscr) - 10; | ||
| 641 | menu_get_ext_help(menu, &help); | 642 | menu_get_ext_help(menu, &help); |
| 642 | 643 | ||
| 643 | show_helptext(_(menu_get_prompt(menu)), str_get(&help)); | 644 | show_helptext(_(menu_get_prompt(menu)), str_get(&help)); |
| @@ -78,6 +78,7 @@ struct gstr str_new(void) · 77 unmodified lines | |||
| 78 | struct gstr gs; | 78 | struct gstr gs; |
| 79 | gs.s = malloc(sizeof(char) * 64); | 79 | gs.s = malloc(sizeof(char) * 64); |
| 80 | gs.len = 64; | 80 | gs.len = 64; |
| 81 | gs.max_width = 0; | ||
| 81 | strcpy(gs.s, "\0"); | 82 | strcpy(gs.s, "\0"); |
| 82 | return gs; | 83 | return gs; |
| 83 | } | 84 | } |
| @@ -88,6 +89,7 @@ struct gstr str_assign(const char *s) · 4 unmodified lines | |||
| 88 | struct gstr gs; | 89 | struct gstr gs; |
| 89 | gs.s = strdup(s); | 90 | gs.s = strdup(s); |
| 90 | gs.len = strlen(s) + 1; | 91 | gs.len = strlen(s) + 1; |
| 92 | gs.max_width = 0; | ||
| 91 | return gs; | 93 | return gs; |
| 92 | } | 94 | } |
| 93 | 95 | ||