menuconfig: wrap long help lines

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Linux Kernel Mailing List
Date: Tuesday, June 1, 2010 - 9:59 am

Gitweb:     http://git.kernel.org/linus/da60fbbcb637b37b1d77a41886ae4e275422ca96
Commit:     da60fbbcb637b37b1d77a41886ae4e275422ca96
Parent:     5358db0b0e16470337c6ec08177deb3f68ed7673
Author:     Vadim Bendebury (вб) <vbendeb@google.com>
AuthorDate: Sun Dec 20 00:29:49 2009 -0800
Committer:  Michal Marek <mmarek@suse.cz>
CommitDate: Tue Feb 2 14:33:55 2010 +0100

    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>
---
 scripts/kconfig/expr.c  |   27 +++++++++++++++++++++++++--
 scripts/kconfig/lkc.h   |    5 +++++
 scripts/kconfig/mconf.c |    1 +
 scripts/kconfig/util.c  |    2 ++
 4 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/scripts/kconfig/expr.c b/scripts/kconfig/expr.c
index edd3f39..d83f232 100644
--- a/scripts/kconfig/expr.c
+++ b/scripts/kconfig/expr.c
@@ -1097,9 +1097,32 @@ void expr_fprint(struct expr *e, FILE *out)
 
 static void expr_print_gstr_helper(void *data, struct symbol *sym, const char *str)
 {
-	str_append((struct gstr*)data, str);
+	struct gstr *gs = (struct gstr*)data;
+	const char *sym_str = NULL;
+
+	if (sym)
+		sym_str = sym_get_string_value(sym);
+
+	if (gs->max_width) {
+		unsigned extra_length = strlen(str);
+		const char *last_cr = strrchr(gs->s, '\n');
+		unsigned last_line_length;
+
+		if (sym_str)
+			extra_length += 4 + strlen(sym_str);
+
+		if (!last_cr)
+			last_cr = gs->s;
+
+		last_line_length = strlen(gs->s) - (last_cr - gs->s);
+
+		if ((last_line_length + extra_length) > gs->max_width)
+			str_append(gs, "\\\n");
+	}
+
+	str_append(gs, str);
 	if (sym)
-		str_printf((struct gstr*)data, " [=%s]", sym_get_string_value(sym));
+		str_printf(gs, " [=%s]", sym_str);
 }
 
 void expr_gstr_print(struct expr *e, struct gstr *gs)
diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h
index f379b0b..e59dd0c 100644
--- a/scripts/kconfig/lkc.h
+++ b/scripts/kconfig/lkc.h
@@ -106,6 +106,11 @@ int file_write_dep(const char *name);
 struct gstr {
 	size_t len;
 	char  *s;
+	/*
+	* when max_width is not zero long lines in string s (if any) get
+	* wrapped not to exceed the max_width value
+	*/
+	int max_width;
 };
 struct gstr str_new(void);
 struct gstr str_assign(const char *s);
diff --git a/scripts/kconfig/mconf.c b/scripts/kconfig/mconf.c
index 8413cf3..ac1e9da 100644
--- a/scripts/kconfig/mconf.c
+++ b/scripts/kconfig/mconf.c
@@ -638,6 +638,7 @@ static void show_help(struct menu *menu)
 {
 	struct gstr help = str_new();
 
+	help.max_width = getmaxx(stdscr) - 10;
 	menu_get_ext_help(menu, &help);
 
 	show_helptext(_(menu_get_prompt(menu)), str_get(&help));
diff --git a/scripts/kconfig/util.c b/scripts/kconfig/util.c
index b6b2a46..81c100d 100644
--- a/scripts/kconfig/util.c
+++ b/scripts/kconfig/util.c
@@ -78,6 +78,7 @@ struct gstr str_new(void)
 	struct gstr gs;
 	gs.s = malloc(sizeof(char) * 64);
 	gs.len = 64;
+	gs.max_width = 0;
 	strcpy(gs.s, "\0");
 	return gs;
 }
@@ -88,6 +89,7 @@ struct gstr str_assign(const char *s)
 	struct gstr gs;
 	gs.s = strdup(s);
 	gs.len = strlen(s) + 1;
+	gs.max_width = 0;
 	return gs;
 }
 
--
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
menuconfig: wrap long help lines, Linux Kernel Mailing ..., (Tue Jun 1, 9:59 am)