public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] menuconfig:inputbox: support navigate input position
@ 2012-12-17 14:38 Wang YanQing
  2012-12-17 18:22 ` Yann E. MORIN
  0 siblings, 1 reply; 3+ messages in thread
From: Wang YanQing @ 2012-12-17 14:38 UTC (permalink / raw)
  To: mmarek
  Cc: linux-kbuild, linux-kernel, rdunlap, bp, yann.morin.1998, sakiwit,
	lacombar, lucas.demarchi, dave, paul.gortmaker, crquan, bpoirier

This patch add support navigate input position *inside* the input
field with LEFT/RIGHT, so it is possible to modify the text in place.

Signed-off-by: Wang YanQing <udknight@gmail.com>
---
 scripts/kconfig/lxdialog/inputbox.c | 121 +++++++++++++++++++++++++++---------
 1 file changed, 92 insertions(+), 29 deletions(-)

diff --git a/scripts/kconfig/lxdialog/inputbox.c b/scripts/kconfig/lxdialog/inputbox.c
index dd8e587..21404a0 100644
--- a/scripts/kconfig/lxdialog/inputbox.c
+++ b/scripts/kconfig/lxdialog/inputbox.c
@@ -45,7 +45,8 @@ int dialog_inputbox(const char *title, const char *prompt, int height, int width
                     const char *init)
 {
 	int i, x, y, box_y, box_x, box_width;
-	int input_x = 0, scroll = 0, key = 0, button = -1;
+	int input_x = 0, key = 0, button = -1;
+	int show_x, len, pos;
 	char *instr = dialog_input_result;
 	WINDOW *dialog;
 
@@ -97,14 +98,17 @@ do_resize:
 	wmove(dialog, box_y, box_x);
 	wattrset(dialog, dlg.inputbox.atr);
 
-	input_x = strlen(instr);
+	len = strlen(instr);
+	pos = len;
 
-	if (input_x >= box_width) {
-		scroll = input_x - box_width + 1;
+	if (len >= box_width) {
+		show_x = len - box_width + 1;
 		input_x = box_width - 1;
 		for (i = 0; i < box_width - 1; i++)
-			waddch(dialog, instr[scroll + i]);
+			waddch(dialog, instr[show_x + i]);
 	} else {
+		show_x = 0;
+		input_x = len;
 		waddstr(dialog, instr);
 	}
 
@@ -121,45 +125,104 @@ do_resize:
 			case KEY_UP:
 			case KEY_DOWN:
 				break;
-			case KEY_LEFT:
-				continue;
-			case KEY_RIGHT:
-				continue;
 			case KEY_BACKSPACE:
 			case 127:
-				if (input_x || scroll) {
+				if (pos) {
 					wattrset(dialog, dlg.inputbox.atr);
-					if (!input_x) {
-						scroll = scroll < box_width - 1 ? 0 : scroll - (box_width - 1);
-						wmove(dialog, box_y, box_x);
-						for (i = 0; i < box_width; i++)
-							waddch(dialog,
-							       instr[scroll + input_x + i] ?
-							       instr[scroll + input_x + i] : ' ');
-						input_x = strlen(instr) - scroll;
+					if (input_x == 0) {
+						show_x--;
 					} else
 						input_x--;
-					instr[scroll + input_x] = '\0';
-					mvwaddch(dialog, box_y, input_x + box_x, ' ');
+
+					if (pos < len) {
+						for (i = pos - 1; i < len; i++) {
+							instr[i] = instr[i+1];
+						}
+					}
+
+					pos--;
+					len--;
+					instr[len] = '\0';
+					wmove(dialog, box_y, box_x);
+					for (i = 0; i < box_width; i++) {
+						if (!instr[show_x + i]) {
+							waddch(dialog, ' ');
+							break;
+						}
+						waddch(dialog, instr[show_x + i]);
+					}
 					wmove(dialog, box_y, input_x + box_x);
 					wrefresh(dialog);
 				}
 				continue;
+			case KEY_LEFT:
+				if (pos > 0) {
+					if (input_x > 0) {
+						wmove(dialog, box_y, --input_x + box_x);
+					} else if (input_x == 0) {
+						show_x--;
+						wmove(dialog, box_y, box_x);
+						for (i = 0; i < box_width; i++) {
+							if (!instr[show_x + i]) {
+								waddch(dialog, ' ');
+								break;
+							}
+							waddch(dialog, instr[show_x + i]);
+						}
+						wmove(dialog, box_y, box_x);
+					}
+					pos--;
+				}
+				continue;
+			case KEY_RIGHT:
+				if (pos < len) {
+					if (input_x < box_width - 1) {
+						wmove(dialog, box_y, ++input_x + box_x);
+					} else if (input_x == box_width - 1) {
+						show_x++;
+						wmove(dialog, box_y, box_x);
+						for (i = 0; i < box_width; i++) {
+							if (!instr[show_x + i]) {
+								waddch(dialog, ' ');
+								break;
+							}
+							waddch(dialog, instr[show_x + i]);
+						}
+						wmove(dialog, box_y, input_x + box_x);
+					}
+					pos++;
+				}
+				continue;
 			default:
 				if (key < 0x100 && isprint(key)) {
-					if (scroll + input_x < MAX_LEN) {
+					if (len < MAX_LEN) {
 						wattrset(dialog, dlg.inputbox.atr);
-						instr[scroll + input_x] = key;
-						instr[scroll + input_x + 1] = '\0';
+						if (pos < len) {
+							for (i = len; i > pos; i--)
+								instr[i] = instr[i-1];
+							instr[pos] = key;
+						} else {
+							instr[len] = key;
+						}
+						pos++;
+						len++;
+						instr[len] = '\0';
+
 						if (input_x == box_width - 1) {
-							scroll++;
-							wmove(dialog, box_y, box_x);
-							for (i = 0; i < box_width - 1; i++)
-								waddch(dialog, instr [scroll + i]);
+							show_x++;
 						} else {
-							wmove(dialog, box_y, input_x++ + box_x);
-							waddch(dialog, key);
+							input_x++;
+						}
+
+						wmove(dialog, box_y, box_x);
+						for (i = 0; i < box_width; i++) {
+							if (!instr[show_x + i]) {
+								waddch(dialog, ' ');
+								break;
+							}
+							waddch(dialog, instr[show_x + i]);
 						}
+						wmove(dialog, box_y, input_x + box_x);
 						wrefresh(dialog);
 					} else
 						flash();	/* Alarm user about overflow */
-- 
1.7.11.1.116.g8228a23

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] menuconfig:inputbox: support navigate input position
  2012-12-17 14:38 [PATCH] menuconfig:inputbox: support navigate input position Wang YanQing
@ 2012-12-17 18:22 ` Yann E. MORIN
  2013-01-15 22:28   ` Michal Marek
  0 siblings, 1 reply; 3+ messages in thread
From: Yann E. MORIN @ 2012-12-17 18:22 UTC (permalink / raw)
  To: Wang YanQing
  Cc: mmarek, linux-kbuild, linux-kernel, rdunlap, bp, sakiwit,
	lacombar, lucas.demarchi, dave, paul.gortmaker, crquan, bpoirier

Wang, All,

On Monday 17 December 2012 Wang YanQing wrote:
> This patch add support navigate input position *inside* the input
> field with LEFT/RIGHT, so it is possible to modify the text in place.
> 
> Signed-off-by: Wang YanQing <udknight@gmail.com>

Tested-by: "Yann E. MORIN" <yann.morin.1998@free.fr>

I am not knowledgeable enough in ncurses and the dialog code-base
to add any reviewed-by tag. All I can say, is that it works as
advertised.

Regards,
Yann E. MORIN.

-- 
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] menuconfig:inputbox: support navigate input position
  2012-12-17 18:22 ` Yann E. MORIN
@ 2013-01-15 22:28   ` Michal Marek
  0 siblings, 0 replies; 3+ messages in thread
From: Michal Marek @ 2013-01-15 22:28 UTC (permalink / raw)
  To: Yann E. MORIN
  Cc: Wang YanQing, linux-kbuild, linux-kernel, rdunlap, bp, sakiwit,
	lacombar, lucas.demarchi, dave, paul.gortmaker, crquan, bpoirier

On 17.12.2012 19:22, Yann E. MORIN wrote:
> Wang, All,
> 
> On Monday 17 December 2012 Wang YanQing wrote:
>> This patch add support navigate input position *inside* the input
>> field with LEFT/RIGHT, so it is possible to modify the text in place.
>>
>> Signed-off-by: Wang YanQing <udknight@gmail.com>
> 
> Tested-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
> 
> I am not knowledgeable enough in ncurses and the dialog code-base
> to add any reviewed-by tag. All I can say, is that it works as
> advertised.

I merged this into kbuild.git#kconfig.

Thanks,
Michal


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-01-15 22:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-17 14:38 [PATCH] menuconfig:inputbox: support navigate input position Wang YanQing
2012-12-17 18:22 ` Yann E. MORIN
2013-01-15 22:28   ` Michal Marek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox