Add new parameter to line_edit: field length (-1 means unlimited)

This commit is contained in:
Andrey A. Chernov 1994-11-18 01:02:42 +00:00
parent cb19812e97
commit a9e8a652cb
4 changed files with 13 additions and 15 deletions

View File

@ -79,7 +79,7 @@ extern bool use_shadow;
void draw_shadow(WINDOW *win, int y, int x, int height, int width);
#endif
void draw_box(WINDOW *win, int y, int x, int height, int width, chtype box, chtype border);
int line_edit(WINDOW* dialog, int box_y, int box_x, int box_width, chtype attrs, int first, unsigned char *result);
int line_edit(WINDOW* dialog, int box_y, int box_x, int flen, int box_width, chtype attrs, int first, unsigned char *result);
int strheight(const char *p);
int strwidth(const char *p);

View File

@ -97,7 +97,7 @@ int dialog_inputbox(unsigned char *title, unsigned char *prompt, int height, int
while (key != ESC) {
if (button == -1) { /* Input box selected */
key = line_edit(dialog, box_y, box_x, box_width, inputbox_attr, first, instr);
key = line_edit(dialog, box_y, box_x, -1, box_width, inputbox_attr, first, instr);
first = 0;
}
else

View File

@ -26,7 +26,7 @@
/*
* Line editor
*/
int line_edit(WINDOW* dialog, int box_y, int box_x, int box_width, chtype attr, int first, unsigned char *result)
int line_edit(WINDOW* dialog, int box_y, int box_x, int flen, int box_width, chtype attr, int first, unsigned char *result)
{
int i, key;
chtype old_attr;
@ -54,8 +54,8 @@ int line_edit(WINDOW* dialog, int box_y, int box_x, int box_width, chtype attr,
}
wmove(dialog, box_y, box_x + input_x);
wrefresh(dialog);
for (;;) {
wrefresh(dialog);
key = wgetch(dialog);
switch (key) {
case TAB:
@ -79,7 +79,6 @@ int line_edit(WINDOW* dialog, int box_y, int box_x, int box_width, chtype attr,
for (i = 0; i < box_width; i++)
waddch(dialog, instr[i] ? instr[i] : ' ');
wmove(dialog, box_y, box_x);
wrefresh(dialog);
continue;
case KEY_END:
for (i = strlen(instr) - 1; i >= scroll + input_x && instr[i] == ' '; i--)
@ -91,7 +90,6 @@ int line_edit(WINDOW* dialog, int box_y, int box_x, int box_width, chtype attr,
for (i = 0; i < box_width; i++)
waddch(dialog, instr[scroll+i] ? instr[scroll+i] : ' ');
wmove(dialog, box_y, input_x + box_x);
wrefresh(dialog);
continue;
case KEY_LEFT:
if (input_x || scroll) {
@ -106,11 +104,12 @@ int line_edit(WINDOW* dialog, int box_y, int box_x, int box_width, chtype attr,
else
input_x--;
wmove(dialog, box_y, input_x + box_x);
wrefresh(dialog);
}
continue;
case KEY_RIGHT:
if (scroll+input_x < MAX_LEN) {
if ( scroll+input_x < MAX_LEN
&& (flen < 0 || scroll+input_x < flen)
) {
if (!instr[scroll+input_x])
instr[scroll+input_x] = ' ';
if (input_x == box_width-1) {
@ -125,9 +124,8 @@ int line_edit(WINDOW* dialog, int box_y, int box_x, int box_width, chtype attr,
waddch(dialog, instr[scroll+input_x]);
input_x++;
}
wrefresh(dialog);
} else
flash(); /* Alarm user about overflow */
beep(); /* Alarm user about overflow */
continue;
case '\b':
case '\177':
@ -151,7 +149,6 @@ int line_edit(WINDOW* dialog, int box_y, int box_x, int box_width, chtype attr,
for (i = input_x; i < box_width; i++)
waddch(dialog, instr[scroll+i] ? instr[scroll+i] : ' ');
wmove(dialog, box_y, input_x + box_x);
wrefresh(dialog);
}
continue;
default:
@ -163,7 +160,9 @@ int line_edit(WINDOW* dialog, int box_y, int box_x, int box_width, chtype attr,
for (i = strlen(instr) - 1; i >= scroll + input_x && instr[i] == ' '; i--)
instr[i] = '\0';
i++;
if (i < MAX_LEN) {
if ( i < MAX_LEN
&& (flen < 0 || i < flen)
) {
memmove(instr+scroll+input_x+1, instr+scroll+input_x, i-scroll+input_x);
instr[scroll+input_x] = key;
if (input_x == box_width-1) {
@ -178,9 +177,8 @@ int line_edit(WINDOW* dialog, int box_y, int box_x, int box_width, chtype attr,
waddch(dialog, instr[scroll+i] ? instr[scroll+i] : ' ');
wmove(dialog, box_y, ++input_x + box_x);
}
wrefresh(dialog);
} else
flash(); /* Alarm user about overflow */
beep(); /* Alarm user about overflow */
continue;
}
}

View File

@ -653,7 +653,7 @@ static int get_search_term(WINDOW *win, unsigned char *search_term, int height,
first = 1;
while (key != ESC) {
key = line_edit(win, y+1, x+1, box_width, searchbox_attr, first, search_term);
key = line_edit(win, y+1, x+1, -1, box_width, searchbox_attr, first, search_term);
first = 0;
switch (key) {
case '\n':