2002-02-08 Yoshinori K. Okuji <okuji@enbug.org>

An internal pager is implemented.

	* stage2/builtins.c (pager_func): New function.
	(builtin_pager): New variable.
	(terminal_func): New option, "--lines=LINES" is added. If this
	option is specified, set MAX_LINES to the value. Otherwise, set
	MAX_LINES to 24.
	(vbeprobe_func): Remove the pager code specific to this
	function.
	(builtin_table): Added a pointer to BUILTIN_PAGER.
	* stage2/char_io.c (max_lines) [!STAGE1_5]: New variable.
	(count_lines) [!STAGE1_5]: Likewise.
	(use_pager) [!STAGE1_5]: Likewise.
	(grub_putchar) [!STAGE1_5]: if C is a newline and COUNT_LINES is
	not -1, count up the number of lines. If it exceeds the maximum
	number of lines minus 2, show a message and wait for input of
	return key. "minus 2" is to reserve space for the message
	printed by this internal pager.
	* stage2/cmdline.c (enter_cmdline): If USE_PAGER is true, set
	COUNT_LINES to zero, before running a command, and reset
	COUNT_LINES to -1 after that.
	* stage2/shared.h (max_lines) [!STAGE1_5]: Declared.
	(count_lines) [!STAGE1_5]: Likewise.
	(use_pager) [!STAGE1_5]: Likewise.
This commit is contained in:
okuji 2002-02-08 01:14:01 +00:00
parent 9f4689e21d
commit b0c95fd0d4
6 changed files with 134 additions and 15 deletions

View file

@ -1,3 +1,30 @@
2002-02-08 Yoshinori K. Okuji <okuji@enbug.org>
An internal pager is implemented.
* stage2/builtins.c (pager_func): New function.
(builtin_pager): New variable.
(terminal_func): New option, "--lines=LINES" is added. If this
option is specified, set MAX_LINES to the value. Otherwise, set
MAX_LINES to 24.
(vbeprobe_func): Remove the pager code specific to this
function.
(builtin_table): Added a pointer to BUILTIN_PAGER.
* stage2/char_io.c (max_lines) [!STAGE1_5]: New variable.
(count_lines) [!STAGE1_5]: Likewise.
(use_pager) [!STAGE1_5]: Likewise.
(grub_putchar) [!STAGE1_5]: if C is a newline and COUNT_LINES is
not -1, count up the number of lines. If it exceeds the maximum
number of lines minus 2, show a message and wait for input of
return key. "minus 2" is to reserve space for the message
printed by this internal pager.
* stage2/cmdline.c (enter_cmdline): If USE_PAGER is true, set
COUNT_LINES to zero, before running a command, and reset
COUNT_LINES to -1 after that.
* stage2/shared.h (max_lines) [!STAGE1_5]: Declared.
(count_lines) [!STAGE1_5]: Likewise.
(use_pager) [!STAGE1_5]: Likewise.
2002-02-08 Yoshinori K. Okuji <okuji@enbug.org>
* stage2/fsys_jfs.c (jfs_read) [STAGE1_5]: Set and reset

6
NEWS
View file

