3 * Text input on a line of the screen.
7 static const char rcsid[] = "$Id: edline.c,v 1.2 2002/11/04 12:27:35 chris Exp $";
15 static int min(const int a, const int b) {
20 * Display on line linenum of the screen the prompt and allow the user to input
21 * a line of text, whose initial value is as supplied. */
22 char *edline(int linenum, const char *prompt, const char *initial) {
23 int xstart, slen, off = 0, pos, i, c;
26 xstart = strlen(prompt) + 2;
29 str = xmalloc(slen = strlen(initial) * 2 + 1);
32 str = xmalloc(slen = 256);
57 if (pos > strlen(str)) {
74 if (pos == strlen(str))
77 memmove(str + pos, str + pos + 1, strlen(str + pos + 1) + 1);
84 memmove(str + pos - 1, str + pos, strlen(str + pos) + 1);
90 for (i = pos; i > 0; --i)
91 if (!isspace((int)str[i])) break;
93 if (isspace((int)str[i])) break;
95 memmove(str + i, str + pos, strlen(str + pos) + 1);
104 if (isprint(c) && c != '\t') {
105 if (strlen(str) == slen - 1)
106 str = xrealloc(str, slen *= 2);
107 memmove(str + pos + 1, str + pos, strlen(str + pos) + 1);
108 str[pos++] = (char)c;
114 /* figure out the offset to use for the string */
116 if (pos > COLS - xstart - 1)
117 off = pos - (COLS - xstart - 1);
119 /* display the string */
120 mvaddstr(linenum, 0, prompt);
122 addnstr(str + off, min(strlen(str + off), COLS - xstart - 1));
124 move(linenum, xstart + pos - off);
126 } while (c != KEY_ENTER && c != '\r' && c != '\x1b' && c != 7 /* ^G */);
128 if (c == KEY_ENTER || c == '\r')