readline: move backspace key handling to the DO_BACKSPACE macro
Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
parent
72703410fe
commit
db494137a8
|
@ -137,6 +137,18 @@ static char* hist_next(void)
|
|||
} \
|
||||
}
|
||||
|
||||
#define DO_BACKSPACE() \
|
||||
wlen = eol_num - num; \
|
||||
num--; \
|
||||
memmove(buf + num, buf + num + 1, wlen); \
|
||||
getcmd_putch(CTL_BACKSPACE); \
|
||||
putnstr(buf + num, wlen); \
|
||||
getcmd_putch(' '); \
|
||||
do { \
|
||||
getcmd_putch(CTL_BACKSPACE); \
|
||||
} while (wlen--); \
|
||||
eol_num--;
|
||||
|
||||
static void cread_add_char(char ichar, int insert, unsigned long *num,
|
||||
unsigned long *eol_num, char *buf, unsigned long len)
|
||||
{
|
||||
|
@ -273,16 +285,7 @@ int readline(const char *prompt, char *buf, int len)
|
|||
case KEY_DEL7:
|
||||
case 8:
|
||||
if (num) {
|
||||
wlen = eol_num - num;
|
||||
num--;
|
||||
memmove(buf + num, buf + num + 1, wlen);
|
||||
getcmd_putch(CTL_BACKSPACE);
|
||||
putnstr(buf + num, wlen);
|
||||
getcmd_putch(' ');
|
||||
do {
|
||||
getcmd_putch(CTL_BACKSPACE);
|
||||
} while (wlen--);
|
||||
eol_num--;
|
||||
DO_BACKSPACE();
|
||||
}
|
||||
break;
|
||||
case KEY_DEL:
|
||||
|
|
Loading…
Reference in New Issue