From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1JPmQQ-0001Wg-Ck for mharc-grub-devel@gnu.org; Thu, 14 Feb 2008 17:19:26 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JPmQO-0001W6-DD for grub-devel@gnu.org; Thu, 14 Feb 2008 17:19:24 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JPmQL-0001Uu-Gc for grub-devel@gnu.org; Thu, 14 Feb 2008 17:19:23 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JPmQL-0001Um-AI for grub-devel@gnu.org; Thu, 14 Feb 2008 17:19:21 -0500 Received: from mailout02.sul.t-online.de ([194.25.134.17] helo=mailout02.sul.t-online.com) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1JPmQK-000676-Rh for grub-devel@gnu.org; Thu, 14 Feb 2008 17:19:21 -0500 Received: from fwd34.aul.t-online.de by mailout02.sul.t-online.com with smtp id 1JPmQK-00046v-00; Thu, 14 Feb 2008 23:19:20 +0100 Received: from [10.3.2.2] (Sy-gVuZOghcc6cV1vORtCcv92n42iWjClSyq+OenePyrCNWFA+J9+iSGsW1fkwKwVt@[217.235.206.156]) by fwd34.aul.t-online.de with esmtp id 1JPmQA-0Pf2ye0; Thu, 14 Feb 2008 23:19:10 +0100 Message-ID: <47B4BE63.5050703@t-online.de> Date: Thu, 14 Feb 2008 23:19:15 +0100 From: Christian Franke User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.11) Gecko/20071128 SeaMonkey/1.1.7 MIME-Version: 1.0 To: grub-devel@gnu.org Content-Type: multipart/mixed; boundary="------------030008020708030609000305" X-ID: Sy-gVuZOghcc6cV1vORtCcv92n42iWjClSyq+OenePyrCNWFA+J9+iSGsW1fkwKwVt X-TOI-MSGID: 7935a75b-7cb1-4351-aa5f-23ccb63a6cb2 X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 3) Subject: [PATCH] Detect line wrap and ESC in pager X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Feb 2008 22:19:25 -0000 This is a multi-part message in MIME format. --------------030008020708030609000305 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit The pager=1 setting is not effective for files with very long (or no) lines. This patch fixes this and allows to disable the pager with ESC. The latter is useful in conjunction with the "abort cat command" patch. Christian 2008-02-14 Christian Franke * kern/term.c (grub_more_columns): New variable. (grub_putcode): Add detection of line wrap for pager. Disable pager on GRUB_TERM_ESC. (grub_set_more): Initialize grub_more_columns. --------------030008020708030609000305 Content-Type: text/x-patch; name="grub2-term-pager.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="grub2-term-pager.patch" --- grub2.orig/kern/term.c 2007-12-25 23:15:24.671875000 +0100 +++ grub2/kern/term.c 2008-02-14 21:44:49.640625000 +0100 @@ -31,6 +31,9 @@ static grub_term_t grub_cur_term; /* The amount of lines counted by the pager. */ static int grub_more_lines; +/* The last column count seen by the pager. */ +static int grub_more_columns; + /* If the more pager is active. */ static int grub_more; @@ -94,8 +97,6 @@ grub_term_get_current (void) void grub_putcode (grub_uint32_t code) { - int height = grub_getwh () & 255; - if (code == '\t' && grub_cur_term->getxy) { int n; @@ -110,36 +111,70 @@ grub_putcode (grub_uint32_t code) (grub_cur_term->putchar) (code); if (code == '\n') - { - grub_putcode ('\r'); + (grub_cur_term->putchar) ('\r'); - grub_more_lines++; + /* Return if pager is disabled. */ + if (! grub_more) + return; - if (grub_more && grub_more_lines == height - 1) + /* Return on if no line feed and no line wrap. */ + if (code == '\n') + grub_more_columns = 0; + else if (code == '\r') + { + grub_more_columns = 0; + return; + } + else if (grub_cur_term->getxy) + { + int column = grub_getxy () >> 8; + if (column >= grub_more_columns) { - char key; - int pos = grub_getxy (); - - /* Show --MORE-- on the lower left side of the screen. */ - grub_gotoxy (1, height - 1); - grub_setcolorstate (GRUB_TERM_COLOR_HIGHLIGHT); - grub_printf ("--MORE--"); - grub_setcolorstate (GRUB_TERM_COLOR_STANDARD); - - key = grub_getkey (); - - /* Remove the message. */ - grub_gotoxy (1, height - 1); - grub_printf (" "); - grub_gotoxy (pos >> 8, pos & 0xFF); - - /* Scroll one lines or an entire page, depending on the key. */ - if (key == '\r' || key =='\n') - grub_more_lines--; - else - grub_more_lines = 0; + grub_more_columns = column; + return; } + grub_more_columns = column; } + else + return; + + /* Return if line count not exceeded. */ + grub_more_lines++; + int height = grub_getwh () & 0xff; + + if (grub_more_lines < height - 1) + return; + + /* Reset pager to avoid recursion arrives here. */ + int more_lines = grub_more_lines; + grub_more_lines = 0; + grub_more_columns = 0; + + int pos = grub_getxy (); + + /* Show --MORE-- on the lower left side of the screen. */ + grub_gotoxy (1, height - 1); + grub_setcolorstate (GRUB_TERM_COLOR_HIGHLIGHT); + grub_printf ("--MORE--"); + grub_setcolorstate (GRUB_TERM_COLOR_STANDARD); + + int key = GRUB_TERM_ASCII_CHAR (grub_getkey ()); + + /* Remove the message. */ + grub_gotoxy (1, height - 1); + grub_printf (" "); + grub_gotoxy (pos >> 8, pos & 0xFF); + + grub_more_columns = pos >> 8; + + /* Scroll one lines or an entire page, depending on the key. + Turn pager off with ESC to allow command abort with another ESC. */ + if (key == '\r' || key == '\n') + grub_more_lines = more_lines - 0; + else if (key == GRUB_TERM_ESC) + grub_more_lines = -10000; + else + grub_more_lines = 0; } /* Put a character. C is one byte of a UTF-8 stream. @@ -273,4 +308,5 @@ grub_set_more (int onoff) grub_more--; grub_more_lines = 0; + grub_more_columns = grub_getxy () >> 8; } --------------030008020708030609000305--