2009-02-13 20:06:27 +00:00
|
|
|
/* menu_text.c - Basic text menu implementation. */
|
|
|
|
/*
|
|
|
|
* GRUB -- GRand Unified Bootloader
|
|
|
|
* Copyright (C) 2003,2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc.
|
|
|
|
*
|
|
|
|
* GRUB is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* GRUB is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <grub/normal.h>
|
|
|
|
#include <grub/term.h>
|
|
|
|
#include <grub/misc.h>
|
|
|
|
#include <grub/loader.h>
|
|
|
|
#include <grub/mm.h>
|
|
|
|
#include <grub/time.h>
|
|
|
|
#include <grub/env.h>
|
|
|
|
#include <grub/menu_viewer.h>
|
2009-11-22 11:49:54 +00:00
|
|
|
#include <grub/i18n.h>
|
2009-12-24 14:34:33 +00:00
|
|
|
#include <grub/charset.h>
|
2009-02-13 20:06:27 +00:00
|
|
|
|
|
|
|
static grub_uint8_t grub_color_menu_normal;
|
|
|
|
static grub_uint8_t grub_color_menu_highlight;
|
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
struct menu_viewer_data
|
2009-02-13 20:06:27 +00:00
|
|
|
{
|
2009-12-24 14:34:33 +00:00
|
|
|
int first, offset;
|
|
|
|
grub_menu_t menu;
|
|
|
|
struct grub_term_output *term;
|
|
|
|
};
|
2009-02-13 20:06:27 +00:00
|
|
|
|
2009-12-05 11:25:07 +00:00
|
|
|
static void
|
2009-12-24 14:34:33 +00:00
|
|
|
print_spaces (int number_spaces, struct grub_term_output *term)
|
2009-12-05 11:25:07 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < number_spaces; i++)
|
2009-12-24 14:34:33 +00:00
|
|
|
grub_putcode (' ', term);
|
2009-12-05 11:25:07 +00:00
|
|
|
}
|
|
|
|
|
2009-12-19 23:00:30 +00:00
|
|
|
void
|
2009-12-05 11:25:07 +00:00
|
|
|
grub_print_ucs4 (const grub_uint32_t * str,
|
2009-12-24 14:34:33 +00:00
|
|
|
const grub_uint32_t * last_position,
|
|
|
|
struct grub_term_output *term)
|
2009-12-05 11:25:07 +00:00
|
|
|
{
|
|
|
|
while (str < last_position)
|
|
|
|
{
|
2009-12-24 14:34:33 +00:00
|
|
|
grub_putcode (*str, term);
|
2009-12-05 11:25:07 +00:00
|
|
|
str++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-19 23:00:30 +00:00
|
|
|
grub_ssize_t
|
2009-12-24 14:34:33 +00:00
|
|
|
grub_getstringwidth (grub_uint32_t * str, const grub_uint32_t * last_position,
|
|
|
|
struct grub_term_output *term)
|
2009-12-05 11:25:07 +00:00
|
|
|
{
|
|
|
|
grub_ssize_t width = 0;
|
|
|
|
|
|
|
|
while (str < last_position)
|
|
|
|
{
|
2009-12-24 14:34:33 +00:00
|
|
|
width += grub_term_getcharwidth (term, *str);
|
2009-12-05 11:25:07 +00:00
|
|
|
str++;
|
|
|
|
}
|
|
|
|
return width;
|
|
|
|
}
|
|
|
|
|
2009-12-20 23:32:15 +00:00
|
|
|
void
|
2009-12-24 14:34:33 +00:00
|
|
|
grub_print_message_indented (const char *msg, int margin_left, int margin_right,
|
|
|
|
struct grub_term_output *term)
|
2009-12-05 11:25:07 +00:00
|
|
|
{
|
2009-12-19 00:05:41 +00:00
|
|
|
int line_len;
|
2009-12-05 11:25:07 +00:00
|
|
|
|
|
|
|
grub_uint32_t *unicode_msg;
|
2009-12-19 23:00:30 +00:00
|
|
|
grub_uint32_t *last_position;
|
2009-12-05 11:25:07 +00:00
|
|
|
|
2009-12-19 23:00:30 +00:00
|
|
|
int msg_len;
|
2009-12-05 11:25:07 +00:00
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
line_len = grub_term_width (term) - grub_term_getcharwidth (term, 'm') *
|
|
|
|
(margin_left + margin_right);
|
|
|
|
|
2009-12-19 23:00:30 +00:00
|
|
|
msg_len = grub_utf8_to_ucs4_alloc (msg, &unicode_msg, &last_position);
|
2009-12-05 11:25:07 +00:00
|
|
|
|
|
|
|
if (msg_len < 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
grub_uint32_t *current_position = unicode_msg;
|
|
|
|
|
|
|
|
grub_uint32_t *next_new_line = unicode_msg;
|
|
|
|
|
2009-12-19 00:05:41 +00:00
|
|
|
int first_loop = 1;
|
|
|
|
|
2009-12-05 11:25:07 +00:00
|
|
|
while (current_position < last_position)
|
|
|
|
{
|
2009-12-19 00:05:41 +00:00
|
|
|
if (! first_loop)
|
2009-12-24 14:34:33 +00:00
|
|
|
grub_putcode ('\n', term);
|
2009-12-23 16:41:32 +00:00
|
|
|
|
2009-12-05 11:25:07 +00:00
|
|
|
next_new_line = (grub_uint32_t *) last_position;
|
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
while (grub_getstringwidth (current_position, next_new_line,term)
|
|
|
|
> line_len
|
2009-12-05 11:25:07 +00:00
|
|
|
|| (*next_new_line != ' ' && next_new_line > current_position &&
|
|
|
|
next_new_line != last_position))
|
|
|
|
{
|
|
|
|
next_new_line--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (next_new_line == current_position)
|
|
|
|
{
|
|
|
|
next_new_line = (next_new_line + line_len > last_position) ?
|
|
|
|
(grub_uint32_t *) last_position : next_new_line + line_len;
|
|
|
|
}
|
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
print_spaces (margin_left, term);
|
|
|
|
grub_print_ucs4 (current_position, next_new_line, term);
|
2009-12-05 11:25:07 +00:00
|
|
|
|
|
|
|
next_new_line++;
|
|
|
|
current_position = next_new_line;
|
2009-12-19 00:05:41 +00:00
|
|
|
first_loop = 0;
|
2009-12-05 11:25:07 +00:00
|
|
|
}
|
|
|
|
grub_free (unicode_msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-13 20:06:27 +00:00
|
|
|
static void
|
2009-12-24 14:34:33 +00:00
|
|
|
draw_border (struct grub_term_output *term)
|
2009-02-13 20:06:27 +00:00
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
grub_term_setcolorstate (term, GRUB_TERM_COLOR_NORMAL);
|
2009-02-13 20:06:27 +00:00
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
grub_term_gotoxy (term, GRUB_TERM_MARGIN, GRUB_TERM_TOP_BORDER_Y);
|
|
|
|
grub_putcode (GRUB_TERM_DISP_UL, term);
|
|
|
|
for (i = 0; i < (unsigned) grub_term_border_width (term) - 2; i++)
|
|
|
|
grub_putcode (GRUB_TERM_DISP_HLINE, term);
|
|
|
|
grub_putcode (GRUB_TERM_DISP_UR, term);
|
2009-02-13 20:06:27 +00:00
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
for (i = 0; i < (unsigned) grub_term_num_entries (term); i++)
|
2009-02-13 20:06:27 +00:00
|
|
|
{
|
2009-12-24 14:34:33 +00:00
|
|
|
grub_term_gotoxy (term, GRUB_TERM_MARGIN, GRUB_TERM_TOP_BORDER_Y + i + 1);
|
|
|
|
grub_putcode (GRUB_TERM_DISP_VLINE, term);
|
|
|
|
grub_term_gotoxy (term, GRUB_TERM_MARGIN + grub_term_border_width (term)
|
|
|
|
- 1,
|
|
|
|
GRUB_TERM_TOP_BORDER_Y + i + 1);
|
|
|
|
grub_putcode (GRUB_TERM_DISP_VLINE, term);
|
2009-02-13 20:06:27 +00:00
|
|
|
}
|
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
grub_term_gotoxy (term, GRUB_TERM_MARGIN,
|
|
|
|
GRUB_TERM_TOP_BORDER_Y + grub_term_num_entries (term) + 1);
|
|
|
|
grub_putcode (GRUB_TERM_DISP_LL, term);
|
|
|
|
for (i = 0; i < (unsigned) grub_term_border_width (term) - 2; i++)
|
|
|
|
grub_putcode (GRUB_TERM_DISP_HLINE, term);
|
|
|
|
grub_putcode (GRUB_TERM_DISP_LR, term);
|
2009-02-13 20:06:27 +00:00
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
grub_term_setcolorstate (term, GRUB_TERM_COLOR_NORMAL);
|
2009-02-13 20:06:27 +00:00
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
grub_term_gotoxy (term, GRUB_TERM_MARGIN,
|
|
|
|
(GRUB_TERM_TOP_BORDER_Y + grub_term_num_entries (term)
|
|
|
|
+ GRUB_TERM_MARGIN + 1));
|
2009-02-13 20:06:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-12-24 14:34:33 +00:00
|
|
|
print_message (int nested, int edit, struct grub_term_output *term)
|
2009-02-13 20:06:27 +00:00
|
|
|
{
|
2009-12-24 14:34:33 +00:00
|
|
|
grub_term_setcolorstate (term, GRUB_TERM_COLOR_NORMAL);
|
2009-02-13 20:06:27 +00:00
|
|
|
|
|
|
|
if (edit)
|
|
|
|
{
|
2009-12-24 14:34:33 +00:00
|
|
|
grub_putcode ('\n', term);
|
2009-12-20 23:32:15 +00:00
|
|
|
grub_print_message_indented (_("Minimum Emacs-like screen editing is \
|
2009-12-05 11:25:07 +00:00
|
|
|
supported. TAB lists completions. Press Ctrl-x to boot, Ctrl-c for a \
|
2009-12-24 14:34:33 +00:00
|
|
|
command-line or ESC to return menu."), STANDARD_MARGIN, STANDARD_MARGIN,
|
|
|
|
term);
|
2009-02-13 20:06:27 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-12-05 11:25:07 +00:00
|
|
|
const char *msg = _("Use the %C and %C keys to select which \
|
2009-12-19 00:05:41 +00:00
|
|
|
entry is highlighted.\n");
|
2009-12-05 11:25:07 +00:00
|
|
|
char *msg_translated =
|
|
|
|
grub_malloc (sizeof (char) * grub_strlen (msg) + 1);
|
|
|
|
|
|
|
|
grub_sprintf (msg_translated, msg, (grub_uint32_t) GRUB_TERM_DISP_UP,
|
|
|
|
(grub_uint32_t) GRUB_TERM_DISP_DOWN);
|
|
|
|
grub_putchar ('\n');
|
2009-12-24 14:34:33 +00:00
|
|
|
grub_print_message_indented (msg_translated, STANDARD_MARGIN,
|
|
|
|
STANDARD_MARGIN, term);
|
2009-12-05 11:25:07 +00:00
|
|
|
|
|
|
|
grub_free (msg_translated);
|
|
|
|
|
2009-02-13 20:06:27 +00:00
|
|
|
if (nested)
|
2009-12-25 15:53:54 +00:00
|
|
|
{
|
|
|
|
grub_print_message_indented
|
|
|
|
(_("Press enter to boot the selected OS, "
|
|
|
|
"\'e\' to edit the commands before booting "
|
|
|
|
"or \'c\' for a command-line. ESC to return previous menu.\n"),
|
|
|
|
STANDARD_MARGIN, STANDARD_MARGIN, term);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
grub_print_message_indented
|
|
|
|
(_("Press enter to boot the selected OS, "
|
|
|
|
"\'e\' to edit the commands before booting "
|
|
|
|
"or \'c\' for a command-line.\n"),
|
|
|
|
STANDARD_MARGIN, STANDARD_MARGIN, term);
|
|
|
|
}
|
2009-02-13 20:06:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-12-24 14:34:33 +00:00
|
|
|
print_entry (int y, int highlight, grub_menu_entry_t entry,
|
|
|
|
struct grub_term_output *term)
|
2009-02-13 20:06:27 +00:00
|
|
|
{
|
|
|
|
int x;
|
|
|
|
const char *title;
|
|
|
|
grub_size_t title_len;
|
|
|
|
grub_ssize_t len;
|
|
|
|
grub_uint32_t *unicode_title;
|
|
|
|
grub_ssize_t i;
|
|
|
|
grub_uint8_t old_color_normal, old_color_highlight;
|
|
|
|
|
|
|
|
title = entry ? entry->title : "";
|
|
|
|
title_len = grub_strlen (title);
|
|
|
|
unicode_title = grub_malloc (title_len * sizeof (*unicode_title));
|
|
|
|
if (! unicode_title)
|
|
|
|
/* XXX How to show this error? */
|
|
|
|
return;
|
|
|
|
|
|
|
|
len = grub_utf8_to_ucs4 (unicode_title, title_len,
|
|
|
|
(grub_uint8_t *) title, -1, 0);
|
|
|
|
if (len < 0)
|
|
|
|
{
|
|
|
|
/* It is an invalid sequence. */
|
|
|
|
grub_free (unicode_title);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
grub_term_getcolor (term, &old_color_normal, &old_color_highlight);
|
|
|
|
grub_term_setcolor (term, grub_color_menu_normal, grub_color_menu_highlight);
|
|
|
|
grub_term_setcolorstate (term, highlight
|
|
|
|
? GRUB_TERM_COLOR_HIGHLIGHT
|
|
|
|
: GRUB_TERM_COLOR_NORMAL);
|
2009-02-13 20:06:27 +00:00
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
grub_term_gotoxy (term, GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_MARGIN, y);
|
2009-02-13 20:06:27 +00:00
|
|
|
|
|
|
|
for (x = GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_MARGIN + 1, i = 0;
|
2009-12-24 14:34:33 +00:00
|
|
|
x < (int) (GRUB_TERM_LEFT_BORDER_X + grub_term_border_width (term)
|
|
|
|
- GRUB_TERM_MARGIN);
|
2009-02-13 20:06:27 +00:00
|
|
|
i++)
|
|
|
|
{
|
|
|
|
if (i < len
|
2009-12-24 14:34:33 +00:00
|
|
|
&& x <= (int) (GRUB_TERM_LEFT_BORDER_X + grub_term_border_width (term)
|
|
|
|
- GRUB_TERM_MARGIN - 1))
|
2009-02-13 20:06:27 +00:00
|
|
|
{
|
|
|
|
grub_ssize_t width;
|
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
width = grub_term_getcharwidth (term, unicode_title[i]);
|
2009-02-13 20:06:27 +00:00
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
if (x + width > (int) (GRUB_TERM_LEFT_BORDER_X
|
|
|
|
+ grub_term_border_width (term)
|
|
|
|
- GRUB_TERM_MARGIN - 1))
|
|
|
|
grub_putcode (GRUB_TERM_DISP_RIGHT, term);
|
2009-02-13 20:06:27 +00:00
|
|
|
else
|
2009-12-24 14:34:33 +00:00
|
|
|
grub_putcode (unicode_title[i], term);
|
2009-02-13 20:06:27 +00:00
|
|
|
|
|
|
|
x += width;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-12-24 14:34:33 +00:00
|
|
|
grub_putcode (' ', term);
|
2009-02-13 20:06:27 +00:00
|
|
|
x++;
|
|
|
|
}
|
|
|
|
}
|
2009-12-24 14:34:33 +00:00
|
|
|
grub_term_setcolorstate (term, GRUB_TERM_COLOR_NORMAL);
|
|
|
|
grub_putcode (' ', term);
|
2009-02-13 20:06:27 +00:00
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
grub_term_gotoxy (term, grub_term_cursor_x (term), y);
|
2009-02-13 20:06:27 +00:00
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
grub_term_setcolor (term, old_color_normal, old_color_highlight);
|
|
|
|
grub_term_setcolorstate (term, GRUB_TERM_COLOR_NORMAL);
|
2009-02-13 20:06:27 +00:00
|
|
|
grub_free (unicode_title);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-12-24 14:34:33 +00:00
|
|
|
print_entries (grub_menu_t menu, int first, int offset,
|
|
|
|
struct grub_term_output *term)
|
2009-02-13 20:06:27 +00:00
|
|
|
{
|
|
|
|
grub_menu_entry_t e;
|
|
|
|
int i;
|
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
grub_term_gotoxy (term,
|
|
|
|
GRUB_TERM_LEFT_BORDER_X + grub_term_border_width (term),
|
|
|
|
GRUB_TERM_FIRST_ENTRY_Y);
|
2009-02-13 20:06:27 +00:00
|
|
|
|
|
|
|
if (first)
|
2009-12-24 14:34:33 +00:00
|
|
|
grub_putcode (GRUB_TERM_DISP_UP, term);
|
2009-02-13 20:06:27 +00:00
|
|
|
else
|
2009-12-24 14:34:33 +00:00
|
|
|
grub_putcode (' ', term);
|
2009-02-13 20:06:27 +00:00
|
|
|
|
|
|
|
e = grub_menu_get_entry (menu, first);
|
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
for (i = 0; i < grub_term_num_entries (term); i++)
|
2009-02-13 20:06:27 +00:00
|
|
|
{
|
2009-12-24 14:34:33 +00:00
|
|
|
print_entry (GRUB_TERM_FIRST_ENTRY_Y + i, offset == i, e, term);
|
2009-02-13 20:06:27 +00:00
|
|
|
if (e)
|
|
|
|
e = e->next;
|
|
|
|
}
|
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
grub_term_gotoxy (term, GRUB_TERM_LEFT_BORDER_X
|
|
|
|
+ grub_term_border_width (term),
|
|
|
|
GRUB_TERM_TOP_BORDER_Y + grub_term_num_entries (term));
|
2009-02-13 20:06:27 +00:00
|
|
|
|
|
|
|
if (e)
|
2009-12-24 14:34:33 +00:00
|
|
|
grub_putcode (GRUB_TERM_DISP_DOWN, term);
|
2009-02-13 20:06:27 +00:00
|
|
|
else
|
2009-12-24 14:34:33 +00:00
|
|
|
grub_putcode (' ', term);
|
2009-02-13 20:06:27 +00:00
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
grub_term_gotoxy (term, grub_term_cursor_x (term),
|
|
|
|
GRUB_TERM_FIRST_ENTRY_Y + offset);
|
2009-02-13 20:06:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize the screen. If NESTED is non-zero, assume that this menu
|
|
|
|
is run from another menu or a command-line. If EDIT is non-zero, show
|
|
|
|
a message for the menu entry editor. */
|
|
|
|
void
|
2009-12-24 14:34:33 +00:00
|
|
|
grub_menu_init_page (int nested, int edit,
|
|
|
|
struct grub_term_output *term)
|
2009-02-13 20:06:27 +00:00
|
|
|
{
|
|
|
|
grub_uint8_t old_color_normal, old_color_highlight;
|
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
grub_term_getcolor (term, &old_color_normal, &old_color_highlight);
|
2009-02-13 20:06:27 +00:00
|
|
|
|
|
|
|
/* By default, use the same colors for the menu. */
|
|
|
|
grub_color_menu_normal = old_color_normal;
|
|
|
|
grub_color_menu_highlight = old_color_highlight;
|
|
|
|
|
|
|
|
/* Then give user a chance to replace them. */
|
2009-12-24 14:34:33 +00:00
|
|
|
grub_parse_color_name_pair (&grub_color_menu_normal,
|
|
|
|
grub_env_get ("menu_color_normal"));
|
|
|
|
grub_parse_color_name_pair (&grub_color_menu_highlight,
|
|
|
|
grub_env_get ("menu_color_highlight"));
|
|
|
|
|
|
|
|
grub_normal_init_page (term);
|
|
|
|
grub_term_setcolor (term, grub_color_menu_normal, grub_color_menu_highlight);
|
|
|
|
draw_border (term);
|
|
|
|
grub_term_setcolor (term, old_color_normal, old_color_highlight);
|
|
|
|
print_message (nested, edit, term);
|
2009-02-13 20:06:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-12-24 14:34:33 +00:00
|
|
|
menu_text_print_timeout (int timeout, void *dataptr)
|
2009-02-13 20:06:27 +00:00
|
|
|
{
|
2009-12-05 11:25:07 +00:00
|
|
|
const char *msg =
|
|
|
|
_("The highlighted entry will be booted automatically in %ds.");
|
2009-12-24 14:34:33 +00:00
|
|
|
struct menu_viewer_data *data = dataptr;
|
|
|
|
char *msg_translated;
|
|
|
|
int posx;
|
2009-12-05 11:25:07 +00:00
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
grub_term_gotoxy (data->term, 0, grub_term_height (data->term) - 3);
|
2009-02-13 20:06:27 +00:00
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
msg_translated = grub_malloc (sizeof (char) * grub_strlen (msg) + 5);
|
|
|
|
if (!msg_translated)
|
|
|
|
{
|
|
|
|
grub_print_error ();
|
|
|
|
grub_errno = GRUB_ERR_NONE;
|
|
|
|
return;
|
|
|
|
}
|
2009-12-19 00:05:41 +00:00
|
|
|
|
|
|
|
grub_sprintf (msg_translated, msg, timeout);
|
2009-12-24 14:34:33 +00:00
|
|
|
grub_print_message_indented (msg_translated, 3, 0, data->term);
|
2009-12-23 16:41:32 +00:00
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
posx = grub_term_getxy (data->term) >> 8;
|
|
|
|
print_spaces (grub_term_width (data->term) - posx - 1, data->term);
|
2009-12-05 11:25:07 +00:00
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
grub_term_gotoxy (data->term,
|
|
|
|
grub_term_cursor_x (data->term),
|
|
|
|
GRUB_TERM_FIRST_ENTRY_Y + data->offset);
|
|
|
|
grub_term_refresh (data->term);
|
2009-12-19 00:05:41 +00:00
|
|
|
}
|
2009-02-13 20:06:27 +00:00
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
static void
|
|
|
|
menu_text_set_chosen_entry (int entry, void *dataptr)
|
2009-02-13 20:06:27 +00:00
|
|
|
{
|
2009-12-24 14:34:33 +00:00
|
|
|
struct menu_viewer_data *data = dataptr;
|
|
|
|
int oldoffset = data->offset;
|
|
|
|
int complete_redraw = 0;
|
2009-12-25 00:13:21 +00:00
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
data->offset = entry - data->first;
|
|
|
|
if (data->offset > grub_term_num_entries (data->term) - 1)
|
2009-02-13 20:06:27 +00:00
|
|
|
{
|
2009-12-25 00:13:21 +00:00
|
|
|
data->first = entry - (grub_term_num_entries (data->term) - 1);
|
2009-12-24 14:34:33 +00:00
|
|
|
data->offset = grub_term_num_entries (data->term) - 1;
|
|
|
|
complete_redraw = 1;
|
2009-02-13 20:06:27 +00:00
|
|
|
}
|
2009-12-24 14:34:33 +00:00
|
|
|
if (data->offset < 0)
|
2009-02-13 20:06:27 +00:00
|
|
|
{
|
2009-12-24 14:34:33 +00:00
|
|
|
data->offset = 0;
|
|
|
|
data->first = entry;
|
|
|
|
complete_redraw = 1;
|
2009-02-13 20:06:27 +00:00
|
|
|
}
|
2009-12-24 14:34:33 +00:00
|
|
|
if (complete_redraw)
|
|
|
|
print_entries (data->menu, data->first, data->offset, data->term);
|
|
|
|
else
|
2009-02-13 20:06:27 +00:00
|
|
|
{
|
2009-12-24 14:34:33 +00:00
|
|
|
print_entry (GRUB_TERM_FIRST_ENTRY_Y + oldoffset, 0,
|
|
|
|
grub_menu_get_entry (data->menu, data->first + oldoffset),
|
|
|
|
data->term);
|
|
|
|
print_entry (GRUB_TERM_FIRST_ENTRY_Y + data->offset, 1,
|
|
|
|
grub_menu_get_entry (data->menu, data->first + data->offset),
|
|
|
|
data->term);
|
2009-02-13 20:06:27 +00:00
|
|
|
}
|
2009-12-24 14:34:33 +00:00
|
|
|
grub_term_refresh (data->term);
|
2009-02-13 20:06:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-12-24 14:34:33 +00:00
|
|
|
menu_text_fini (void *dataptr)
|
2009-02-13 20:06:27 +00:00
|
|
|
{
|
2009-12-24 14:34:33 +00:00
|
|
|
struct menu_viewer_data *data = dataptr;
|
2009-02-13 20:06:27 +00:00
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
grub_term_setcursor (data->term, 1);
|
2009-12-25 00:13:21 +00:00
|
|
|
grub_term_cls (data->term);
|
|
|
|
|
2009-02-13 20:06:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-12-24 14:34:33 +00:00
|
|
|
menu_text_clear_timeout (void *dataptr)
|
2009-02-13 20:06:27 +00:00
|
|
|
{
|
2009-12-24 14:34:33 +00:00
|
|
|
struct menu_viewer_data *data = dataptr;
|
|
|
|
|
|
|
|
grub_term_gotoxy (data->term, 0, grub_term_height (data->term) - 3);
|
|
|
|
print_spaces (grub_term_width (data->term) - 1, data->term);
|
|
|
|
grub_term_gotoxy (data->term, grub_term_cursor_x (data->term),
|
|
|
|
GRUB_TERM_FIRST_ENTRY_Y + data->offset);
|
|
|
|
grub_term_refresh (data->term);
|
2009-02-13 20:06:27 +00:00
|
|
|
}
|
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
void
|
|
|
|
grub_menu_text_register_instances (int entry, grub_menu_t menu, int nested)
|
2009-02-13 20:06:27 +00:00
|
|
|
{
|
2009-12-24 14:34:33 +00:00
|
|
|
struct menu_viewer_data *data;
|
|
|
|
struct grub_menu_viewer *instance;
|
|
|
|
struct grub_term_output *term;
|
2009-02-13 20:06:27 +00:00
|
|
|
|
2009-12-24 16:51:43 +00:00
|
|
|
FOR_ACTIVE_TERM_OUTPUTS(term)
|
|
|
|
{
|
|
|
|
instance = grub_zalloc (sizeof (*instance));
|
|
|
|
if (!instance)
|
|
|
|
{
|
|
|
|
grub_print_error ();
|
|
|
|
grub_errno = GRUB_ERR_NONE;
|
2009-12-24 14:34:33 +00:00
|
|
|
continue;
|
2009-12-24 16:51:43 +00:00
|
|
|
}
|
|
|
|
data = grub_zalloc (sizeof (*data));
|
|
|
|
if (!data)
|
|
|
|
{
|
|
|
|
grub_free (instance);
|
|
|
|
grub_print_error ();
|
|
|
|
grub_errno = GRUB_ERR_NONE;
|
|
|
|
continue;
|
|
|
|
}
|
2009-12-25 00:13:21 +00:00
|
|
|
|
2009-12-24 16:51:43 +00:00
|
|
|
data->term = term;
|
|
|
|
instance->data = data;
|
|
|
|
instance->set_chosen_entry = menu_text_set_chosen_entry;
|
|
|
|
instance->print_timeout = menu_text_print_timeout;
|
|
|
|
instance->clear_timeout = menu_text_clear_timeout;
|
|
|
|
instance->fini = menu_text_fini;
|
2009-12-25 00:13:21 +00:00
|
|
|
|
2009-12-24 16:51:43 +00:00
|
|
|
data->menu = menu;
|
|
|
|
|
|
|
|
data->offset = entry;
|
|
|
|
data->first = 0;
|
|
|
|
if (data->offset > grub_term_num_entries (data->term) - 1)
|
|
|
|
{
|
|
|
|
data->first = data->offset - (grub_term_num_entries (data->term) - 1);
|
|
|
|
data->offset = grub_term_num_entries (data->term) - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
grub_term_setcursor (data->term, 0);
|
|
|
|
grub_menu_init_page (nested, 0, data->term);
|
|
|
|
print_entries (menu, data->first, data->offset, data->term);
|
|
|
|
grub_term_refresh (data->term);
|
2009-12-25 00:13:21 +00:00
|
|
|
grub_menu_register_viewer (instance);
|
2009-12-24 16:51:43 +00:00
|
|
|
}
|
2009-02-13 20:06:27 +00:00
|
|
|
}
|