in graphics/pdcurs34/pdcurses/pdc_getstr.c [374:546]
int wgetn_wstr(WINDOW *win, wint_t *wstr, int n)
{
int ch;
int i;
int num;
int x;
int chars;
char *p;
bool stop;
bool oldecho;
bool oldcbreak;
bool oldnodelay;
#ifdef CONFIG_PDCURSES_MULTITHREAD
FAR struct pdc_context_s *ctx = PDC_ctx();
#endif
PDC_LOG(("wgetn_wstr() - called\n"));
if (!win || !wstr)
{
return ERR;
}
chars = 0;
p = wstr;
stop = false;
x = win->_curx;
oldcbreak = SP->cbreak; /* remember states */
oldecho = SP->echo;
oldnodelay = win->_nodelay;
SP->echo = false; /* we do echo ourselves */
cbreak(); /* ensure each key is returned immediately */
win->_nodelay = false; /* don't return -1 */
wrefresh(win);
while (!stop)
{
ch = wgetch(win);
switch (ch)
{
case '\t':
ch = ' ';
num = TABSIZE - (win->_curx - x) % TABSIZE;
for (i = 0; i < num; i++)
{
if (chars < n)
{
if (oldecho)
{
waddch(win, ch);
}
*p++ = ch;
++chars;
}
else
{
beep();
}
}
break;
case _ECHAR: /* CTRL-H -- Delete character */
if (p > wstr)
{
if (oldecho)
{
waddstr(win, "\b \b");
}
ch = *--p;
if ((ch < ' ') && (oldecho))
{
waddstr(win, "\b \b");
}
chars--;
}
break;
case _DLCHAR: /* CTRL-U -- Delete line */
while (p > wstr)
{
if (oldecho)
{
waddstr(win, "\b \b");
}
ch = *--p;
if ((ch < ' ') && (oldecho))
{
waddstr(win, "\b \b");
}
}
chars = 0;
break;
case _DWCHAR: /* CTRL-W -- Delete word */
while ((p > wstr) && (*(p - 1) == ' '))
{
if (oldecho)
{
waddstr(win, "\b \b");
}
--p; /* remove space */
chars--;
}
while ((p > wstr) && (*(p - 1) != ' '))
{
if (oldecho)
{
waddstr(win, "\b \b");
}
ch = *--p;
if ((ch < ' ') && (oldecho))
{
waddstr(win, "\b \b");
}
chars--;
}
break;
case '\n':
case '\r':
stop = true;
if (oldecho)
{
waddch(win, '\n');
}
break;
default:
if (chars < n)
{
if (!SP->key_code)
{
*p++ = ch;
if (oldecho)
{
waddch(win, ch);
}
chars++;
}
}
else
{
beep();
}
break;
}
wrefresh(win);
}
*p = '\0';
SP->echo = oldecho; /* restore old settings */
SP->cbreak = oldcbreak;
win->_nodelay = oldnodelay;
return OK;
}