fix some bugs in the command-line.

This commit is contained in:
okuji 1999-09-17 11:49:43 +00:00
parent dfe653fc49
commit d6279335bb
4 changed files with 202 additions and 171 deletions

View file

@ -1,3 +1,14 @@
1999-09-17 OKUJI Yoshinori <okuji@kuicr.kyoto-u.ac.jp>
* stage2/char_io.c [!STAGE1_5] (get_cmdline): The argument
COMPLETION is renamed to READLINE.
Do not initialize KILL here.
TAB, C-a, C-e, C-f, C-b, C-u, C-k, C-y, C-p and C-n are handled
only if READLINE is non-zero.
If ECHO_CHAR is not NUL, do not remove the leading spaces in BUF.
Add CMDLINE into the history list only if READLINE is non-zero.
* stage2/stage2.c (cmain): Initialize the kill buffer.
1999-09-17 OKUJI Yoshinori <okuji@kuicr.kyoto-u.ac.jp>
Killing, yanking and manipulating the history are supported.

View file

@ -220,7 +220,7 @@ add_history (const char *cmdline, int no)
If ECHO_CHAR is nonzero, echo it instead of the typed character. */
int
get_cmdline (char *prompt, char *cmdline, int maxlen,
int echo_char, int completion)
int echo_char, int readline)
{
int ystart, yend, xend, lpos, c;
/* The length of PROMPT. */
@ -331,7 +331,6 @@ get_cmdline (char *prompt, char *cmdline, int maxlen,
}
lpos = llen;
grub_strcpy (buf, cmdline);
*kill = 0;
cl_init ();
@ -367,12 +366,12 @@ get_cmdline (char *prompt, char *cmdline, int maxlen,
c = ASCII_CHAR (c);
/* If READLINE is non-zero, handle readline-like key bindings. */
if (readline)
{
switch (c)
{
case 27: /* ESC immediately return 1 */
return 1;
case 9: /* TAB lists completions */
if (completion)
{
int i, j = 0, llen_old = llen;
@ -450,33 +449,6 @@ get_cmdline (char *prompt, char *cmdline, int maxlen,
cl_setcpos ();
}
break;
case 4: /* C-d delete character under cursor */
if (lpos == llen)
break;
lpos++;
/* fallthrough is on purpose! */
case 8: /* C-h backspace */
#ifdef GRUB_UTIL
case 127: /* also backspace */
#endif
if (lpos > 0)
{
int i;
grub_memmove (buf + lpos - 1, buf + lpos, llen - lpos + 1);
i = lpos;
lpos = llen - 1;
cl_setcpos ();
putchar (' ');
lpos = i - 1; /* restore lpos and decrement */
llen--;
cl_setcpos ();
if (lpos != llen)
{
cl_print (buf + lpos, echo_char);
cl_setcpos ();
}
}
break;
case 21: /* C-u kill to beginning of line */
if (lpos == 0)
break;
@ -558,6 +530,43 @@ get_cmdline (char *prompt, char *cmdline, int maxlen,
cl_setcpos ();
}
break;
}
}
/* ESC, C-d and C-h are always handled. Actually C-d is not
functional if READLINE is zero, as the cursor cannot go
backward, but that's ok. */
switch (c)
{
case 27: /* ESC immediately return 1 */
return 1;
case 4: /* C-d delete character under cursor */
if (lpos == llen)
break;
lpos++;
/* fallthrough is on purpose! */
case 8: /* C-h backspace */
#ifdef GRUB_UTIL
case 127: /* also backspace */
#endif
if (lpos > 0)
{
int i;
grub_memmove (buf + lpos - 1, buf + lpos, llen - lpos + 1);
i = lpos;
lpos = llen - 1;
cl_setcpos ();
putchar (' ');
lpos = i - 1; /* restore lpos and decrement */
llen--;
cl_setcpos ();
if (lpos != llen)
{
cl_print (buf + lpos, echo_char);
cl_setcpos ();
}
}
break;
default: /* insert printable character into line */
if (c >= ' ' && c <= '~')
{
@ -575,11 +584,18 @@ get_cmdline (char *prompt, char *cmdline, int maxlen,
putchar ('\n');
gotoxy (0, getxy () & 0xff);
/* remove leading spaces */
for (lpos = 0; buf[lpos] == ' '; lpos++);
/* If ECHO_CHAR is NUL, remove the leading spaces. */
lpos = 0;
if (! echo_char)
while (buf[lpos] == ' ')
lpos++;
/* Copy the working buffer to CMDLINE. */
grub_memmove (cmdline, buf + lpos, llen - lpos + 1);
if (lpos < llen)
/* If the readline-like feature is turned on and CMDLINE is not
empty, add it into the history list. */
if (readline && lpos < llen)
add_history (cmdline, 0);
return 0;

View file

@ -614,7 +614,7 @@ void init_page (void);
void print_error (void);
char *convert_to_ascii (char *buf, int c, ...);
int get_cmdline (char *prompt, char *cmdline, int maxlen,
int echo_char, int completion);
int echo_char, int history);
int substring (char *s1, char *s2);
int get_based_digit (int c, int base);
int safe_parse_maxint (char **str_ptr, int *myint_ptr);

View file

@ -572,6 +572,10 @@ cmain (void)
{
int config_len, menu_len, num_entries;
char *config_entries, *menu_entries;
char *kill = (char *) KILL_BUF;
/* Initialize the kill buffer. */
*kill = 0;
/* Never return. */
for (;;)