From 5c56cac95f5597ebfb598db9c974b0525233a265 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 23 Mar 2010 18:06:49 +0100 Subject: [PATCH] Fix few pager bugs --- include/grub/normal.h | 1 + normal/cmdline.c | 3 +++ normal/term.c | 37 +++++++++++++++++++++---------------- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/include/grub/normal.h b/include/grub/normal.h index dbc2be327..ca5bd759a 100644 --- a/include/grub/normal.h +++ b/include/grub/normal.h @@ -113,6 +113,7 @@ void read_terminal_list (void); void grub_set_more (int onoff); int grub_normal_get_char_counter (void); +void grub_normal_reset_more (void); void grub_xputs_normal (const char *str); diff --git a/normal/cmdline.c b/normal/cmdline.c index f10dc47fe..daa0a1adb 100644 --- a/normal/cmdline.c +++ b/normal/cmdline.c @@ -362,6 +362,7 @@ grub_cmdline_get (const char *prompt) grub_putcode ('\n', term); } grub_printf ("%s ", prompt_translated); + grub_normal_reset_more (); { struct cmdline_term *cl_term_cur; @@ -440,6 +441,8 @@ grub_cmdline_get (const char *prompt) print_completion); grub_free (bufu8); + grub_normal_reset_more (); + if (restore) { /* Restore the prompt. */ diff --git a/normal/term.c b/normal/term.c index a8a3e63de..09299f647 100644 --- a/normal/term.c +++ b/normal/term.c @@ -39,9 +39,6 @@ struct term_state static struct term_state *term_states = NULL; -/* The amount of lines counted by the pager. */ -static unsigned grub_more_lines; - /* If the more pager is active. */ static int grub_more; @@ -53,6 +50,14 @@ grub_normal_get_char_counter (void) return grub_normal_char_counter; } +void +grub_normal_reset_more (void) +{ + static struct term_state *state; + for (state = term_states; state; state = state->next) + state->num_lines = 0; +} + static void print_more (void) { @@ -92,14 +97,14 @@ print_more (void) /* Scroll one lines or an entire page, depending on the key. */ - { - static struct term_state *state; - for (state = term_states; state; state = state->next) - if (key == '\r' || key =='\n') - state->num_lines = 0; - else + if (key == '\r' || key =='\n') + grub_normal_reset_more (); + else + { + static struct term_state *state; + for (state = term_states; state; state = state->next) state->num_lines -= 2; - } + } } void @@ -109,8 +114,7 @@ grub_set_more (int onoff) grub_more++; else grub_more--; - - grub_more_lines = 0; + grub_normal_reset_more (); } static grub_uint32_t @@ -529,8 +533,8 @@ print_ucs4_terminal (const grub_uint32_t * str, grub_print_spaces (term, margin_right); grub_putcode ('\n', term); - if (state && state->num_lines++ - >= (grub_ssize_t) grub_term_height (term)) + if (state && ++state->num_lines + >= (grub_ssize_t) grub_term_height (term) - 2) { state->backlog_ucs4 = (ptr == last_space || *ptr == '\n') ? ptr + 1 : ptr; @@ -597,7 +601,8 @@ put_glyphs_terminal (const struct grub_unicode_glyph *visual, if (visual_ptr->base == '\n') grub_print_spaces (term, margin_right); putglyph (visual_ptr, term); - if (state && state->num_lines++ >= (grub_ssize_t) grub_term_height (term)) + if (state && ++state->num_lines + >= (grub_ssize_t) grub_term_height (term) - 2) { state->backlog_glyphs = visual_ptr + 1; state->backlog_len = visual_len - (visual - visual_ptr) - 1; @@ -736,7 +741,7 @@ grub_xputs_normal (const char *str) { int cur; cur = print_ucs4_real (unicode_str, unicode_last_position, 0, 0, - term, 1); + term, grub_more); if (cur) backlog = 1; }