zbyszek / rpms / grub2

Forked from rpms/grub2 5 years ago
Clone
31004e6
From 1314381c929134bfe80ecf100571875dcc35adff Mon Sep 17 00:00:00 2001
31004e6
From: Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>
31004e6
Date: Sat, 27 Apr 2013 00:02:23 +0200
f74b50e
Subject: [PATCH 359/482] 	Replace libcurses with our own vt100 handling
31004e6
 for the ease of testing 	and decreasing prerequisites.
31004e6
31004e6
---
31004e6
 ChangeLog                    |   5 +
31004e6
 INSTALL                      |   6 +-
31004e6
 configure.ac                 |  16 ---
31004e6
 docs/grub.texi               |  45 +++---
31004e6
 gentpl.py                    |   2 +-
31004e6
 grub-core/Makefile.am        |   1 +
31004e6
 grub-core/Makefile.core.def  |   4 +-
31004e6
 grub-core/term/emu/console.c | 329 ++++++++++++++-----------------------------
31004e6
 include/grub/terminfo.h      |   2 -
31004e6
 9 files changed, 146 insertions(+), 264 deletions(-)
31004e6
31004e6
diff --git a/ChangeLog b/ChangeLog
31004e6
index f554ba8..237ca05 100644
31004e6
--- a/ChangeLog
31004e6
+++ b/ChangeLog
31004e6
@@ -1,5 +1,10 @@
31004e6
 2013-04-26  Vladimir Serbinenko  <phcoder@gmail.com>
31004e6
 
31004e6
+	Replace libcurses with our own vt100 handling for the ease of testing
31004e6
+	and decreasing prerequisites.
31004e6
+
31004e6
+2013-04-26  Vladimir Serbinenko  <phcoder@gmail.com>
31004e6
+
31004e6
 	* grub-core/Makefile.core.def: Fix grub-emu and grub-emu-lite sources.
31004e6
 
31004e6
 2013-04-26  Vladimir Serbinenko  <phcoder@gmail.com>
31004e6
diff --git a/INSTALL b/INSTALL
31004e6
index 3333686..a626395 100644
31004e6
--- a/INSTALL
31004e6
+++ b/INSTALL
31004e6
@@ -23,11 +23,11 @@ On GNU/Linux, you also need:
31004e6
 
31004e6
 * libdevmapper 1.02.34 or later (recommended)
31004e6
 
31004e6
-To build grub-emu, you need:
31004e6
+For optional grub-emu features, you need:
31004e6
 
31004e6
-* ncurses
31004e6
-* libusb (recommended)
31004e6
 * SDL (recommended)
31004e6
+* libpciaccess (optional)
31004e6
+* libusb (optional)
31004e6
 
31004e6
 To build GRUB's graphical terminal (gfxterm), you need:
31004e6
 
