Hell[o]

> [...]

OK, split fixes in to separate patches this time as requested.

01-grub2-simple_console.patch
==========================

This is a idea how to handle ascii&&cp473&&utf based menus for
diffrent consoles. I added a two term flags GRUB_TERM_SIMPLE_MENU
(ascii menu) and GRUB_TERM_CP437_MENU (cp437 menus) and handle borders
code remap in kern/term.c/grub_putcode() by using new function
remap_border()

For now GRUB_TERM_CP437_MENU is used in i386/pc/console.c, vesafb.c,
vga.c and GRUB_TERM_SIMPLE_MENU is used in i386/pc/serial.c and in
ieee1275/ofconsole.c

I think it would be wise to use ascii border codes for OF as there is
no easy way to check the terminal type (serial, screen) and encoding
(on my ODW normal console seems to use cp437, but framebuffer console
seems to be using something else) Anyway ascii menu looks quite nice
here.

02-grub2-ofconsole_cosmetic.patch
==============================

Two small things here. First make grub_ofconsole_writeesc() use single
grub_ieee1275_write() call and correct '- 1' in grub_ofconsole_getxy()
... hmmm maybe this should go in to [4]

03-grub2-ofconsole_backspace.patch
===============================

My OF seems to send 127 for backspace key this patch handle '127' as
backspace. Now I can use it normaly ;)

04-grub2-ofconsole_fix.patch
========================

Fixed cursor x/y position tracking for ofconsole as currect version
definitly doesn't not work as expect to. I am not sure only about
grub_curr_y -= 4; line as my OF scroll the console +4 lines when reach
last line, but is '4' correct for other OF implementations ?

-- 
--- Marcin 'Morgoth' Kurek ---
diff -urN grub2.org/include/grub/term.h grub2/include/grub/term.h
--- grub2.org/include/grub/term.h	2007-07-22 01:32:22.000000000 +0200
+++ grub2/include/grub/term.h	2007-10-01 19:20:49.734330521 +0200
@@ -51,10 +51,13 @@
 #define GRUB_TERM_NO_EDIT	(1 << 1)
 /* Set when the terminal cannot do fancy things.  */
 #define GRUB_TERM_DUMB		(1 << 2)
+/* Set to use ascii menu borders.  */
+#define GRUB_TERM_SIMPLE_MENU	(1 << 3) 
+/* Set to use cp437 menu borders.  */
+#define GRUB_TERM_CP437_MENU	(1 << 4)
 /* Set when the terminal needs to be initialized.  */
 #define GRUB_TERM_NEED_INIT	(1 << 16)
 
-
 /* Unicode characters for fancy graphics.  */
 #define GRUB_TERM_DISP_LEFT	0x2190
 #define GRUB_TERM_DISP_UP	0x2191
diff -urN grub2.org/kern/term.c grub2/kern/term.c
--- grub2.org/kern/term.c	2007-07-22 01:32:26.000000000 +0200
+++ grub2/kern/term.c	2007-10-01 19:27:23.367330521 +0200
@@ -90,6 +90,94 @@
   return grub_cur_term;
 }
 
+static
+grub_uint32_t remap_border(grub_uint32_t code)
+{
+  if (grub_cur_term->flags & GRUB_TERM_SIMPLE_MENU)
+    {
+      switch (code)
+        {
+        case GRUB_TERM_DISP_LEFT:
+          code = '<';
+          break;
+
+        case GRUB_TERM_DISP_UP:
+          code = '^';
+          break;
+
+        case GRUB_TERM_DISP_RIGHT:
+          code = '>';
+          break;
+
+        case GRUB_TERM_DISP_DOWN:
+          code = 'v';
+          break;
+
+        case GRUB_TERM_DISP_HLINE:
+          code = '-';
+          break;
+
+        case GRUB_TERM_DISP_VLINE:
+          code = '|';
+          break;
+                                                                                                    
+        case GRUB_TERM_DISP_UL:
+        case GRUB_TERM_DISP_UR:
+        case GRUB_TERM_DISP_LL:
+        case GRUB_TERM_DISP_LR:
+          code = '+';
+          break;
+        }
+    }
+  else if(grub_cur_term->flags & GRUB_TERM_CP437_MENU)
+    {
+      switch (code)
+        {
+        case GRUB_TERM_DISP_LEFT:
+          code = 0x1b;
+          break;
+
+        case GRUB_TERM_DISP_UP:
+          code = 0x18;
+          break;
+
+        case GRUB_TERM_DISP_RIGHT:
+          code = 0x1a;
+          break;
+
+        case GRUB_TERM_DISP_DOWN:
+          code = 0x19;
+          break;
+
+        case GRUB_TERM_DISP_HLINE:
+          code = 0xc4;
+          break;
+
+        case GRUB_TERM_DISP_VLINE:
+          code = 0xb3;
+          break;
+                                                                                                    
+        case GRUB_TERM_DISP_UL:
+          code = 0xda;
+          break;
+
+        case GRUB_TERM_DISP_UR:
+          code = 0xbf;
+          break;
+
+        case GRUB_TERM_DISP_LL:
+          code = 0xc0;
+          break;
+
+        case GRUB_TERM_DISP_LR:
+          code = 0xd9;
+          break;
+        }
+    }
+
+  return code;
+}
+
 /* Put a Unicode character.  */
 void
 grub_putcode (grub_uint32_t code)
