summaryrefslogtreecommitdiff
path: root/misc/dialog/patches/patch-ae
blob: 19a8f8ab9a899a52e84b53fcfcede1f37411a9cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
$NetBSD: patch-ae,v 1.3 2000/07/28 20:30:11 jlam Exp $

--- inputbox.c.orig	Fri Aug 18 07:39:51 1995
+++ inputbox.c	Fri Jul 28 15:30:22 2000
@@ -29,11 +29,21 @@
 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 i, j, x, y, box_y, box_x, box_width;
+    int input_x = 0, d_scroll = 0, key = 0, button = -1;
     unsigned char *instr = dialog_input_result;
     WINDOW *dialog;
 
+    /* Choose useful default height and width if they are negative */
+    if (height < 0)
+        height = strheight(prompt) + 4 + 2;
+    if (width < 0) {
+        i = strwidth(prompt);
+        j = ((title != NULL) ? strwidth(title) : 0);
+        width = MAX (i, j) + 4;
+    }
+    width = MAX (width, MIN_DIALOG_WIDTH);
+
     /* center dialog box on screen */
     x = (COLS - width) / 2;
     y = (LINES - height) / 2;
@@ -91,10 +101,10 @@
 	strcpy (instr, init);
     input_x = strlen (instr);
     if (input_x >= box_width) {
-	scroll = input_x - box_width + 1;
+	d_scroll = input_x - box_width + 1;
 	input_x = box_width - 1;
 	for (i = 0; i < box_width - 1; i++)
-	    waddch (dialog, instr[scroll + i]);
+	    waddch (dialog, instr[d_scroll + i]);
     } else
 	waddstr (dialog, instr);
     wmove (dialog, box_y, box_x + input_x);
@@ -118,19 +128,19 @@
 		continue;
 	    case KEY_BACKSPACE:
 	    case 127:
-		if (input_x || scroll) {
+		if (input_x || d_scroll) {
 		    wattrset (dialog, inputbox_attr);
 		    if (!input_x) {
-			scroll = scroll < box_width - 1 ?
-			    0 : scroll - (box_width - 1);
+			d_scroll = d_scroll < box_width - 1 ?
+			    0 : d_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;
+			    waddch (dialog, instr[d_scroll + input_x + i] ?
+				    instr[d_scroll + input_x + i] : ' ');
+			input_x = strlen (instr) - d_scroll;
 		    } else
 			input_x--;
-		    instr[scroll + input_x] = '\0';
+		    instr[d_scroll + input_x] = '\0';
 		    wmove (dialog, box_y, input_x + box_x);
 		    waddch (dialog, ' ');
 		    wmove (dialog, box_y, input_x + box_x);
@@ -139,15 +149,15 @@
 		continue;
 	    default:
 		if (key < 0x100 && isprint (key)) {
-		    if (scroll + input_x < MAX_LEN) {
+		    if (d_scroll + input_x < MAX_LEN) {
 			wattrset (dialog, inputbox_attr);
-			instr[scroll + input_x] = key;
-			instr[scroll + input_x + 1] = '\0';
+			instr[d_scroll + input_x] = key;
+			instr[d_scroll + input_x + 1] = '\0';
 			if (input_x == box_width - 1) {
-			    scroll++;
+			    d_scroll++;
 			    wmove (dialog, box_y, box_x);
 			    for (i = 0; i < box_width - 1; i++)
-				waddch (dialog, instr[scroll + i]);
+				waddch (dialog, instr[d_scroll + i]);
 			} else {
 			    wmove (dialog, box_y, input_x++ + box_x);
 			    waddch (dialog, key);