2005-08-21 Yoshinori K. Okuji <okuji@enbug.org>
* util/console.c (grub_ncurses_putchar): If C is greater than 0x7f, set C to a question mark. (grub_ncurses_getcharwidth): New function. (grub_ncurses_term): Specify grub_ncurses_getcharwidth as getcharwidth. * normal/menu.c (print_entry): Made aware of Unicode. First, convert TITLE to UCS-4, and predict the cursor position by grub_getcharwidth. * include/grub/misc.h (grub_utf8_to_ucs4): Specify the qualifier const to SRC. * kern/misc.c (grub_utf16_to_utf8): Likewise.
This commit is contained in:
parent
16ccb8b138
commit
385c6a92a3
5 changed files with 72 additions and 13 deletions
16
ChangeLog
16
ChangeLog
|
@ -1,3 +1,19 @@
|
||||||
|
2005-08-21 Yoshinori K. Okuji <okuji@enbug.org>
|
||||||
|
|
||||||
|
* util/console.c (grub_ncurses_putchar): If C is greater than
|
||||||
|
0x7f, set C to a question mark.
|
||||||
|
(grub_ncurses_getcharwidth): New function.
|
||||||
|
(grub_ncurses_term): Specify grub_ncurses_getcharwidth as
|
||||||
|
getcharwidth.
|
||||||
|
|
||||||
|
* normal/menu.c (print_entry): Made aware of Unicode. First,
|
||||||
|
convert TITLE to UCS-4, and predict the cursor position by
|
||||||
|
grub_getcharwidth.
|
||||||
|
|
||||||
|
* include/grub/misc.h (grub_utf8_to_ucs4): Specify the qualifier
|
||||||
|
const to SRC.
|
||||||
|
* kern/misc.c (grub_utf16_to_utf8): Likewise.
|
||||||
|
|
||||||
2005-08-20 Yoshinori K. Okuji <okuji@enbug.org>
|
2005-08-20 Yoshinori K. Okuji <okuji@enbug.org>
|
||||||
|
|
||||||
* loader/powerpc/ieee1275/linux.c (grub_rescue_cmd_linux): Specify
|
* loader/powerpc/ieee1275/linux.c (grub_rescue_cmd_linux): Specify
|
||||||
|
|
|
@ -73,7 +73,7 @@ grub_uint8_t *EXPORT_FUNC(grub_utf16_to_utf8) (grub_uint8_t *dest,
|
||||||
grub_uint16_t *src,
|
grub_uint16_t *src,
|
||||||
grub_size_t size);
|
grub_size_t size);
|
||||||
grub_ssize_t EXPORT_FUNC(grub_utf8_to_ucs4) (grub_uint32_t *dest,
|
grub_ssize_t EXPORT_FUNC(grub_utf8_to_ucs4) (grub_uint32_t *dest,
|
||||||
grub_uint8_t *src,
|
const grub_uint8_t *src,
|
||||||
grub_size_t size);
|
grub_size_t size);
|
||||||
|
|
||||||
grub_err_t EXPORT_FUNC(grub_split_cmdline) (const char *str,
|
grub_err_t EXPORT_FUNC(grub_split_cmdline) (const char *str,
|
||||||
|
|
|
@ -809,7 +809,8 @@ grub_utf16_to_utf8 (grub_uint8_t *dest, grub_uint16_t *src,
|
||||||
characters (when the input is unknown). If an invalid sequence is found,
|
characters (when the input is unknown). If an invalid sequence is found,
|
||||||
return -1. */
|
return -1. */
|
||||||
grub_ssize_t
|
grub_ssize_t
|
||||||
grub_utf8_to_ucs4 (grub_uint32_t *dest, grub_uint8_t *src, grub_size_t size)
|
grub_utf8_to_ucs4 (grub_uint32_t *dest, const grub_uint8_t *src,
|
||||||
|
grub_size_t size)
|
||||||
{
|
{
|
||||||
grub_uint32_t *p = dest;
|
grub_uint32_t *p = dest;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* GRUB -- GRand Unified Bootloader
|
* GRUB -- GRand Unified Bootloader
|
||||||
* Copyright (C) 2003,2004 Free Software Foundation, Inc.
|
* Copyright (C) 2003,2004,2005 Free Software Foundation, Inc.
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -41,11 +41,13 @@ draw_border (void)
|
||||||
{
|
{
|
||||||
grub_gotoxy (GRUB_TERM_MARGIN, GRUB_TERM_TOP_BORDER_Y + i + 1);
|
grub_gotoxy (GRUB_TERM_MARGIN, GRUB_TERM_TOP_BORDER_Y + i + 1);
|
||||||
grub_putcode (GRUB_TERM_DISP_VLINE);
|
grub_putcode (GRUB_TERM_DISP_VLINE);
|
||||||
grub_gotoxy (GRUB_TERM_MARGIN + GRUB_TERM_BORDER_WIDTH - 1, GRUB_TERM_TOP_BORDER_Y + i + 1);
|
grub_gotoxy (GRUB_TERM_MARGIN + GRUB_TERM_BORDER_WIDTH - 1,
|
||||||
|
GRUB_TERM_TOP_BORDER_Y + i + 1);
|
||||||
grub_putcode (GRUB_TERM_DISP_VLINE);
|
grub_putcode (GRUB_TERM_DISP_VLINE);
|
||||||
}
|
}
|
||||||
|
|
||||||
grub_gotoxy (GRUB_TERM_MARGIN, GRUB_TERM_TOP_BORDER_Y + GRUB_TERM_NUM_ENTRIES + 1);
|
grub_gotoxy (GRUB_TERM_MARGIN,
|
||||||
|
GRUB_TERM_TOP_BORDER_Y + GRUB_TERM_NUM_ENTRIES + 1);
|
||||||
grub_putcode (GRUB_TERM_DISP_LL);
|
grub_putcode (GRUB_TERM_DISP_LL);
|
||||||
for (i = 0; i < (unsigned) GRUB_TERM_BORDER_WIDTH - 2; i++)
|
for (i = 0; i < (unsigned) GRUB_TERM_BORDER_WIDTH - 2; i++)
|
||||||
grub_putcode (GRUB_TERM_DISP_HLINE);
|
grub_putcode (GRUB_TERM_DISP_HLINE);
|
||||||
|
@ -53,7 +55,9 @@ draw_border (void)
|
||||||
|
|
||||||
grub_setcolorstate (GRUB_TERM_COLOR_STANDARD);
|
grub_setcolorstate (GRUB_TERM_COLOR_STANDARD);
|
||||||
|
|
||||||
grub_gotoxy (GRUB_TERM_MARGIN, GRUB_TERM_TOP_BORDER_Y + GRUB_TERM_NUM_ENTRIES + GRUB_TERM_MARGIN + 1);
|
grub_gotoxy (GRUB_TERM_MARGIN,
|
||||||
|
(GRUB_TERM_TOP_BORDER_Y + GRUB_TERM_NUM_ENTRIES
|
||||||
|
+ GRUB_TERM_MARGIN + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -97,8 +101,23 @@ print_entry (int y, int highlight, grub_menu_entry_t entry)
|
||||||
{
|
{
|
||||||
int x;
|
int x;
|
||||||
const char *title;
|
const char *title;
|
||||||
|
grub_ssize_t len;
|
||||||
|
grub_uint32_t *unicode_title;
|
||||||
|
grub_ssize_t i;
|
||||||
|
|
||||||
title = entry ? entry->title : "";
|
title = entry ? entry->title : "";
|
||||||
|
unicode_title = grub_malloc (grub_strlen (title) * sizeof (*unicode_title));
|
||||||
|
if (! unicode_title)
|
||||||
|
/* XXX How to show this error? */
|
||||||
|
return;
|
||||||
|
|
||||||
|
len = grub_utf8_to_ucs4 (unicode_title, title, grub_strlen (title));
|
||||||
|
if (len < 0)
|
||||||
|
{
|
||||||
|
/* It is an invalid sequence. */
|
||||||
|
grub_free (unicode_title);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
grub_setcolorstate (highlight
|
grub_setcolorstate (highlight
|
||||||
? GRUB_TERM_COLOR_HIGHLIGHT
|
? GRUB_TERM_COLOR_HIGHLIGHT
|
||||||
|
@ -106,23 +125,36 @@ print_entry (int y, int highlight, grub_menu_entry_t entry)
|
||||||
|
|
||||||
grub_gotoxy (GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_MARGIN, y);
|
grub_gotoxy (GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_MARGIN, y);
|
||||||
|
|
||||||
for (x = GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_MARGIN + 1;
|
for (x = GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_MARGIN + 1, i = 0;
|
||||||
x < GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_BORDER_WIDTH - GRUB_TERM_MARGIN;
|
x < GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_BORDER_WIDTH - GRUB_TERM_MARGIN;
|
||||||
x++)
|
i++)
|
||||||
{
|
{
|
||||||
if (*title && x <= GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_BORDER_WIDTH - GRUB_TERM_MARGIN - 1)
|
if (i < len
|
||||||
|
&& x <= (GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_BORDER_WIDTH
|
||||||
|
- GRUB_TERM_MARGIN - 1))
|
||||||
{
|
{
|
||||||
if (x == GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_BORDER_WIDTH - GRUB_TERM_MARGIN - 1)
|
grub_ssize_t width;
|
||||||
|
|
||||||
|
width = grub_getcharwidth (unicode_title[i]);
|
||||||
|
|
||||||
|
if (x + width > (GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_BORDER_WIDTH
|
||||||
|
- GRUB_TERM_MARGIN - 1))
|
||||||
grub_putcode (GRUB_TERM_DISP_RIGHT);
|
grub_putcode (GRUB_TERM_DISP_RIGHT);
|
||||||
else
|
else
|
||||||
grub_putchar (*title++);
|
grub_putcode (unicode_title[i]);
|
||||||
|
|
||||||
|
x += width;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
grub_putchar (' ');
|
grub_putchar (' ');
|
||||||
|
x++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
grub_gotoxy (GRUB_TERM_CURSOR_X, y);
|
grub_gotoxy (GRUB_TERM_CURSOR_X, y);
|
||||||
|
|
||||||
grub_setcolorstate (GRUB_TERM_COLOR_STANDARD);
|
grub_setcolorstate (GRUB_TERM_COLOR_STANDARD);
|
||||||
|
grub_free (unicode_title);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
|
@ -80,12 +80,21 @@ grub_ncurses_putchar (grub_uint32_t c)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
/* ncurses does not support Unicode. */
|
||||||
|
if (c > 0x7f)
|
||||||
|
c = '?';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
addch (c | grub_console_attr);
|
addch (c | grub_console_attr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static grub_ssize_t
|
||||||
|
grub_ncurses_getcharwidth (grub_uint32_t code __attribute__ ((unused)))
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
grub_ncurses_setcolorstate (grub_term_color_state state)
|
grub_ncurses_setcolorstate (grub_term_color_state state)
|
||||||
{
|
{
|
||||||
|
@ -283,6 +292,7 @@ static struct grub_term grub_ncurses_term =
|
||||||
.init = grub_ncurses_init,
|
.init = grub_ncurses_init,
|
||||||
.fini = grub_ncurses_fini,
|
.fini = grub_ncurses_fini,
|
||||||
.putchar = grub_ncurses_putchar,
|
.putchar = grub_ncurses_putchar,
|
||||||
|
.getcharwidth = grub_ncurses_getcharwidth,
|
||||||
.checkkey = grub_ncurses_checkkey,
|
.checkkey = grub_ncurses_checkkey,
|
||||||
.getkey = grub_ncurses_getkey,
|
.getkey = grub_ncurses_getkey,
|
||||||
.getxy = grub_ncurses_getxy,
|
.getxy = grub_ncurses_getxy,
|
||||||
|
|
Loading…
Reference in a new issue