@@ -106,7 +194,9 @@
 
       return;
     }
-  
+
+  code = remap_border (code);
+
   (grub_cur_term->putchar) (code);
   
   if (code == '\n')
diff -urN grub2.org/term/i386/pc/console.c grub2/term/i386/pc/console.c
--- grub2.org/term/i386/pc/console.c	2007-07-22 01:32:30.000000000 +0200
+++ grub2/term/i386/pc/console.c	2007-10-01 19:30:35.966330521 +0200
@@ -25,58 +25,13 @@
 static grub_uint8_t grub_console_normal_color = 0x7;
 static grub_uint8_t grub_console_highlight_color = 0x70;
 
-static grub_uint32_t
-map_char (grub_uint32_t c)
-{
-  if (c > 0x7f)
-    {
-      /* Map some unicode characters to the VGA font, if possible.  */
-      switch (c)
-	{
-	case 0x2190:	/* left arrow */
-	  c = 0x1b;
-	  break;
-	case 0x2191:	/* up arrow */
-	  c = 0x18;
-	  break;
-	case 0x2192:	/* right arrow */
-	  c = 0x1a;
-	  break;
-	case 0x2193:	/* down arrow */
-	  c = 0x19;
-	  break;
-	case 0x2501:	/* horizontal line */
-	  c = 0xc4;
-	  break;
-	case 0x2503:	/* vertical line */
-	  c = 0xb3;
-	  break;
-	case 0x250F:	/* upper-left corner */
-	  c = 0xda;
-	  break;
-	case 0x2513:	/* upper-right corner */
-	  c = 0xbf;
-	  break;
-	case 0x2517:	/* lower-left corner */
-	  c = 0xc0;
-	  break;
-	case 0x251B:	/* lower-right corner */
-	  c = 0xd9;
-	  break;
-
-	default:
-	  c = '?';
-	  break;
-	}
-    }
-
-  return c;
-}
-
 static void
 grub_console_putchar (grub_uint32_t c)
 {
-  grub_console_real_putchar (map_char (c));
+  /* No Unicode support.  */
+  if (c > 0x7f)
+    c = '?';
+  grub_console_real_putchar (c);
 }
 
 static grub_ssize_t
@@ -133,7 +88,7 @@
     .setcolorstate = grub_console_setcolorstate,
     .setcolor = grub_console_setcolor,
     .setcursor = grub_console_setcursor,
-    .flags = 0,
+    .flags = GRUB_TERM_CP437_MENU,
     .next = 0
   };
 