@ -12,6 +12,12 @@ New in 0.92:
"savedefault") are hidden. If you want to see help messages for those
commands, you will have to specify the names to "help" explicitly.
(Also, note that <TAB> still shows all the commands.)
* A built-in, `more'-like pager is added. When a command prints too many
lines to fit the screen, GRUB waits until you hit return key. This
feature can be turned off by the new command "pager".
* The command "terminal" accepts a new option, "--lines=LINES". You can
set the maximum number of lines arbitrarily with this option. If you
don't specify it, the maximum number will be 24.
New in 0.91 - 2002-01-21:
* Support for Linux DAC960 is added.

View file

@ -2568,6 +2568,38 @@ static struct builtin builtin_modulenounzip =
" disabled."
};
/* pager [on|off] */
static int
pager_func (char *arg, int flags)
{
/* If ARG is empty, toggle the flag. */
if (! *arg)
use_pager = ! use_pager;
else if (grub_memcmp (arg, "on", 2) == 0)
use_pager = 1;
else if (grub_memcmp (arg, "off", 3) == 0)
use_pager = 0;
else
{
errnum = ERR_BAD_ARGUMENT;
return 1;
}
grub_printf (" Internal pager is now %s\n", use_pager ? "on" : "off");
return 0;
}
static struct builtin builtin_pager =
{
"pager",
pager_func,
BUILTIN_CMDLINE | BUILTIN_MENU | BUILTIN_HELP_LIST,
"pager [FLAG]",
"Toggle pager mode with no argument. If FLAG is given and its value"
" is `on', turn on the mode. If FLAG is `off', turn off the mode."
};
/* partnew PART TYPE START LEN */
static int
@ -3866,6 +3898,7 @@ terminal_func (char *arg, int flags)
int to = -1;
int dumb = 0;
int saved_terminal = terminal;
int lines = 0;
/* Get GNU-style long options. */
while (1)
@ -3879,6 +3912,20 @@ terminal_func (char *arg, int flags)
if (! safe_parse_maxint (&val, &to))
return 1;
}
else if (grub_memcmp (arg, "--lines=", sizeof ("--lines=") - 1) == 0)
{
char *val = arg + sizeof ("--lines=") - 1;
if (! safe_parse_maxint (&val, &lines))
return 1;
/* Probably less than four is meaningless.... */
if (lines < 4)
{
errnum = ERR_BAD_ARGUMENT;
return 1;
}
}
else
break;
@ -3998,6 +4045,12 @@ terminal_func (char *arg, int flags)
}
#endif /* SUPPORT_SERIAL */
if (lines)
max_lines = lines;
else
/* 24 would be a good default value. */
max_lines = 24;
return 0;
}
@ -4006,14 +4059,14 @@ static struct builtin builtin_terminal =
"terminal",
terminal_func,
BUILTIN_MENU | BUILTIN_CMDLINE | BUILTIN_HELP_LIST,
"terminal [--dumb] [--timeout=SECS] [console] [serial]",
"terminal [--dumb] [--timeout=SECS] [--lines=LINES] [console] [serial]",
"Select a terminal. When serial is specified, wait until you push any key"
" to continue. If both console and serial are specified, the terminal"
" to which you input a key first will be selected. If no argument is"
" specified, print current setting. The option --dumb speicifies that"
" specified, print current setting. The option --dumb specifies that"
" your terminal is dumb, otherwise, vt100-compatibility is assumed."
" If --timeout is present, this command will wait at most for SECS"
" seconds."
" seconds. The option --lines specifies the maximum number of lines."
};
#endif /* SUPPORT_SERIAL || SUPPORT_HERCULES */
@ -4334,7 +4387,6 @@ vbeprobe_func (char *arg, int flags)
struct vbe_controller controller;
unsigned short *mode_list;
int mode_number = -1;
int count = 1;
auto unsigned long vbe_far_ptr_to_linear (unsigned long);
@ -4416,16 +4468,6 @@ vbeprobe_func (char *arg, int flags)
if (mode_number != -1)
break;
count++;
/* XXX: arbitrary. */
if (count == 22)
{
grub_printf ("\nHit any key to continue.\n");
count = 0;
getkey ();
}
}
}
@ -4494,6 +4536,7 @@ struct builtin *builtin_table[] =
#endif /* USE_MD5_PASSWORDS */
&builtin_module,
&builtin_modulenounzip,
&builtin_pager,
&builtin_partnew,
&builtin_parttype,
&builtin_password,

View file

@ -1,7 +1,7 @@
/* char_io.c - basic console input and output */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
* Copyright (C) 1999,2000,2001,2002 Free Software Foundation, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -30,6 +30,9 @@
#ifndef STAGE1_5
int auto_fill = 1;
int max_lines = 24;
int count_lines = -1;
int use_pager = 1;
#endif
void
@ -1123,6 +1126,34 @@ grub_putchar (int c)
col++;
}
else if (c == '\n')
{
/* Internal `more'-like feature. */
if (count_lines != -1)
{
count_lines++;
if (count_lines >= max_lines - 2)
{
int tmp;
/* It's important to disable the feature temporarily, because
the following grub_printf call will print newlines. */
count_lines = -1;
grub_printf ("\n\n[Hit return to continue]");
do
{
tmp = ASCII_CHAR (getkey ());
}
while (tmp != '\n' && tmp != '\r');
grub_printf ("\n\n");
/* Restart to count lines. */
count_lines = 0;
return;
}
}
}
if (terminal & TERMINAL_CONSOLE)
console_putchar (c);

View file

@ -162,9 +162,16 @@ enter_cmdline (char *heap, int forever)
disks. */
buf_drive = -1;
/* Start to count lines, only if the internal pager is in use. */
if (use_pager)
count_lines = 0;
/* Run BUILTIN->FUNC. */
arg = skip_to (1, heap);
(builtin->func) (arg, BUILTIN_CMDLINE);
/* Finish the line count. */
count_lines = -1;
}
}

View file

@ -608,6 +608,11 @@ extern char *password;
extern password_t password_type;
extern int auth;
extern char commands[];
/* For `more'-like feature. */
extern int max_lines;
extern int count_lines;
extern int use_pager;
#endif
#ifndef NO_DECOMPRESSION