All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Detect line wrap and ESC in pager
@ 2008-02-14 22:19 Christian Franke
  2008-02-17 13:48 ` Robert Millan
  0 siblings, 1 reply; 4+ messages in thread
From: Christian Franke @ 2008-02-14 22:19 UTC (permalink / raw)
  To: grub-devel

[-- 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;
 }

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-02-21 17:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-02-14 22:19 [PATCH] Detect line wrap and ESC in pager Christian Franke
2008-02-17 13:48 ` Robert Millan
2008-02-17 15:35   ` Christian Franke
2008-02-21 17:43     ` Christian Franke

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.