diff -urN grub2.org/term/i386/pc/serial.c grub2/term/i386/pc/serial.c
--- grub2.org/term/i386/pc/serial.c	2007-07-22 01:32:30.000000000 +0200
+++ grub2/term/i386/pc/serial.c	2007-10-01 19:30:22.478330521 +0200
@@ -324,48 +324,9 @@
   /* Keep track of the cursor.  */
   if (keep_track)
     {
-      /* The serial terminal does not have VGA fonts.  */
+      /* The serial terminal does not support Unicode.  */
       if (c > 0x7F)
-	{
-	  /* Better than nothing.  */
-	  switch (c)
-	    {
-	    case GRUB_TERM_DISP_LEFT:
-	      c = '<';
-	      break;
-	      
-	    case GRUB_TERM_DISP_UP:
-	      c = '^';
-	      break;
-	      
-	    case GRUB_TERM_DISP_RIGHT:
-	      c = '>';
-	      break;
-	      
-	    case GRUB_TERM_DISP_DOWN:
-	      c = 'v';
-	      break;
-	      
-	    case GRUB_TERM_DISP_HLINE:
-	      c = '-';
-	      break;
-	      
-	    case GRUB_TERM_DISP_VLINE:
-	      c = '|';
-	      break;
-	      
-	    case GRUB_TERM_DISP_UL:
-	    case GRUB_TERM_DISP_UR:
-	    case GRUB_TERM_DISP_LL:
-	    case GRUB_TERM_DISP_LR:
-	      c = '+';
-	      break;
-	      
-	    default:
-	      c = '?';
-	      break;
-	    }
-	}
+        c = '?';
       
       switch (c)
 	{
@@ -498,7 +459,7 @@
   .setcolorstate = grub_serial_setcolorstate,
   .setcolor = grub_serial_setcolor,
   .setcursor = grub_serial_setcursor,
-  .flags = 0,
+  .flags = GRUB_TERM_SIMPLE_MENU,
   .next = 0
 };
 
diff -urN grub2.org/term/i386/pc/vesafb.c grub2/term/i386/pc/vesafb.c
--- grub2.org/term/i386/pc/vesafb.c	2007-07-22 01:32:31.000000000 +0200
+++ grub2/term/i386/pc/vesafb.c	2007-10-01 19:37:38.160330521 +0200
@@ -214,45 +214,7 @@
 			       unsigned *width)
 {
   if (code > 0x7f)
-    {
-      /* Map some unicode characters to the VGA font, if possible.  */
-      switch (code)
-	{
-	case 0x2190:	/* left arrow */
-	  code = 0x1b;
-	  break;
-	case 0x2191:	/* up arrow */
-	  code = 0x18;
-	  break;
-	case 0x2192:	/* right arrow */
-	  code = 0x1a;
-	  break;
-	case 0x2193:	/* down arrow */
-	  code = 0x19;
-	  break;
-	case 0x2501:	/* horizontal line */
-	  code = 0xc4;
-	  break;
-	case 0x2503:	/* vertical line */
-	  code = 0xb3;
-	  break;
-	case 0x250F:	/* upper-left corner */
-	  code = 0xda;
-	  break;
-	case 0x2513:	/* upper-right corner */
-	  code = 0xbf;
-	  break;
-	case 0x2517:	/* lower-left corner */
-	  code = 0xc0;
-	  break;
-	case 0x251B:	/* lower-right corner */
-	  code = 0xd9;
-	  break;
-
-	default:
-	  return grub_font_get_glyph (code, bitmap, width);
-	}
-    }
+    return grub_font_get_glyph (code, bitmap, width);
 
   if (bitmap)
     grub_memcpy (bitmap,
@@ -601,7 +563,7 @@
     .setcolorstate = grub_virtual_screen_setcolorstate,
     .setcolor = grub_virtual_screen_setcolor,
     .setcursor = grub_vesafb_setcursor,
-    .flags = 0,
+    .flags = GRUB_TERM_CP437_MENU,
     .next = 0
   };
 
diff -urN grub2.org/term/i386/pc/vga.c grub2/term/i386/pc/vga.c
--- grub2.org/term/i386/pc/vga.c	2007-07-22 01:32:31.000000000 +0200
+++ grub2/term/i386/pc/vga.c	2007-10-01 19:38:10.883330521 +0200
@@ -198,45 +198,7 @@
 get_vga_glyph (grub_uint32_t code, unsigned char bitmap[32], unsigned *width)
 {
   if (code > 0x7f)
-    {
-      /* Map some unicode characters to the VGA font, if possible.  */
-      switch (code)
-	{
-	case 0x2190:	/* left arrow */
-	  code = 0x1b;
-	  break;
-	case 0x2191:	/* up arrow */
-	  code = 0x18;
-	  break;
-	case 0x2192:	/* right arrow */
-	  code = 0x1a;
-	  break;
-	case 0x2193:	/* down arrow */
-	  code = 0x19;
-	  break;
-	case 0x2501:	/* horizontal line */
-	  code = 0xc4;
-	  break;
-	case 0x2503:	/* vertical line */
-	  code = 0xb3;
-	  break;
-	case 0x250F:	/* upper-left corner */
-	  code = 0xda;
-	  break;
-	case 0x2513:	/* upper-right corner */
-	  code = 0xbf;
-	  break;
-	case 0x2517:	/* lower-left corner */
-	  code = 0xc0;
-	  break;
-	case 0x251B:	/* lower-right corner */
-	  code = 0xd9;
-	  break;
-
-	default:
-	  return grub_font_get_glyph (code, bitmap, width);
-	}
-    }
+    return grub_font_get_glyph (code, bitmap, width);
 
   if (bitmap)
     grub_memcpy (bitmap, vga_font + code * CHAR_HEIGHT, CHAR_HEIGHT);
@@ -590,7 +552,7 @@
     .setcolorstate = grub_vga_setcolorstate,
     .setcolor = grub_vga_setcolor,
     .setcursor = grub_vga_setcursor,
-    .flags = 0,
+    .flags = GRUB_TERM_CP437_MENU,
     .next = 0
   };
 
diff -urN grub2.org/term/ieee1275/ofconsole.c grub2/term/ieee1275/ofconsole.c
--- grub2.org/term/ieee1275/ofconsole.c	2007-07-22 11:05:11.000000000 +0200
+++ grub2/term/ieee1275/ofconsole.c	2007-10-01 19:01:49.820330521 +0200
@@ -75,6 +75,7 @@
 grub_ofconsole_putchar (grub_uint32_t c)
 {
   char chr = c;
+  
   if (c == '\n')
     {
       grub_curr_y++;
@@ -86,6 +87,7 @@
       if (grub_curr_x > grub_ofconsole_width)
 	grub_putcode ('\n');
     }
+
   grub_ieee1275_write (stdout_ihandle, &chr, 1, 0);
 }
 
@@ -366,7 +368,7 @@
     .setcolor = grub_ofconsole_setcolor,
     .setcursor = grub_ofconsole_setcursor,
     .refresh = grub_ofconsole_refresh,
-    .flags = 0,
+    .flags = GRUB_TERM_SIMPLE_MENU,
     .next = 0
   };
 
diff -urN grub2.org/util/console.c grub2/util/console.c
--- grub2.org/util/console.c	2007-07-22 01:32:31.000000000 +0200
+++ grub2/util/console.c	2007-10-01 19:01:49.821330521 +0200
@@ -44,47 +44,6 @@
 static void
 grub_ncurses_putchar (grub_uint32_t c)
 {
-  /* Better than nothing.  */
-  switch (c)
-    {
-    case GRUB_TERM_DISP_LEFT:
-      c = '<';
-      break;
-
-    case GRUB_TERM_DISP_UP:
-      c = '^';
-      break;
-
-    case GRUB_TERM_DISP_RIGHT:
-      c = '>';
-      break;
-
-    case GRUB_TERM_DISP_DOWN:
-      c = 'v';
-      break;
-
-    case GRUB_TERM_DISP_HLINE:
-      c = '-';
-      break;
-
-    case GRUB_TERM_DISP_VLINE:
-      c = '|';
-      break;
-
-    case GRUB_TERM_DISP_UL:
-    case GRUB_TERM_DISP_UR:
-    case GRUB_TERM_DISP_LL:
-    case GRUB_TERM_DISP_LR:
-      c = '+';
-      break;
-
-    default:
-      /* ncurses does not support Unicode.  */
-      if (c > 0x7f)
-	c = '?';
-      break;
-    }
-  
   addch (c | grub_console_attr);
 }
 
@@ -302,7 +261,7 @@
     .setcolor = grub_ncurses_setcolor,
     .setcursor = grub_ncurses_setcursor,
     .refresh = grub_ncurses_refresh,
-    .flags = 0,
+    .flags = GRUB_TERM_SIMPLE_MENU,
     .next = 0
   };
 
diff -urN grub2.org/term/ieee1275/ofconsole.c grub2/term/ieee1275/ofconsole.c
--- grub2.org/term/ieee1275/ofconsole.c	2007-10-01 18:02:14.964330521 +0200
+++ grub2/term/ieee1275/ofconsole.c	2007-10-01 18:02:39.000000000 +0200
@@ -63,12 +63,8 @@
 static void
 grub_ofconsole_writeesc (const char *str)
 {
-  while (*str)
-    {
-      char chr = *(str++);
-      grub_ieee1275_write (stdout_ihandle, &chr, 1, 0);
-    }
-  
+  int len = grub_strlen(str);
+  grub_ieee1275_write (stdout_ihandle, str, len, 0);
 }
 
 static void
