Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1NQkzd-00083B-6d for mharc-grub-devel@gnu.org; Fri, 01 Jan 2010 12:08:53 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NQkzc-00082Z-B8 for grub-devel@gnu.org; Fri, 01 Jan 2010 12:08:52 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NQkzX-0007zf-2o for grub-devel@gnu.org; Fri, 01 Jan 2010 12:08:51 -0500 Received: from [199.232.76.173] (port=44696 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NQkzW-0007za-Uf for grub-devel@gnu.org; Fri, 01 Jan 2010 12:08:46 -0500 Received: from 197.red-80-32-81.staticip.rima-tde.net ([80.32.81.197]:60472 helo=mail.pina.cat) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NQkzV-0003ol-U7 for grub-devel@gnu.org; Fri, 01 Jan 2010 12:08:46 -0500 Received: from pinux (unknown [192.168.0.78]) by mail.pina.cat (Postfix) with ESMTPA id ECC4C2894B244 for ; Fri, 1 Jan 2010 18:08:43 +0100 (CET) Received: by pinux (Postfix, from userid 1000) id F117E120C7; Fri, 1 Jan 2010 18:08:42 +0100 (CET) Date: Fri, 1 Jan 2010 18:08:42 +0100 From: Carles Pina i Estany To: grub-devel@gnu.org Message-ID: <20100101170842.GA20814@pina.cat> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="YZ5djTAD1cGYuMQK" Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) Subject: [PATCH] help command fix (II) X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 01 Jan 2010 17:08:52 -0000 --YZ5djTAD1cGYuMQK Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hello, Some days ago I sent: http://lists.gnu.org/archive/html/grub-devel/2009-12/msg00433.html As Vladimir commented on IRC: patch was not checking how long the strings appears on the screen (multiple-byte chars, etc.) Find attached a new version, measuring the width of the strings. I have tested it adding some long summary in some commands and works fine (apparently at least). Thank you, -- Carles Pina i Estany http://pinux.info --YZ5djTAD1cGYuMQK Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="help2.patch" === modified file 'ChangeLog' --- ChangeLog 2010-01-01 12:33:45 +0000 +++ ChangeLog 2010-01-01 17:08:20 +0000 @@ -1,3 +1,14 @@ +2010-01-01 Carles Pina i Estany + + * 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 Import from Gnulib. === modified file 'commands/help.c' --- commands/help.c 2009-12-25 23:50:59 +0000 +++ commands/help.c 2010-01-01 17:06:21 +0000 @@ -22,6 +22,8 @@ #include #include #include +#include +#include static grub_err_t grub_cmd_help (grub_extcmd_t ext __attribute__ ((unused)), int argc, @@ -38,19 +40,42 @@ grub_cmd_help (grub_extcmd_t ext __attri 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)); + char *command_help; + const char *summary_translated = _(cmd->summary); + grub_uint32_t *unicode_command_help; + grub_uint32_t *unicode_last_position; + + 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); + + while (grub_getstringwidth (unicode_command_help, + unicode_last_position) > + (GRUB_TERM_WIDTH / 2) - 2) + { + unicode_last_position--; + } - grub_printf ("%s%s", description, (cnt++) % 2 ? "\n" : " "); + grub_print_ucs4 (unicode_command_help, unicode_last_position); + + if ((cnt++) % 2) + { + grub_putchar ('\n'); + } + else + { + grub_print_spaces (GRUB_TERM_WIDTH / 2 - + grub_getstringwidth (unicode_command_help, + unicode_last_position)); + } + + grub_free (command_help); + grub_free (unicode_command_help); } return 0; } === modified file 'include/grub/term.h' --- include/grub/term.h 2009-08-28 13:20:34 +0000 +++ include/grub/term.h 2010-01-01 17:04:10 +0000 @@ -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) === modified file 'normal/menu_text.c' --- normal/menu_text.c 2009-12-27 21:32:52 +0000 +++ normal/menu_text.c 2010-01-01 15:48:11 +0000 @@ -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 (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, 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"); --YZ5djTAD1cGYuMQK--