add auto fill mode into grub_putchar, to fix the ">80 characters in one line" problem.

This commit is contained in:
okuji 2000-09-06 12:31:24 +00:00
parent 1b38e4d0cf
commit 6ee3c49cc8
4 changed files with 75 additions and 2 deletions

View file

@ -1,3 +1,23 @@
2000-09-06 OKUJI Yoshinori <okuji@gnu.org>
* stage2/char_io.c [!STAGE1_5] (auto_fill): New variable.
[!STAGE1_5] (get_cmdline): Save AUTO_FILL in SAVED_AUTO_FILL in
the beginning and restore AUTO_FILL before return.
Set AUTO_FILL to one and zero before and after calling
print_completions, respectively.
(grub_putchar) [!STAGE1_5]: Use a static variable COL to track
the position of the cursor. If C is a carriage return, clear
COL. If C is a backspace and COL is positive, decrease COL. If C
is a printable character, increase COL. In this case, if
AUTO_FILL is non-zero and COL is greater than or equal to 79,
put a newline automatically.
* stage2/shared.h (auto_fill): Declared.
* stage2/stage2.c (run_menu): In the menu interface, disable the
auto fill mode (i.e. set AUTO_FILL to zero), and enable it again
when booting an entry.
(cmain): Initialize AUTO_FILL (i.e. set it to one) in the
beginning of the loop.
2000-09-06 OKUJI Yoshinori <okuji@gnu.org>
Add support for "boot previously booted entry by default", based

View file

@ -25,6 +25,10 @@
# include <serial.h>
#endif
#ifndef STAGE1_5
int auto_fill = 1;
#endif
void
print_error (void)
{
@ -269,7 +273,9 @@ get_cmdline (char *prompt, char *cmdline, int maxlen,
char *buf = (char *) CMDLINE_BUF;
/* The kill buffer. */
char *kill_buf = (char *) KILL_BUF;
/* The original state of AUTO_FILL. */
int saved_auto_fill = auto_fill;
/* Nested function definitions for code simplicity. */
/* The forward declarations of nested functions are prefixed
@ -555,6 +561,9 @@ get_cmdline (char *prompt, char *cmdline, int maxlen,
lpos = llen;
grub_strcpy (buf, cmdline);
/* Disable the auto fill mode. */
auto_fill = 0;
cl_init ();
while (ASCII_CHAR (c = getkey ()) != '\n' && ASCII_CHAR (c) != '\r')
@ -607,7 +616,11 @@ get_cmdline (char *prompt, char *cmdline, int maxlen,
completion. */
grub_memmove (completion_buffer, buf + i, lpos - i);
completion_buffer[lpos - i] = 0;
/* Enable the auto fill mode temporarily. */
auto_fill = 1;
ret = print_completions (is_filename, 1);
/* Disable the auto fill mode again. */
auto_fill = 0;
errnum = ERR_NONE;
if (ret >= 0)
@ -621,7 +634,11 @@ get_cmdline (char *prompt, char *cmdline, int maxlen,
the list. */
grub_putchar ('\n');
/* Enable the auto fill mode temporarily. */
auto_fill = 1;
print_completions (is_filename, 0);
/* Disable the auto fill mode again. */
auto_fill = 0;
errnum = ERR_NONE;
}
}
@ -774,6 +791,9 @@ get_cmdline (char *prompt, char *cmdline, int maxlen,
if (readline && lpos < llen)
add_history (cmdline, 0);
/* Restore the auto fill mode. */
auto_fill = saved_auto_fill;
return 0;
}
@ -1056,6 +1076,10 @@ checkkey (void)
void
grub_putchar (int c)
{
#ifndef STAGE1_5
static int col = 0;
#endif
if (c == '\n')
grub_putchar ('\r');
@ -1065,7 +1089,25 @@ grub_putchar (int c)
console_putchar (c);
#else /* ! STAGE1_5 */
/* Track the cursor by software here. */
/* XXX: This doesn't handle horizontal or vertical tabs. */
if (c == '\r')
col = 0;
else if (c == '\b')
{
if (col > 0)
col--;
}
else if (c >= ' ' && c <= '~')
{
/* Fold a line only if AUTO_FILL is true. */
if (auto_fill && col >= 79)
grub_putchar ('\n');
col++;
}
if (terminal & TERMINAL_CONSOLE)
console_putchar (c);

View file

@ -750,6 +750,9 @@ extern kernel_t kernel_type;
extern int show_menu;
extern int grub_timeout;
/* Control the auto fill mode. */
extern int auto_fill;
/* This variable specifies which console should be used. */
extern int terminal;

View file

@ -327,6 +327,9 @@ restart:
/* Only display the menu if the user wants to see it. */
if (show_menu)
{
/* Disable the auto fill mode. */
auto_fill = 0;
init_page ();
#ifndef GRUB_UTIL
# ifdef SUPPORT_SERIAL
@ -682,7 +685,11 @@ restart:
}
/* Attempt to boot an entry. */
boot_entry:
/* Enable the auto fill mode. */
auto_fill = 1;
while (1)
{
cls ();
@ -786,6 +793,7 @@ cmain (void)
/* Never return. */
for (;;)
{
auto_fill = 1;
config_len = 0;
menu_len = 0;
num_entries = 0;