Implement menu & command-list on dumb terminals.
This commit is contained in:
parent
19477b0574
commit
2edd28f97b
2 changed files with 149 additions and 77 deletions
16
ChangeLog
16
ChangeLog
|
@ -1,3 +1,19 @@
|
||||||
|
2001-05-25 Klaus Reichl <Klaus.Reichl@alcatel.at>
|
||||||
|
|
||||||
|
* stage2/stage2.c (print_entries_raw): New function.
|
||||||
|
(run_menu): Use it to implement menu & command-list if on dumb
|
||||||
|
terminals.
|
||||||
|
Changes are:
|
||||||
|
Adjust FIRST_ENTRY only on non-dumb terminals.
|
||||||
|
Setting of SHOW_MENU is honoured also on dumb
|
||||||
|
terminals.
|
||||||
|
Likely if SHOW_MENU is false, ESC brings her to the
|
||||||
|
menu - not to the command-line as before.
|
||||||
|
PRINT_BORDER, GOTOXY, SET_LINE_xxx are only called if
|
||||||
|
not on dumb terminals.
|
||||||
|
Show entry number when timeout is running if terminal is dumb.
|
||||||
|
Prompt with entry number when waiting for keys.
|
||||||
|
|
||||||
2001-05-14 Pavel Roskin <proski@gnu.org>
|
2001-05-14 Pavel Roskin <proski@gnu.org>
|
||||||
|
|
||||||
* stage2/shared.h (ENTRY): Remove unnecessary `##'.
|
* stage2/shared.h (ENTRY): Remove unnecessary `##'.
|
||||||
|
|
210
stage2/stage2.c
210
stage2/stage2.c
|
@ -138,6 +138,33 @@ print_entries (int y, int size, int first, char *menu_entries)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
print_entries_raw (int size, int first, char *menu_entries)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
#define LINE_LENGTH 67
|
||||||
|
|
||||||
|
for (i = 0; i < LINE_LENGTH; i++)
|
||||||
|
grub_putchar ('-');
|
||||||
|
grub_putchar ('\n');
|
||||||
|
|
||||||
|
for (i = first; i < size; i++)
|
||||||
|
{
|
||||||
|
/* grub's printf can't %02d so ... */
|
||||||
|
if (i < 10)
|
||||||
|
grub_putchar (' ');
|
||||||
|
grub_printf ("%d: %s\n", i, get_entry (menu_entries, i, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < LINE_LENGTH; i++)
|
||||||
|
grub_putchar ('-');
|
||||||
|
grub_putchar ('\n');
|
||||||
|
|
||||||
|
#undef LINE_LENGTH
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
print_border (int y, int size)
|
print_border (int y, int size)
|
||||||
{
|
{
|
||||||
|
@ -290,20 +317,21 @@ run_menu (char *menu_entries, char *config_entries, int num_entries,
|
||||||
*/
|
*/
|
||||||
|
|
||||||
restart:
|
restart:
|
||||||
while (entryno > 11)
|
/* Dumb terminal always use all entries for display
|
||||||
|
invariant for TERMINAL_DUMB: first_entry == 0 */
|
||||||
|
if (! (terminal & TERMINAL_DUMB))
|
||||||
{
|
{
|
||||||
first_entry++;
|
while (entryno > 11)
|
||||||
entryno--;
|
{
|
||||||
|
first_entry++;
|
||||||
|
entryno--;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If the timeout was expired or wasn't set, force to show the menu
|
/* If the timeout was expired or wasn't set, force to show the menu
|
||||||
interface. If the terminal is dumb and the timeout is set, hide
|
interface. */
|
||||||
the menu to boot the default entry automatically when the timeout
|
|
||||||
is expired. */
|
|
||||||
if (grub_timeout < 0)
|
if (grub_timeout < 0)
|
||||||
show_menu = 1;
|
show_menu = 1;
|
||||||
else if (terminal & TERMINAL_DUMB)
|
|
||||||
show_menu = 0;
|
|
||||||
|
|
||||||
/* If SHOW_MENU is false, don't display the menu until ESC is pressed. */
|
/* If SHOW_MENU is false, don't display the menu until ESC is pressed. */
|
||||||
if (! show_menu)
|
if (! show_menu)
|
||||||
|
@ -337,38 +365,12 @@ restart:
|
||||||
grub_timeout--;
|
grub_timeout--;
|
||||||
|
|
||||||
/* Print a message. */
|
/* Print a message. */
|
||||||
if (terminal & TERMINAL_DUMB)
|
grub_printf ("\rPress `ESC' to enter the menu... %d ",
|
||||||
grub_printf ("\rPress `ESC' to enter the command-line... %d ",
|
grub_timeout);
|
||||||
grub_timeout);
|
|
||||||
else
|
|
||||||
grub_printf ("\rPress `ESC' to enter the menu... %d ",
|
|
||||||
grub_timeout);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If the terminal is dumb, enter the command-line interface instead. */
|
|
||||||
if (show_menu && (terminal & TERMINAL_DUMB))
|
|
||||||
{
|
|
||||||
if (! auth && password)
|
|
||||||
{
|
|
||||||
/* The user must enter a correct password. */
|
|
||||||
char entered[32];
|
|
||||||
|
|
||||||
/* Make sure that PASSWORD is NUL-terminated. */
|
|
||||||
nul_terminate (password);
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
|
||||||
grub_memset (entered, 0, sizeof (entered));
|
|
||||||
get_cmdline ("Password: ", entered, 31, '*', 0);
|
|
||||||
}
|
|
||||||
while (check_password (entered, password, password_type) != 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
enter_cmdline (heap, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Only display the menu if the user wants to see it. */
|
/* Only display the menu if the user wants to see it. */
|
||||||
if (show_menu)
|
if (show_menu)
|
||||||
{
|
{
|
||||||
|
@ -383,7 +385,8 @@ restart:
|
||||||
nocursor ();
|
nocursor ();
|
||||||
#endif /* ! GRUB_UTIL */
|
#endif /* ! GRUB_UTIL */
|
||||||
|
|
||||||
print_border (3, 12);
|
if (! (terminal & TERMINAL_DUMB))
|
||||||
|
print_border (3, 12);
|
||||||
|
|
||||||
#ifdef GRUB_UTIL
|
#ifdef GRUB_UTIL
|
||||||
/* In the grub shell, always use ACS_*. */
|
/* In the grub shell, always use ACS_*. */
|
||||||
|
@ -408,6 +411,9 @@ restart:
|
||||||
# endif /* SUPPORT_SERIAL */
|
# endif /* SUPPORT_SERIAL */
|
||||||
#endif /* ! GRUB_UTIL */
|
#endif /* ! GRUB_UTIL */
|
||||||
|
|
||||||
|
if (terminal & TERMINAL_DUMB)
|
||||||
|
print_entries_raw (num_entries, first_entry, menu_entries);
|
||||||
|
|
||||||
grub_printf ("\n\
|
grub_printf ("\n\
|
||||||
Use the %c and %c keys to select which entry is highlighted.\n",
|
Use the %c and %c keys to select which entry is highlighted.\n",
|
||||||
disp_up, disp_down);
|
disp_up, disp_down);
|
||||||
|
@ -432,10 +438,16 @@ restart:
|
||||||
selected line, or escape to go back to the main menu.");
|
selected line, or escape to go back to the main menu.");
|
||||||
}
|
}
|
||||||
|
|
||||||
print_entries (3, 12, first_entry, menu_entries);
|
if (terminal & TERMINAL_DUMB)
|
||||||
|
grub_printf ("\n\nThe selected entry is %d ", entryno);
|
||||||
/* highlight initial line */
|
else
|
||||||
set_line_highlight (4 + entryno, first_entry + entryno, menu_entries);
|
{
|
||||||
|
print_entries (3, 12, first_entry, menu_entries);
|
||||||
|
|
||||||
|
/* highlight initial line */
|
||||||
|
set_line_highlight (4 + entryno, first_entry + entryno,
|
||||||
|
menu_entries);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* XX using RT clock now, need to initialize value */
|
/* XX using RT clock now, need to initialize value */
|
||||||
|
@ -456,9 +468,17 @@ restart:
|
||||||
|
|
||||||
/* else not booting yet! */
|
/* else not booting yet! */
|
||||||
time2 = time1;
|
time2 = time1;
|
||||||
gotoxy (3, 22);
|
|
||||||
printf ("The highlighted entry will be booted automatically in %d seconds. ", grub_timeout);
|
if (terminal & TERMINAL_DUMB)
|
||||||
gotoxy (74, 4 + entryno);
|
grub_printf ("\r Entry %d will be booted automatically in %d seconds. ",
|
||||||
|
entryno, grub_timeout);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
gotoxy (3, 22);
|
||||||
|
printf ("The highlighted entry will be booted automatically in %d seconds. ", grub_timeout);
|
||||||
|
gotoxy (74, 4 + entryno);
|
||||||
|
}
|
||||||
|
|
||||||
grub_timeout--;
|
grub_timeout--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -469,52 +489,74 @@ restart:
|
||||||
in grub if interrupt driven I/O is done). */
|
in grub if interrupt driven I/O is done). */
|
||||||
if ((checkkey () != -1) || (grub_timeout == -1))
|
if ((checkkey () != -1) || (grub_timeout == -1))
|
||||||
{
|
{
|
||||||
|
/* Key was pressed, show which entry is selected before GETKEY,
|
||||||
|
since we're comming in here also on GRUB_TIMEOUT == -1 and
|
||||||
|
hang in GETKEY */
|
||||||
|
if (terminal & TERMINAL_DUMB)
|
||||||
|
grub_printf ("\r Highlighted entry is %d: ", entryno);
|
||||||
|
|
||||||
c = translate_keycode (getkey ());
|
c = translate_keycode (getkey ());
|
||||||
|
|
||||||
if (grub_timeout >= 0)
|
if (grub_timeout >= 0)
|
||||||
{
|
{
|
||||||
gotoxy (3, 22);
|
if (terminal & TERMINAL_DUMB)
|
||||||
|
grub_putchar ('\r');
|
||||||
|
else
|
||||||
|
gotoxy (3, 22);
|
||||||
printf (" ");
|
printf (" ");
|
||||||
grub_timeout = -1;
|
grub_timeout = -1;
|
||||||
fallback_entry = -1;
|
fallback_entry = -1;
|
||||||
gotoxy (74, 4 + entryno);
|
if (! (terminal & TERMINAL_DUMB))
|
||||||
|
gotoxy (74, 4 + entryno);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We told them above (at least in SUPPORT_SERIAL) to use
|
/* We told them above (at least in SUPPORT_SERIAL) to use
|
||||||
'^' or 'v' so accept these keys. */
|
'^' or 'v' so accept these keys. */
|
||||||
if (c == 16 || c == '^')
|
if (c == 16 || c == '^')
|
||||||
{
|
{
|
||||||
if (entryno > 0)
|
if (terminal & TERMINAL_DUMB)
|
||||||
{
|
{
|
||||||
set_line_normal (4 + entryno, first_entry + entryno,
|
if (entryno > 0)
|
||||||
menu_entries);
|
entryno--;
|
||||||
entryno--;
|
|
||||||
set_line_highlight (4 + entryno, first_entry + entryno,
|
|
||||||
menu_entries);
|
|
||||||
}
|
}
|
||||||
else if (first_entry > 0)
|
else
|
||||||
{
|
{
|
||||||
first_entry--;
|
if (entryno > 0)
|
||||||
print_entries (3, 12, first_entry, menu_entries);
|
{
|
||||||
set_line_highlight (4, first_entry + entryno, menu_entries);
|
set_line_normal (4 + entryno, first_entry + entryno,
|
||||||
|
menu_entries);
|
||||||
|
entryno--;
|
||||||
|
set_line_highlight (4 + entryno, first_entry + entryno,
|
||||||
|
menu_entries);
|
||||||
|
}
|
||||||
|
else if (first_entry > 0)
|
||||||
|
{
|
||||||
|
first_entry--;
|
||||||
|
print_entries (3, 12, first_entry, menu_entries);
|
||||||
|
set_line_highlight (4, first_entry + entryno,
|
||||||
|
menu_entries);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((c == 14 || c == 'v') && first_entry + entryno + 1 < num_entries)
|
if ((c == 14 || c == 'v') && first_entry + entryno + 1 < num_entries)
|
||||||
{
|
{
|
||||||
if (entryno < 11)
|
if (terminal & TERMINAL_DUMB)
|
||||||
{
|
entryno++;
|
||||||
set_line_normal (4 + entryno, first_entry + entryno,
|
else
|
||||||
menu_entries);
|
if (entryno < 11)
|
||||||
entryno++;
|
{
|
||||||
set_line_highlight (4 + entryno, first_entry + entryno,
|
set_line_normal (4 + entryno, first_entry + entryno,
|
||||||
menu_entries);
|
menu_entries);
|
||||||
}
|
entryno++;
|
||||||
else if (num_entries > 12 + first_entry)
|
set_line_highlight (4 + entryno, first_entry + entryno,
|
||||||
{
|
menu_entries);
|
||||||
first_entry++;
|
}
|
||||||
print_entries (3, 12, first_entry, menu_entries);
|
else if (num_entries > 12 + first_entry)
|
||||||
set_line_highlight (15, first_entry + entryno, menu_entries);
|
{
|
||||||
}
|
first_entry++;
|
||||||
|
print_entries (3, 12, first_entry, menu_entries);
|
||||||
|
set_line_highlight (15, first_entry + entryno, menu_entries);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config_entries)
|
if (config_entries)
|
||||||
|
@ -526,15 +568,16 @@ restart:
|
||||||
{
|
{
|
||||||
if ((c == 'd') || (c == 'o') || (c == 'O'))
|
if ((c == 'd') || (c == 'o') || (c == 'O'))
|
||||||
{
|
{
|
||||||
set_line_normal (4 + entryno, first_entry + entryno,
|
if (! (terminal & TERMINAL_DUMB))
|
||||||
menu_entries);
|
set_line_normal (4 + entryno, first_entry + entryno,
|
||||||
|
menu_entries);
|
||||||
|
|
||||||
/* insert after is almost exactly like insert before */
|
/* insert after is almost exactly like insert before */
|
||||||
if (c == 'o')
|
if (c == 'o')
|
||||||
{
|
{
|
||||||
/* But `o' differs from `O', since it may causes
|
/* But `o' differs from `O', since it may causes
|
||||||
the menu screen to scroll up. */
|
the menu screen to scroll up. */
|
||||||
if (entryno < 11)
|
if (entryno < 11 || (terminal & TERMINAL_DUMB))
|
||||||
entryno++;
|
entryno++;
|
||||||
else
|
else
|
||||||
first_entry++;
|
first_entry++;
|
||||||
|
@ -575,9 +618,19 @@ restart:
|
||||||
first_entry--;
|
first_entry--;
|
||||||
}
|
}
|
||||||
|
|
||||||
print_entries (3, 12, first_entry, menu_entries);
|
if (terminal & TERMINAL_DUMB)
|
||||||
set_line_highlight (4 + entryno, first_entry + entryno,
|
{
|
||||||
menu_entries);
|
grub_printf ("\n\n");
|
||||||
|
print_entries_raw (num_entries, first_entry,
|
||||||
|
menu_entries);
|
||||||
|
grub_printf ("\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
print_entries (3, 12, first_entry, menu_entries);
|
||||||
|
set_line_highlight (4 + entryno, first_entry + entryno,
|
||||||
|
menu_entries);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cur_entry = menu_entries;
|
cur_entry = menu_entries;
|
||||||
|
@ -595,7 +648,10 @@ restart:
|
||||||
char entered[32];
|
char entered[32];
|
||||||
char *pptr = password;
|
char *pptr = password;
|
||||||
|
|
||||||
gotoxy (1, 21);
|
if (terminal & TERMINAL_DUMB)
|
||||||
|
grub_printf ("\r ");
|
||||||
|
else
|
||||||
|
gotoxy (1, 21);
|
||||||
|
|
||||||
/* Wipe out the previously entered password */
|
/* Wipe out the previously entered password */
|
||||||
memset (entered, 0, sizeof (entered));
|
memset (entered, 0, sizeof (entered));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue