dcavalca / rpms / grub2

Forked from rpms/grub2 3 years ago
Clone

Blame SOURCES/0359-Replace-libcurses-with-our-own-vt100-handling-for-th.patch

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