linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Benjamin Poirier <bpoirier@suse.de>
To: Michal Marek <mmarek@suse.cz>
Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org,
	Randy Dunlap <rdunlap@xenotime.net>,
	Borislav Petkov <bp@alien8.de>,
	"Yann E. MORIN" <yann.morin.1998@free.fr>,
	Jean Sacren <sakiwit@gmail.com>,
	Arnaud Lacombe <lacombar@gmail.com>,
	Lucas De Marchi <lucas.demarchi@profusion.mobi>,
	Davidlohr Bueso <dave@gnu.org>, Wang YanQing <udknight@gmail.com>,
	Paul Gortmaker <paul.gortmaker@windriver.com>,
	Cheng Renquan <crquan@gmail.com>
Subject: [PATCH v2 2/6] menuconfig: Extend dialog_textbox so that it can exit on arbitrary keypresses
Date: Thu, 23 Aug 2012 14:55:04 -0400	[thread overview]
Message-ID: <1345748108-12206-3-git-send-email-bpoirier@suse.de> (raw)
In-Reply-To: <1345748108-12206-1-git-send-email-bpoirier@suse.de>

The caller will be able to perform actions based on hotkeys in the displayed
text.

Signed-off-by: Benjamin Poirier <bpoirier@suse.de>
---
 scripts/kconfig/lxdialog/dialog.h  |    3 ++-
 scripts/kconfig/lxdialog/textbox.c |   31 +++++++++++++++++++++----------
 scripts/kconfig/mconf.c            |   12 ++++++++++--
 3 files changed, 33 insertions(+), 13 deletions(-)

diff --git a/scripts/kconfig/lxdialog/dialog.h b/scripts/kconfig/lxdialog/dialog.h
index b5211fc..014c029 100644
--- a/scripts/kconfig/lxdialog/dialog.h
+++ b/scripts/kconfig/lxdialog/dialog.h
@@ -209,7 +209,8 @@ int first_alpha(const char *string, const char *exempt);
 int dialog_yesno(const char *title, const char *prompt, int height, int width);
 int dialog_msgbox(const char *title, const char *prompt, int height,
 		  int width, int pause);
