pkgsrc/misc/dialog/patches/patch-ae

89 lines
3 KiB
Text

$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);