]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
2010-01-01 Carles Pina i Estany <carles@pina.cat>
authorcarles <carles@pinux>
Fri, 1 Jan 2010 17:58:00 +0000 (18:58 +0100)
committercarles <carles@pinux>
Fri, 1 Jan 2010 17:58:00 +0000 (18:58 +0100)
* commands/help.c: Include `grub/mm.h' and `grub/normal.h'.
(grub_cmd_help): Print the cmd->name before the cmd->summary. Cut the
string using string width.
* normal/menu_text.c (grub_print_message_indented): Use
grub_print_spaces and not print_spaces.
(print_timeout): Likewise.
(print_spaces): Move to...
* include/grub/term.h: ... here. Change the name to grub_print_spaces.

ChangeLog
commands/help.c
include/grub/term.h
normal/menu_text.c

index 17ddc35d75f57b4b82ca3338c924a145b1af4d24..634e8aad08cf3ab1a0a29537678db7d9948d412d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2010-01-01  Carles Pina i Estany  <carles@pina.cat>
+
+       * commands/help.c: Include `grub/mm.h' and `grub/normal.h'.
+       (grub_cmd_help): Print the cmd->name before the cmd->summary. Cut the
+       string using string width.
+       * normal/menu_text.c (grub_print_message_indented): Use
+       grub_print_spaces and not print_spaces.
+       (print_timeout): Likewise.
+       (print_spaces): Move to...
+       * include/grub/term.h: ... here. Change the name to grub_print_spaces.
+
 2010-01-01  Robert Millan  <rmh.grub@aybabtu.com>
 
        Import from Gnulib.
index 9f0ee752829b1aedbbe7d95f25f11746e4428969..8ca2a5b1fa8d7db1af172f3d7da80f1f5b366705 100644 (file)
@@ -22,6 +22,8 @@
 #include <grub/term.h>
 #include <grub/extcmd.h>
 #include <grub/i18n.h>
+#include <grub/mm.h>
+#include <grub/normal.h>
 
 static grub_err_t
 grub_cmd_help (grub_extcmd_t ext __attribute__ ((unused)), int argc,
@@ -38,19 +40,46 @@ grub_cmd_help (grub_extcmd_t ext __attribute__ ((unused)), int argc,
       if ((cmd->prio & GRUB_PRIO_LIST_FLAG_ACTIVE) &&
          (cmd->flags & GRUB_COMMAND_FLAG_CMDLINE))
        {
-         char description[GRUB_TERM_WIDTH / 2];
-         const char* summary_translated = _(cmd->summary);
-         int desclen = grub_strlen (summary_translated);
-
-         /* Make a string with a length of GRUB_TERM_WIDTH / 2 - 1 filled
-            with the description followed by spaces.  */
-         grub_memset (description, ' ', GRUB_TERM_WIDTH / 2 - 1);
-         description[GRUB_TERM_WIDTH / 2 - 1] = '\0';
-         grub_memcpy (description, summary_translated,
-                      (desclen < GRUB_TERM_WIDTH / 2 - 1
-                       ? desclen : GRUB_TERM_WIDTH / 2 - 1));
-
-         grub_printf ("%s%s", description, (cnt++) % 2 ? "\n" : " ");
+         char *command_help;
+         int stringwidth;
+         grub_uint32_t *unicode_command_help;
+         grub_uint32_t *unicode_last_position;
+         grub_uint32_t *unicode_last_screen_position;
+         const char *summary_translated = _(cmd->summary);
+
+         command_help = grub_malloc (grub_strlen (cmd->name) +
+                                     sizeof (" ") - 1 +
+                                     grub_strlen (summary_translated));
+                                     
+         grub_sprintf(command_help, "%s %s", cmd->name, summary_translated);
+
+         grub_utf8_to_ucs4_alloc (command_help, &unicode_command_help,
+                                  &unicode_last_position);
+         
+         unicode_last_screen_position = unicode_command_help;
+
+         stringwidth = 0;
+
+         while (unicode_last_screen_position < unicode_last_position && 
+                stringwidth < ((GRUB_TERM_WIDTH / 2) - 2))
+           {
+             stringwidth += grub_getcharwidth (*unicode_last_screen_position);
+             unicode_last_screen_position++;
+           }
+
+         grub_print_ucs4 (unicode_command_help, unicode_last_screen_position);
+         
+         if ((cnt++) % 2)
+           {
+             grub_putchar ('\n');
+           }
+           else
+           {
+             grub_print_spaces (GRUB_TERM_WIDTH / 2 - stringwidth);
+           }
+         
+         grub_free (command_help);
+         grub_free (unicode_command_help);
        }
       return 0;
     }
index 316d75390467388ad0261ebe7b4491f9c2065696..ec158353d0055455f4ddaf8bb3f1b0ba8fd73f0a 100644 (file)
@@ -299,6 +299,14 @@ int EXPORT_FUNC(grub_getcursor) (void);
 void EXPORT_FUNC(grub_refresh) (void);
 void EXPORT_FUNC(grub_set_more) (int onoff);
 
+static inline void
+grub_print_spaces (int number_spaces)
+{
+  while (--number_spaces >= 0)
+      grub_putchar (' ');
+}
+
+
 /* For convenience.  */
 #define GRUB_TERM_ASCII_CHAR(c)        ((c) & 0xff)
 
index bac15f32b8feea85327d7adfc5890c7cf26370e8..5c985fa6f5e79e9ede73e328f555cca1b90d152d 100644 (file)
@@ -45,14 +45,6 @@ grub_wait_after_message (void)
   grub_putchar ('\n');
 }
 
-static void
-print_spaces (int number_spaces)
-{
-  int i;
-  for (i = 0; i < number_spaces; i++)
-    grub_putchar (' ');
-}
-
 void
 grub_print_ucs4 (const grub_uint32_t * str,
                 const grub_uint32_t * last_position)
@@ -149,7 +141,7 @@ grub_print_message_indented (const char *msg, int margin_left, int margin_right)
            (grub_uint32_t *) last_position : next_new_line + line_len;
        }
 
-      print_spaces (margin_left);
+      grub_print_spaces (margin_left);
       grub_print_ucs4 (current_position, next_new_line);
 
       next_new_line++;
@@ -405,7 +397,7 @@ print_timeout (int timeout, int offset)
  
   int posx;
   posx = grub_getxy() >> 8;
-  print_spaces (GRUB_TERM_WIDTH - posx - 1);
+  grub_print_spaces (GRUB_TERM_WIDTH - posx - 1);
 
   grub_gotoxy (GRUB_TERM_CURSOR_X, GRUB_TERM_FIRST_ENTRY_Y + offset);
   grub_refresh ();
@@ -495,7 +487,7 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot)
          if (timeout >= 0)
            {
              grub_gotoxy (0, GRUB_TERM_HEIGHT - 3);
-              print_spaces (GRUB_TERM_WIDTH - 1);
+              grub_print_spaces (GRUB_TERM_WIDTH - 1);
 
              grub_env_unset ("timeout");
              grub_env_unset ("fallback");