Skip to content

Commit da60fbb

Browse files
vbendeb-langmichal42
authored andcommitted
menuconfig: wrap long help lines
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. Signed-off-by: Vadim Bendebury <vbendeb@google.com> Signed-off-by: Michal Marek <mmarek@suse.cz>
1 parent 5358db0 commit da60fbb

4 files changed

Lines changed: 33 additions & 2 deletions

File tree

‎scripts/kconfig/expr.c‎

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,9 +1097,32 @@ void expr_fprint(struct expr *e, FILE *out)
10971097

10981098
static void expr_print_gstr_helper(void *data, struct symbol *sym, const char *str)
10991099
{
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);
11011124
if (sym)
1102-
str_printf((struct gstr*)data, " [=%s]", sym_get_string_value(sym));
1125+
str_printf(gs, " [=%s]", sym_str);
11031126
}
11041127

11051128
void expr_gstr_print(struct expr *e, struct gstr *gs)

‎scripts/kconfig/lkc.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ int file_write_dep(const char *name);
106106
struct gstr {
107107
size_t len;
108108
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;
109114
};
110115
struct gstr str_new(void);
111116
struct gstr str_assign(const char *s);

‎scripts/kconfig/mconf.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,7 @@ static void show_help(struct menu *menu)
638638
{
639639
struct gstr help = str_new();
640640

641+
help.max_width = getmaxx(stdscr) - 10;
641642
menu_get_ext_help(menu, &help);
642643

643644
show_helptext(_(menu_get_prompt(menu)), str_get(&help));

‎scripts/kconfig/util.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ struct gstr str_new(void)
7878
struct gstr gs;
7979
gs.s = malloc(sizeof(char) * 64);
8080
gs.len = 64;
81+
gs.max_width = 0;
8182
strcpy(gs.s, "\0");
8283
return gs;
8384
}
@@ -88,6 +89,7 @@ struct gstr str_assign(const char *s)
8889
struct gstr gs;
8990
gs.s = strdup(s);
9091
gs.len = strlen(s) + 1;
92+
gs.max_width = 0;
9193
return gs;
9294
}
9395

0 commit comments

Comments
 (0)