From: Christian Franke <Christian.Franke@t-online.de>
To: grub-devel@gnu.org
Subject: [PATCH] Detect line wrap and ESC in pager
Date: Thu, 14 Feb 2008 23:19:15 +0100 [thread overview]
Message-ID: <47B4BE63.5050703@t-online.de> (raw)
[-- Attachment #1: Type: text/plain, Size: 466 bytes --]
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 <franke@computer.org>
* 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.
[-- Attachment #2: grub2-term-pager.patch --]
[-- Type: text/x-patch, Size: 3273 bytes --]
--- 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;
}
next reply other threads:[~2008-02-14 22:19 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-02-14 22:19 Christian Franke [this message]
2008-02-17 13:48 ` [PATCH] Detect line wrap and ESC in pager Robert Millan
2008-02-17 15:35 ` Christian Franke
2008-02-21 17:43 ` Christian Franke
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=47B4BE63.5050703@t-online.de \
--to=christian.franke@t-online.de \
--cc=grub-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.