Detect line wrap and ESC in pager
PATCH 1/1 Detect line wrap and ESC in pager
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 <[email protected]>
* 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.
kern/term.c +63 -27
@@ -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 ; }
Quoted 3 lines · Christian Franke
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.
Why not with 'q|Q' ? Then it would be consistent with less(1)
Or it could even handle both...
Signature · 5 lines
Robert Millan <GPLv2> I know my rights; I want my phone call! <DRM> What use is a phone call… if you are unable to speak? (as seen on /.)
Quoted 12 lines · Robert Millan
Quoted 4 lines · Christian Franke
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.
Why not with 'q|Q' ? Then it would be consistent with less(1)
Or it could even handle both...
q|Q in less abort the current command. ESC in the patch disables the pager temporarily to give the user the chance to abort the (cat-)command with another ESC.
Christian
Quoted 8 lines · Christian Franke
Quoted 7 lines · Robert Millan
Quoted 4 lines · Christian Franke
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.
Quoted 7 lines
Quoted 5 lines
Why not with 'q|Q' ? Then it would be consistent with less(1)
Or it could even handle both...
q|Q in less abort the current command. ESC in the patch disables the pager temporarily to give the user the chance to abort the (cat-)command with another ESC.
'F' would possibly be more:-) consistent with less(1).
Christian