31004e6
diff --git a/configure.ac b/configure.ac
31004e6
index 7d3aeac..5ff7f25 100644
31004e6
--- a/configure.ac
31004e6
+++ b/configure.ac
31004e6
@@ -842,22 +842,6 @@ AC_ARG_ENABLE([grub-emu-pci],
31004e6
                              [build and install the `grub-emu' debugging utility with PCI support (potentially dangerous) (default=no)])])
31004e6
 
31004e6
 if test "$platform" = emu; then
31004e6
-  missing_ncurses=
31004e6
-[# Check for curses libraries.]
31004e6
-  AC_CHECK_LIB([ncurses], [wgetch], [LIBCURSES="-lncurses"],
31004e6
-    [AC_CHECK_LIB([curses], [wgetch], [LIBCURSES="-lcurses"],
31004e6
-      [missing_ncurses=[true]])])
31004e6
-  AC_SUBST([LIBCURSES])
31004e6
-[if [ x"$missing_ncurses" = x ]; then ]
31004e6
-  [# Check for headers.]
31004e6
-  AC_CHECK_HEADERS([ncurses/curses.h], [],
31004e6
-    [AC_CHECK_HEADERS([ncurses.h], [],
31004e6
-      [AC_CHECK_HEADERS([curses.h], [],
31004e6
-	[missing_ncurses=[true]])])])
31004e6
-[fi]
31004e6
-if test x"$missing_ncurses" = xtrue ; then
31004e6
-  AC_MSG_ERROR([grub-emu can't be compiled without ncurses])
31004e6
-fi
31004e6
 
31004e6
 if test x"$enable_grub_emu_usb" != xyes ; then
31004e6
    grub_emu_usb_excuse="not enabled"
31004e6
diff --git a/docs/grub.texi b/docs/grub.texi
31004e6
index 920a558..754e191 100644
31004e6
--- a/docs/grub.texi
31004e6
+++ b/docs/grub.texi
31004e6
@@ -4586,26 +4586,35 @@ On normalized ZFS subvolumes filenames out of normalisation are inaccessible.
31004e6
 
31004e6
 @chapter Output terminal
31004e6
 Firmware output console ``console'' on ARC and IEEE1275 are limited to ASCII.
31004e6
+
31004e6
 BIOS firmware console and VGA text are limited to ASCII and some pseudographics.
31004e6
+
31004e6
 None of above mentioned is appropriate for displaying international and any
31004e6
 unsupported character is replaced with question mark except pseudographics
31004e6
-which we attempt to approximate with ASCII. EFI console on the other hand
31004e6
-nominally supports UTF-16 but actual language coverage depends on firmware and
31004e6
-may be very limited. The encoding used on serial can be chosen with
31004e6
-@command{terminfo} as either ASCII, UTF-8 or ``visual UTF-8''. Last one is
31004e6
-against the specification but results in correct rendering of right-to-left
31004e6
-on some readers which don't have own bidi implementation. When using gfxterm
31004e6
-or gfxmenu GRUB itself is responsible for rendering the text. In this case
31004e6
-GRUB is limited by loaded fonts. If fonts contain all required characters
31004e6
-then bidirectional text, cursive variants and combining marks other than
31004e6
-enclosing, half (e.g. left half tilde or combining overline) and double ones.
31004e6
-Ligatures aren't supported though. This should cover European, Middle Eastern
31004e6
-(if you don't mind lack of lam-alif ligature in Arabic) and East Asian scripts.
31004e6
-Notable unsupported scripts are Brahmic family and derived as well as
31004e6
-Mongolian, Tifinagh, Korean Jamo (precomposed characters have no problem)
31004e6
-and tonal writing (2e5-2e9). GRUB also ignores deprecated (as specified
31004e6
-in Unicode) characters (e.g. tags). GRUB also doesn't handle so called
31004e6
-``annotation characters'' If you can complete either of
31004e6
+which we attempt to approximate with ASCII.
31004e6
+
31004e6
+EFI console on the other hand nominally supports UTF-16 but actual language
31004e6
+coverage depends on firmware and may be very limited.
31004e6
+
31004e6
+The encoding used on serial can be chosen with @command{terminfo} as
31004e6
+either ASCII, UTF-8 or ``visual UTF-8''. Last one is against the specification
31004e6
+but results in correct rendering of right-to-left on some readers which don't
31004e6
+have own bidi implementation.
31004e6
+
31004e6
+On emu GRUB checks if charset is UTF-8 and uses it if so and uses ASCII
31004e6
+otherwise.
31004e6
+
31004e6
+When using gfxterm or gfxmenu GRUB itself is responsible for rendering the
31004e6
+text. In this case GRUB is limited by loaded fonts. If fonts contain all
31004e6
+required characters then bidirectional text, cursive variants and combining
31004e6
+marks other than enclosing, half (e.g. left half tilde or combining overline)
31004e6
+and double ones. Ligatures aren't supported though. This should cover European,
31004e6
+Middle Eastern (if you don't mind lack of lam-alif ligature in Arabic) and
31004e6
+East Asian scripts. Notable unsupported scripts are Brahmic family and
31004e6
+derived as well as Mongolian, Tifinagh, Korean Jamo (precomposed characters
31004e6
+have no problem) and tonal writing (2e5-2e9). GRUB also ignores deprecated
31004e6
+(as specified in Unicode) characters (e.g. tags). GRUB also doesn't handle so
31004e6
+called ``annotation characters'' If you can complete either of
31004e6
 two lists or, better, propose a patch to improve rendering, please contact
31004e6
 developer team.
31004e6
 
31004e6
@@ -4826,7 +4835,7 @@ and mips-qemu_mips can use only memory up to first hole.
31004e6
 @multitable @columnfractions .20 .20 .20 .20 .20
31004e6
 @item                    @tab MIPS qemu @tab emu
31004e6
 @item video              @tab no        @tab yes
31004e6
-@item console charset    @tab CP437     @tab ASCII
31004e6
+@item console charset    @tab CP437     @tab Unicode (*)
31004e6
 @item network            @tab no        @tab yes
31004e6
 @item ATA/AHCI           @tab yes       @tab no
31004e6
 @item AT keyboard        @tab yes       @tab no
31004e6
diff --git a/gentpl.py b/gentpl.py
31004e6
index b159795..8674622 100644
31004e6
--- a/gentpl.py
31004e6
+++ b/gentpl.py
31004e6
@@ -57,7 +57,7 @@ GROUPS["videomodules"]   = GRUB_PLATFORMS[:];
31004e6
 for i in GROUPS["videoinkernel"]: GROUPS["videomodules"].remove(i)
31004e6
 
31004e6
 # Similar for terminfo
31004e6
-GROUPS["terminfoinkernel"] = ["mips_loongson", "mips_arc", "mips_qemu_mips" ] + GROUPS["ieee1275"];
31004e6
+GROUPS["terminfoinkernel"] = [ "emu", "mips_loongson", "mips_arc", "mips_qemu_mips" ] + GROUPS["ieee1275"];
31004e6
 GROUPS["terminfomodule"]   = GRUB_PLATFORMS[:];
31004e6
 for i in GROUPS["terminfoinkernel"]: GROUPS["terminfomodule"].remove(i)
31004e6
 
31004e6
diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am
31004e6
index 07aad50..fa6afcf 100644
31004e6
--- a/grub-core/Makefile.am
31004e6
+++ b/grub-core/Makefile.am
31004e6
@@ -216,6 +216,7 @@ if COND_emu
31004e6
 KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/datetime.h
31004e6
 KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/emu/misc.h
31004e6
 KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/emu/export.h
31004e6
+KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h
31004e6
 if COND_GRUB_EMU_SDL
31004e6
 KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/sdl.h
31004e6
 endif
31004e6
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
31004e6
index e2ecff1..2a8ac6f 100644
31004e6
--- a/grub-core/Makefile.core.def
31004e6
+++ b/grub-core/Makefile.core.def
31004e6
@@ -250,7 +250,7 @@ program = {
31004e6
 
31004e6
   ldadd = 'kernel.exec$(EXEEXT)';
31004e6
   ldadd = '$(MODULE_FILES)';
31004e6
-  ldadd = 'gnulib/libgnu.a $(LIBCURSES) $(LIBINTL) $(LIBUTIL) $(LIBSDL) $(LIBUSB) $(LIBPCIACCESS) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)';
31004e6
+  ldadd = 'gnulib/libgnu.a $(LIBINTL) $(LIBUTIL) $(LIBSDL) $(LIBUSB) $(LIBPCIACCESS) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)';
31004e6
 
31004e6
   enable = emu;
31004e6
 };
31004e6
@@ -262,7 +262,7 @@ program = {
31004e6
   emu_nodist = symlist.c;
31004e6
 
31004e6
   ldadd = 'kernel.exec$(EXEEXT)';
31004e6
-  ldadd = 'gnulib/libgnu.a $(LIBCURSES) $(LIBINTL) $(LIBUTIL) $(LIBSDL) $(LIBUSB) $(LIBPCIACCESS) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)';
31004e6
+  ldadd = 'gnulib/libgnu.a $(LIBINTL) $(LIBUTIL) $(LIBSDL) $(LIBUSB) $(LIBPCIACCESS) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)';
31004e6
 
31004e6
   enable = emu;
31004e6
 };
31004e6
diff --git a/grub-core/term/emu/console.c b/grub-core/term/emu/console.c
31004e6
index 5bd5db1..d61ade1 100644
31004e6
--- a/grub-core/term/emu/console.c
31004e6
+++ b/grub-core/term/emu/console.c
31004e6
@@ -1,7 +1,7 @@
31004e6
-/*  console.c -- Ncurses console for GRUB.  */
31004e6
+/*  console.c -- console for GRUB.  */
31004e6
 /*
31004e6
  *  GRUB  --  GRand Unified Bootloader
31004e6
- *  Copyright (C) 2003,2005,2007,2008  Free Software Foundation, Inc.
31004e6
+ *  Copyright (C) 2013  Free Software Foundation, Inc.
31004e6
  *
31004e6
  *  GRUB is free software: you can redistribute it and/or modify
31004e6
  *  it under the terms of the GNU General Public License as published by
31004e6
@@ -20,274 +20,159 @@
31004e6
 #include <config.h>
31004e6
 #include <config-util.h>
31004e6
 
31004e6
-/* For compatibility.  */
31004e6
-#ifndef A_NORMAL
31004e6
-# define A_NORMAL	0
31004e6
-#endif /* ! A_NORMAL */
31004e6
-#ifndef A_STANDOUT
31004e6
-# define A_STANDOUT	0
31004e6
-#endif /* ! A_STANDOUT */
31004e6
-
31004e6
-#include <grub/emu/console.h>
31004e6
 #include <grub/term.h>
31004e6
 #include <grub/types.h>
31004e6
+#include <grub/misc.h>
31004e6
+#include <grub/mm.h>
31004e6
+#include <grub/time.h>
31004e6
+#include <grub/terminfo.h>
31004e6
+#include <grub/dl.h>
31004e6
+
31004e6
+#include <sys/types.h>
31004e6
+#include <sys/stat.h>
31004e6
+#include <fcntl.h>
31004e6
+#include <unistd.h>
31004e6
+#include <termios.h>
31004e6
+#include <stdlib.h>
31004e6
+#include <sys/ioctl.h>
31004e6
+#include <langinfo.h>
31004e6
 
31004e6
-#if defined(HAVE_NCURSES_CURSES_H)
31004e6
-# include <ncurses/curses.h>
31004e6
-#elif defined(HAVE_NCURSES_H)
31004e6
-# include <ncurses.h>
31004e6
-#elif defined(HAVE_CURSES_H)
31004e6
-# include <curses.h>
31004e6
-#else
31004e6
-#error What the hell?
31004e6
-#endif
31004e6
-
31004e6
-static int grub_console_attr = A_NORMAL;
31004e6
-
31004e6
-grub_uint8_t grub_console_cur_color = 7;
31004e6
-
31004e6
-static const grub_uint8_t grub_console_standard_color = 0x7;
31004e6
-
31004e6
-#define NUM_COLORS	8
31004e6
-
31004e6
-static grub_uint8_t color_map[NUM_COLORS] =
31004e6
-{
31004e6
-  COLOR_BLACK,
31004e6
-  COLOR_BLUE,
31004e6
-  COLOR_GREEN,
31004e6
-  COLOR_CYAN,
31004e6
-  COLOR_RED,
31004e6
-  COLOR_MAGENTA,
31004e6
-  COLOR_YELLOW,
31004e6
-  COLOR_WHITE
31004e6
-};
31004e6
+#include <grub/emu/console.h>
31004e6
 
31004e6
-static int use_color;
31004e6
+extern struct grub_terminfo_output_state grub_console_terminfo_output;
31004e6
+static int original_fl;
31004e6
+static int saved_orig;
31004e6
+static struct termios orig_tty;
31004e6
+static struct termios new_tty;
31004e6
 
31004e6
 static void
31004e6
-grub_ncurses_putchar (struct grub_term_output *term __attribute__ ((unused)),
31004e6
-		      const struct grub_unicode_glyph *c)
31004e6
+put (struct grub_term_output *term __attribute__ ((unused)), const int c)
31004e6
 {
31004e6
-  addch (c->base | grub_console_attr);
31004e6
-}
31004e6
+  char chr = c;
31004e6
 
31004e6
-static void
31004e6
-grub_ncurses_setcolorstate (struct grub_term_output *term,
31004e6
-			    grub_term_color_state state)
31004e6
-{
31004e6
-  switch (state)
31004e6
-    {
31004e6
-    case GRUB_TERM_COLOR_STANDARD:
31004e6
-      grub_console_cur_color = grub_console_standard_color;
31004e6
-      grub_console_attr = A_NORMAL;
31004e6
-      break;
31004e6
-    case GRUB_TERM_COLOR_NORMAL:
31004e6
-      grub_console_cur_color = grub_term_normal_color;
31004e6
-      grub_console_attr = A_NORMAL;
31004e6
-      break;
31004e6
-    case GRUB_TERM_COLOR_HIGHLIGHT:
31004e6
-      grub_console_cur_color = grub_term_highlight_color;
31004e6
-      grub_console_attr = A_STANDOUT;
31004e6
-      break;
31004e6
-    default:
31004e6
-      break;
31004e6
-    }
31004e6
-
31004e6
-  if (use_color)
31004e6
-    {
31004e6
-      grub_uint8_t fg, bg;
31004e6
-
31004e6
-      fg = (grub_console_cur_color & 7);
31004e6
-      bg = (grub_console_cur_color >> 4) & 7;
31004e6
-
31004e6
-      grub_console_attr = (grub_console_cur_color & 8) ? A_BOLD : A_NORMAL;
31004e6
-      color_set ((bg << 3) + fg, 0);
31004e6
-    }
31004e6
+  write (STDOUT_FILENO, &chr, 1);
31004e6
 }
31004e6
 
31004e6
 static int
31004e6
-grub_ncurses_getkey (struct grub_term_input *term __attribute__ ((unused)))
31004e6
-{
31004e6
-  int c;
31004e6
-
31004e6
-  wtimeout (stdscr, 100);
31004e6
-  c = getch ();
31004e6
-
31004e6
-  switch (c)
31004e6
-    {
31004e6
-    case ERR:
31004e6
-      return GRUB_TERM_NO_KEY;
31004e6
-    case KEY_LEFT:
31004e6
-      c = GRUB_TERM_KEY_LEFT;
31004e6
-      break;
31004e6
-
31004e6
-    case KEY_RIGHT:
31004e6
-      c = GRUB_TERM_KEY_RIGHT;
31004e6
-      break;
31004e6
-
31004e6
-    case KEY_UP:
31004e6
-      c = GRUB_TERM_KEY_UP;
31004e6
-      break;
31004e6
-
31004e6
-    case KEY_DOWN:
31004e6
-      c = GRUB_TERM_KEY_DOWN;
31004e6
-      break;
31004e6
-
31004e6
-    case KEY_IC:
31004e6
-      c = 24;
31004e6
-      break;
31004e6
-
31004e6
-    case KEY_DC:
31004e6
-      c = GRUB_TERM_KEY_DC;
31004e6
-      break;
31004e6
-
31004e6
-    case KEY_BACKSPACE:
31004e6
-      /* XXX: For some reason ncurses on xterm does not return
31004e6
-	 KEY_BACKSPACE.  */
31004e6
-    case 127:
31004e6
-      c = '\b';
31004e6
-      break;
31004e6
-
31004e6
-    case KEY_HOME:
31004e6
-      c = GRUB_TERM_KEY_HOME;
31004e6
-      break;
31004e6
-
31004e6
-    case KEY_END:
31004e6
-      c = GRUB_TERM_KEY_END;
31004e6
-      break;
31004e6
-
31004e6
-    case KEY_NPAGE:
31004e6
-      c = GRUB_TERM_KEY_NPAGE;
31004e6
-      break;
31004e6
-
31004e6
-    case KEY_PPAGE:
31004e6
-      c = GRUB_TERM_KEY_PPAGE;
31004e6
-      break;
31004e6
-    }
31004e6
-
31004e6
-  return c;
31004e6
-}
31004e6
-
31004e6
-static grub_uint16_t
31004e6
-grub_ncurses_getxy (struct grub_term_output *term __attribute__ ((unused)))
31004e6
+readkey (struct grub_term_input *term __attribute__ ((unused)))
31004e6
 {
31004e6
-  int x;
31004e6
-  int y;
31004e6
+  grub_uint8_t c;
31004e6
+  ssize_t actual;
31004e6
 
31004e6
-  getyx (stdscr, y, x);
31004e6
-
31004e6
-  return (x << 8) | y;
31004e6
+  actual = read (STDIN_FILENO, &c, 1);
31004e6
+  if (actual > 0)
31004e6
+    return c;
31004e6
+  return -1;
31004e6
 }
31004e6
 
31004e6
-static grub_uint16_t
31004e6
-grub_ncurses_getwh (struct grub_term_output *term __attribute__ ((unused)))
31004e6
+static grub_err_t
31004e6
+grub_console_init_input (struct grub_term_input *term)
31004e6
 {
31004e6
-  int x;
31004e6
-  int y;
31004e6
+  if (!saved_orig)
31004e6
+    {
31004e6
+      original_fl = fcntl (STDIN_FILENO, F_GETFL);
31004e6
+      fcntl (STDIN_FILENO, F_SETFL, original_fl | O_NONBLOCK);
31004e6
+    }
31004e6
 
31004e6
-  getmaxyx (stdscr, y, x);
31004e6
+  saved_orig = 1;
31004e6
 
31004e6
-  return (x << 8) | y;
31004e6
-}
31004e6
+  tcgetattr(STDIN_FILENO, &orig_tty);
31004e6
+  new_tty = orig_tty;
31004e6
+  new_tty.c_lflag &= ~(ICANON | ECHO);
31004e6
+  new_tty.c_cc[VMIN] = 1;
31004e6
+  tcsetattr(STDIN_FILENO, TCSANOW, &new_tty);
31004e6
 
31004e6
-static void
31004e6
-grub_ncurses_gotoxy (struct grub_term_output *term __attribute__ ((unused)),
31004e6
-		     grub_uint8_t x, grub_uint8_t y)
31004e6
-{
31004e6
-  move (y, x);
31004e6
+  return grub_terminfo_input_init (term);
31004e6
 }
31004e6
 
31004e6
-static void
31004e6
-grub_ncurses_cls (struct grub_term_output *term __attribute__ ((unused)))
31004e6
-{
31004e6
-  clear ();
31004e6
-  refresh ();
31004e6
-}
31004e6
-
31004e6
-static void
31004e6
-grub_ncurses_setcursor (struct grub_term_output *term __attribute__ ((unused)),
31004e6
-			int on)
31004e6
-{
31004e6
-  curs_set (on ? 1 : 0);
31004e6
-}
31004e6
-
31004e6
-static void
31004e6
-grub_ncurses_refresh (struct grub_term_output *term __attribute__ ((unused)))
31004e6
+static grub_err_t
31004e6
+grub_console_fini_input (struct grub_term_input *term
31004e6
+		       __attribute__ ((unused)))
31004e6
 {
31004e6
-  refresh ();
31004e6
+  fcntl (STDIN_FILENO, F_SETFL, original_fl);
31004e6
+  tcsetattr(STDIN_FILENO, TCSANOW, &orig_tty);
31004e6
+  saved_orig = 0;
31004e6
+  return GRUB_ERR_NONE;
31004e6
 }
31004e6
 
31004e6
 static grub_err_t
31004e6
-grub_ncurses_init (struct grub_term_output *term __attribute__ ((unused)))
31004e6
+grub_console_init_output (struct grub_term_output *term)
31004e6
 {
31004e6
-  initscr ();
31004e6
-  raw ();
31004e6
-  noecho ();
31004e6
-  scrollok (stdscr, TRUE);
31004e6
-
31004e6
-  nonl ();
31004e6
-  intrflush (stdscr, FALSE);
31004e6
-  keypad (stdscr, TRUE);
31004e6
-
31004e6
-  if (has_colors ())
31004e6
+  struct winsize size;
31004e6
+  if (ioctl (STDOUT_FILENO, TIOCGWINSZ, &size) >= 0)
31004e6
     {
31004e6
-      start_color ();
31004e6
-
31004e6
-      if ((COLORS >= NUM_COLORS) && (COLOR_PAIRS >= NUM_COLORS * NUM_COLORS))
31004e6
-        {
31004e6
-          int i, j, n;
31004e6
-
31004e6
-          n = 0;
31004e6
-          for (i = 0; i < NUM_COLORS; i++)
31004e6
-            for (j = 0; j < NUM_COLORS; j++)
31004e6
-              init_pair(n++, color_map[j], color_map[i]);
31004e6
-
31004e6
-          use_color = 1;
31004e6
-        }
31004e6
+      grub_console_terminfo_output.width = size.ws_col;
31004e6
+      grub_console_terminfo_output.height = size.ws_row;
31004e6
+    }
31004e6
+  else
31004e6
+    {
31004e6
+      grub_console_terminfo_output.width = 80;
31004e6
+      grub_console_terminfo_output.height = 24;
31004e6
     }
31004e6
 
31004e6
-  return 0;
31004e6
-}
31004e6
+  grub_terminfo_output_init (term);
31004e6
 
31004e6
-static grub_err_t
31004e6
-grub_ncurses_fini (struct grub_term_output *term __attribute__ ((unused)))
31004e6
-{
31004e6
-  endwin ();
31004e6
   return 0;
31004e6
 }
31004e6
 
31004e6
 
31004e6
-static struct grub_term_input grub_ncurses_term_input =
31004e6
+
31004e6
+struct grub_terminfo_input_state grub_console_terminfo_input =
31004e6
+  {
31004e6
+    .readkey = readkey
31004e6
+  };
31004e6
+
31004e6
+struct grub_terminfo_output_state grub_console_terminfo_output =
31004e6
+  {
31004e6
+    .put = put,
31004e6
+    .width = 80,
31004e6
+    .height = 24
31004e6
+  };
31004e6
+
31004e6
+static struct grub_term_input grub_console_term_input =
31004e6
   {
31004e6
     .name = "console",
31004e6
-    .getkey = grub_ncurses_getkey,
31004e6
+    .init = grub_console_init_input,
31004e6
+    .fini = grub_console_fini_input,
31004e6
+    .getkey = grub_terminfo_getkey,
31004e6
+    .data = &grub_console_terminfo_input
31004e6
   };
31004e6
 
31004e6
-static struct grub_term_output grub_ncurses_term_output =
31004e6
+static struct grub_term_output grub_console_term_output =
31004e6
   {
31004e6
     .name = "console",
31004e6
-    .init = grub_ncurses_init,
31004e6
-    .fini = grub_ncurses_fini,
31004e6
-    .putchar = grub_ncurses_putchar,
31004e6
-    .getxy = grub_ncurses_getxy,
31004e6
-    .getwh = grub_ncurses_getwh,
31004e6
-    .gotoxy = grub_ncurses_gotoxy,
31004e6
-    .cls = grub_ncurses_cls,
31004e6
-    .setcolorstate = grub_ncurses_setcolorstate,
31004e6
-    .setcursor = grub_ncurses_setcursor,
31004e6
-    .refresh = grub_ncurses_refresh,
31004e6
-    .flags = GRUB_TERM_CODE_TYPE_ASCII
31004e6
+    .init = grub_console_init_output,
31004e6
+    .putchar = grub_terminfo_putchar,
31004e6
+    .getxy = grub_terminfo_getxy,
31004e6
+    .getwh = grub_terminfo_getwh,
31004e6
+    .gotoxy = grub_terminfo_gotoxy,
31004e6
+    .cls = grub_terminfo_cls,
31004e6
+    .setcolorstate = grub_terminfo_setcolorstate,
31004e6
+    .setcursor = grub_terminfo_setcursor,
31004e6
+    .data = &grub_console_terminfo_output,
31004e6
   };
31004e6
 
31004e6
 void
31004e6
 grub_console_init (void)
31004e6
 {
31004e6
-  grub_term_register_output ("console", &grub_ncurses_term_output);
31004e6
-  grub_term_register_input ("console", &grub_ncurses_term_input);
31004e6
+  const char *cs = nl_langinfo (CODESET);
31004e6
+  if (cs && grub_strcasecmp (cs, "UTF-8"))
31004e6
+    grub_console_term_output.flags = GRUB_TERM_CODE_TYPE_UTF8_LOGICAL;
31004e6
+  else
31004e6
+    grub_console_term_output.flags = GRUB_TERM_CODE_TYPE_ASCII;
31004e6
+  grub_term_register_input ("console", &grub_console_term_input);
31004e6
+  grub_term_register_output ("console", &grub_console_term_output);
31004e6
+  grub_terminfo_init ();
31004e6
+  grub_terminfo_output_register (&grub_console_term_output, "vt100-color");
31004e6
 }
31004e6
 
31004e6
 void
31004e6
 grub_console_fini (void)
31004e6
 {
31004e6
-  grub_ncurses_fini (&grub_ncurses_term_output);
31004e6
+  if (saved_orig)
31004e6
+    {
31004e6
+      fcntl (STDIN_FILENO, F_SETFL, original_fl);
31004e6
+      tcsetattr(STDIN_FILENO, TCSANOW, &orig_tty);
31004e6
+    }
31004e6
+  saved_orig = 0;
31004e6
 }
31004e6
diff --git a/include/grub/terminfo.h b/include/grub/terminfo.h
31004e6
index 20541a9..2bbae1f 100644
31004e6
--- a/include/grub/terminfo.h
31004e6
+++ b/include/grub/terminfo.h
31004e6
@@ -82,9 +82,7 @@ grub_err_t EXPORT_FUNC (grub_terminfo_output_register) (struct grub_term_output
31004e6
 							const char *type);
31004e6
 grub_err_t EXPORT_FUNC (grub_terminfo_output_unregister) (struct grub_term_output *term);
31004e6
 
31004e6
-#ifndef GRUB_MACHINE_EMU
31004e6
 void grub_terminfo_init (void);
31004e6
 void grub_terminfo_fini (void);
31004e6
-#endif
31004e6
 
31004e6
 #endif /* ! GRUB_TERMINFO_HEADER */
31004e6
-- 
31004e6
1.8.2.1
31004e6