@@ -219,7 +215,7 @@
 static grub_uint16_t
 grub_ofconsole_getxy (void)
 {
-  return ((grub_curr_x - 1) << 8) | grub_curr_y;
+  return (grub_curr_x << 8) | grub_curr_y;
 }
 
 static grub_uint16_t
diff -urN grub2.org/term/ieee1275/ofconsole.c grub2/term/ieee1275/ofconsole.c
--- grub2.org/term/ieee1275/ofconsole.c	2007-10-01 18:02:39.000000000 +0200
+++ grub2/term/ieee1275/ofconsole.c	2007-10-01 18:06:33.000000000 +0200
@@ -135,43 +135,56 @@
 
   grub_ieee1275_read (stdin_ihandle, &c, 1, &actual);
 
-  if (actual > 0 && c == '\e')
+  if (actual > 0)
     {
-      grub_ieee1275_read (stdin_ihandle, &c, 1, &actual);
-      if (actual <= 0)
-	{
-	  *key = '\e';
-	  return 1;
-	}
+      if (c != '\e')
+      {
+        switch(c)
+        {
+          case 127:
+            /* Backspace */
+            c = '\b';
+            break;
+        }
+      }
+      else
+      {
+        grub_ieee1275_read (stdin_ihandle, &c, 1, &actual);
+        if (actual <= 0)
+	  {
+	    *key = '\e';
+	    return 1;
+	  }
       
-      if (c != 91)
-	return 0;
+        if (c != 91)
+	  return 0;
       
-      grub_ieee1275_read (stdin_ihandle, &c, 1, &actual);
-      if (actual <= 0)
-	return 0;
+        grub_ieee1275_read (stdin_ihandle, &c, 1, &actual);
+        if (actual <= 0)
+	  return 0;
       
-      switch (c)
-	{
-	case 65:
-	  /* Up: Ctrl-p.  */
-	  c = 16; 
-	  break;
-	case 66:
-	  /* Down: Ctrl-n.  */
-	  c = 14;
-	  break;
-	case 67:
-	  /* Right: Ctrl-f.  */
-	  c = 6;
-	  break;
-	case 68:
-	  /* Left: Ctrl-b.  */
-	  c = 2;
-	  break;
-	}
+        switch (c)
+	  {
+	  case 65:
+	    /* Up: Ctrl-p.  */
+	    c = 16; 
+	    break;
+	  case 66:
+	    /* Down: Ctrl-n.  */
+	    c = 14;
+	    break;
+	  case 67:
+	    /* Right: Ctrl-f.  */
+	    c = 6;
+	    break;
+	  case 68:
+	    /* Left: Ctrl-b.  */
+	    c = 2;
+	    break;
+	  }
+      }
     }
-  
+
   *key = c;
   return actual > 0;
 }
diff -urN grub2.org/term/ieee1275/ofconsole.c grub2/term/ieee1275/ofconsole.c
--- grub2.org/term/ieee1275/ofconsole.c	2007-10-01 18:06:33.000000000 +0200
+++ grub2/term/ieee1275/ofconsole.c	2007-10-01 18:11:58.000000000 +0200
@@ -70,20 +70,38 @@
 static void
 grub_ofconsole_putchar (grub_uint32_t c)
 {
-  char chr = c;
-  
-  if (c == '\n')
-    {
+  char chr;
+
+  switch(c)
+  {
+    case '\a':
+      break;            
+    case '\n':
+      grub_putcode ('\r');
       grub_curr_y++;
+      if(grub_curr_y > (grub_ofconsole_height - 1))
+        grub_curr_y -= 4; /* Is this realy correct for all OF versions around ? */
+      break;
+    case '\r':
       grub_curr_x = 0;
-    }
-  else
-    {
+      break;
+    case '\b':
+      if(grub_curr_x > 0)
+        grub_curr_x--;
+      break;
+
+    default:
+      if(c == '\t')
+        c = ' ';
+
+      if (grub_curr_x >= (grub_ofconsole_width - 1))
+        grub_putcode ('\n');
+
       grub_curr_x++;
-      if (grub_curr_x > grub_ofconsole_width)
-	grub_putcode ('\n');
-    }
+      break;
+  }                                                                                                                                                                        
 
+  chr = c;
   grub_ieee1275_write (stdout_ihandle, &chr, 1, 0);
 }
 
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/grub-devel

Reply via email to