-int dialog_textbox(const char *title, const char *file, int height, int width);
+int dialog_textbox(const char *title, const char *file, int height, int width,
+		   int *keys);
 int dialog_menu(const char *title, const char *prompt,
 		const void *selected, int *s_scroll);
 int dialog_checklist(const char *title, const char *prompt, int height,
diff --git a/scripts/kconfig/lxdialog/textbox.c b/scripts/kconfig/lxdialog/textbox.c
index 264a2b9..eb4ee92 100644
--- a/scripts/kconfig/lxdialog/textbox.c
+++ b/scripts/kconfig/lxdialog/textbox.c
@@ -47,14 +47,16 @@ static void refresh_text_box(WINDOW *dialog, WINDOW *box, int boxh, int boxw,
 
 /*
  * Display text from a file in a dialog box.
+ *
+ * keys is a null-terminated array
  */
-int dialog_textbox(const char *title, const char *tbuf,
-		   int initial_height, int initial_width)
+int dialog_textbox(const char *title, const char *tbuf, int initial_height,
+		   int initial_width, int *keys)
 {
 	int i, x, y, cur_x, cur_y, key = 0;
 	int height, width, boxh, boxw;
-	int passed_end;
 	WINDOW *dialog, *box;
+	bool done = false;
 
 	begin_reached = 1;
 	end_reached = 0;
@@ -122,7 +124,7 @@ do_resize:
 	attr_clear(box, boxh, boxw, dlg.dialog.atr);
 	refresh_text_box(dialog, box, boxh, boxw, cur_y, cur_x);
 
-	while ((key != KEY_ESC) && (key != '\n')) {
+	while (!done) {
 		key = wgetch(dialog);
 		switch (key) {
 		case 'E':	/* Exit */
@@ -130,9 +132,9 @@ do_resize:
 		case 'X':
 		case 'x':
 		case 'q':
-			delwin(box);
-			delwin(dialog);
-			return 0;
+		case '\n':
+			done = true;
+			break;
 		case 'g':	/* First page */
 		case KEY_HOME:
 			if (!begin_reached) {
@@ -156,6 +158,8 @@ do_resize:
 		case 'k':
 		case KEY_UP:
 			if (!begin_reached) {
+				int passed_end = 0;
+
 				back_lines(page_length + 1);
 
 				/* We don't call print_page() here but use
@@ -169,7 +173,6 @@ do_resize:
 				wscrl(box, -1);	/* Scroll box region down one line */
 				scrollok(box, FALSE);
 				page_length = 0;
-				passed_end = 0;
 				for (i = 0; i < boxh; i++) {
 					if (!i) {
 						/* print first line of page */
@@ -252,7 +255,8 @@ do_resize:
 					 cur_y, cur_x);
 			break;
 		case KEY_ESC:
-			key = on_key_esc(dialog);
+			if (on_key_esc(dialog) == KEY_ESC)
+				done = true;
 			break;
 		case KEY_RESIZE:
 			back_lines(height);
@@ -260,11 +264,18 @@ do_resize:
 			delwin(dialog);
 			on_key_resize();
 			goto do_resize;
+		default:
+			for (i = 0; keys[i]; i++) {
+				if (key == keys[i]) {
+					done = true;
+					break;
+				}
+			}
 		}
 	}
 	delwin(box);
 	delwin(dialog);
-	return key;		/* ESC pressed */
+	return key;
 }
 
 /*
diff --git a/scripts/kconfig/mconf.c b/scripts/kconfig/mconf.c
index f584a28..116e5da 100644
--- a/scripts/kconfig/mconf.c
+++ b/scripts/kconfig/mconf.c
@@ -280,6 +280,8 @@ static void conf_choice(struct menu *menu);
 static void conf_string(struct menu *menu);
 static void conf_load(void);
 static void conf_save(void);
+static int show_textbox_ext(const char *title, const char *text, int r, int c,
+			    int *keys);
 static void show_textbox(const char *title, const char *text, int r, int c);
 static void show_helptext(const char *title, const char *text);
 static void show_help(struct menu *menu);
@@ -619,10 +621,16 @@ static void conf(struct menu *menu)
 	}
 }
 
-static void show_textbox(const char *title, const char *text, int r, int c)
+static int show_textbox_ext(const char *title, const char *text, int r, int c,
+			    int *keys)
 {
 	dialog_clear();
-	dialog_textbox(title, text, r, c);
+	return dialog_textbox(title, text, r, c, keys);
+}
+
+static void show_textbox(const char *title, const char *text, int r, int c)
+{
+	show_textbox_ext(title, text, r, c, (int []) {0});
 }
 
 static void show_helptext(const char *title, const char *text)
-- 
1.7.7


  parent reply	other threads:[~2012-08-23 18:57 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-23 18:55 [PATCH v2 0/6] menuconfig: jump to search results Benjamin Poirier
2012-08-23 18:55 ` [PATCH v2 1/6] menuconfig: Remove superfluous conditionnal Benjamin Poirier
2012-08-23 18:55 ` Benjamin Poirier [this message]
2012-08-23 18:55 ` [PATCH v2 3/6] menuconfig: Extend dialog_textbox so that it can return to a scrolled position Benjamin Poirier
2012-08-23 18:55 ` [PATCH v2 4/6] menuconfig: Add jump keys to search results Benjamin Poirier
2012-08-27 12:37   ` Dirk Gouders
2012-08-23 18:55 ` [PATCH v2 5/6] menuconfig: Do not open code textbox scroll up/down Benjamin Poirier
2012-08-23 18:55 ` [PATCH v2 6/6] menuconfig: Assign jump keys per-page instead of globally Benjamin Poirier
2012-08-24 15:49 ` [PATCH v2 0/6] menuconfig: jump to search results Borislav Petkov
2012-08-24 17:24   ` Benjamin Poirier
2012-09-27 16:14 ` Michal Marek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1345748108-12206-3-git-send-email-bpoirier@suse.de \
    --to=bpoirier@suse.de \
    --cc=bp@alien8.de \
    --cc=crquan@gmail.com \
    --cc=dave@gnu.org \
    --cc=lacombar@gmail.com \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lucas.demarchi@profusion.mobi \
    --cc=mmarek@suse.cz \
    --cc=paul.gortmaker@windriver.com \
    --cc=rdunlap@xenotime.net \
    --cc=sakiwit@gmail.com \
    --cc=udknight@gmail.com \
    --cc=yann.morin.1998@free.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).