Work on multi-out terminal
This commit is contained in:
parent
a2c1332b70
commit
f4c623e170
21 changed files with 707 additions and 570 deletions
477
normal/cmdline.c
477
normal/cmdline.c
|
@ -28,10 +28,10 @@
|
|||
#include <grub/env.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
static char *kill_buf;
|
||||
static grub_uint32_t *kill_buf;
|
||||
|
||||
static int hist_size;
|
||||
static char **hist_lines = 0;
|
||||
static grub_uint32_t **hist_lines = 0;
|
||||
static int hist_pos = 0;
|
||||
static int hist_end = 0;
|
||||
static int hist_used = 0;
|
||||
|
@ -39,7 +39,7 @@ static int hist_used = 0;
|
|||
grub_err_t
|
||||
grub_set_history (int newsize)
|
||||
{
|
||||
char **old_hist_lines = hist_lines;
|
||||
grub_uint32_t **old_hist_lines = hist_lines;
|
||||
hist_lines = grub_malloc (sizeof (char *) * newsize);
|
||||
|
||||
/* Copy the old lines into the new buffer. */
|
||||
|
@ -90,17 +90,42 @@ grub_set_history (int newsize)
|
|||
|
||||
/* Get the entry POS from the history where `0' is the newest
|
||||
entry. */
|
||||
static char *
|
||||
static grub_uint32_t *
|
||||
grub_history_get (int pos)
|
||||
{
|
||||
pos = (hist_pos + pos) % hist_size;
|
||||
return hist_lines[pos];
|
||||
}
|
||||
|
||||
static grub_size_t
|
||||
strlen_ucs4 (const grub_uint32_t *s)
|
||||
{
|
||||
const grub_uint32_t *p = s;
|
||||
|
||||
while (*p)
|
||||
p++;
|
||||
|
||||
return p - s;
|
||||
}
|
||||
|
||||
static grub_uint32_t *
|
||||
strdup_ucs4 (const grub_uint32_t *s)
|
||||
{
|
||||
grub_size_t len;
|
||||
char *p;
|
||||
|
||||
len = strlen_ucs4 (s) + 1;
|
||||
p = (char *) grub_malloc (len * sizeof (grub_uint32_t));
|
||||
if (! p)
|
||||
return 0;
|
||||
|
||||
return grub_memcpy (p, s, len * sizeof (grub_uint32_t));
|
||||
}
|
||||
|
||||
|
||||
/* Insert a new history line S on the top of the history. */
|
||||
static void
|
||||
grub_history_add (char *s)
|
||||
grub_history_add (grub_uint32_t *s)
|
||||
{
|
||||
/* Remove the oldest entry in the history to make room for a new
|
||||
entry. */
|
||||
|
@ -121,16 +146,16 @@ grub_history_add (char *s)
|
|||
hist_pos = hist_size + hist_pos;
|
||||
|
||||
/* Insert into history. */
|
||||
hist_lines[hist_pos] = grub_strdup (s);
|
||||
hist_lines[hist_pos] = strdup_ucs4 (s);
|
||||
}
|
||||
|
||||
/* Replace the history entry on position POS with the string S. */
|
||||
static void
|
||||
grub_history_replace (int pos, char *s)
|
||||
grub_history_replace (int pos, grub_uint32_t *s)
|
||||
{
|
||||
pos = (hist_pos + pos) % hist_size;
|
||||
grub_free (hist_lines[pos]);
|
||||
hist_lines[pos] = grub_strdup (s);
|
||||
hist_lines[pos] = strdup_ucs4 (s);
|
||||
}
|
||||
|
||||
/* A completion hook to print items. */
|
||||
|
@ -176,62 +201,81 @@ print_completion (const char *item, grub_completion_type_t type, int count)
|
|||
grub_printf (" %s", item);
|
||||
}
|
||||
|
||||
/* Get a command-line. If ECHO_CHAR is not zero, echo it instead of input
|
||||
characters. If READLINE is non-zero, readline-like key bindings are
|
||||
available. If ESC is pushed, return zero, otherwise return non-zero. */
|
||||
/* FIXME: The dumb interface is not supported yet. */
|
||||
int
|
||||
grub_cmdline_get (const char *prompt, char cmdline[], unsigned max_len,
|
||||
int echo_char, int readline, int history)
|
||||
struct cmdline_term
|
||||
{
|
||||
unsigned xpos, ypos, ystart, width, height;
|
||||
struct grub_term_output *term;
|
||||
};
|
||||
|
||||
/* Get a command-line. If ESC is pushed, return zero,
|
||||
otherwise return command line. */
|
||||
/* FIXME: The dumb interface is not supported yet. */
|
||||
char *
|
||||
grub_cmdline_get (const char *prompt, unsigned max_len)
|
||||
{
|
||||
unsigned xpos, ypos, ystart;
|
||||
grub_size_t lpos, llen;
|
||||
grub_size_t plen;
|
||||
char buf[max_len];
|
||||
grub_uint32_t buf[max_len];
|
||||
int key;
|
||||
int histpos = 0;
|
||||
auto void cl_insert (const char *str);
|
||||
auto void cl_insert (const grub_uint32_t *str);
|
||||
auto void cl_delete (unsigned len);
|
||||
auto void cl_print (int pos, int c);
|
||||
auto void cl_set_pos (void);
|
||||
auto void cl_print (struct cmdline_term *cl_term, int pos, grub_uint32_t c);
|
||||
auto void cl_set_pos (struct cmdline_term *cl_term);
|
||||
auto void cl_print_all (int pos, grub_uint32_t c);
|
||||
auto void cl_set_pos_all (void);
|
||||
const char *prompt_translated = _(prompt);
|
||||
struct cmdline_term *cl_terms;
|
||||
unsigned nterms;
|
||||
|
||||
void cl_set_pos (void)
|
||||
void cl_set_pos (struct cmdline_term *cl_term)
|
||||
{
|
||||
cl_term->xpos = (plen + lpos) % (cl_term->width - 1);
|
||||
cl_term->ypos = cl_term->ystart + (plen + lpos) / (cl_term->width - 1);
|
||||
cl_term->term->gotoxy (cl_term->xpos, cl_term->ypos);
|
||||
}
|
||||
|
||||
void cl_set_pos_all ()
|
||||
{
|
||||
unsigned i;
|
||||
for (i = 0; i < nterms; i++)
|
||||
cl_set_pos (&cl_terms[i]);
|
||||
}
|
||||
|
||||
void cl_print (struct cmdline_term *cl_term, int pos, grub_uint32_t c)
|
||||
{
|
||||
xpos = (plen + lpos) % 79;
|
||||
ypos = ystart + (plen + lpos) / 79;
|
||||
grub_gotoxy (xpos, ypos);
|
||||
|
||||
grub_refresh ();
|
||||
}
|
||||
|
||||
void cl_print (int pos, int c)
|
||||
{
|
||||
char *p;
|
||||
grub_uint32_t *p;
|
||||
|
||||
for (p = buf + pos; *p; p++)
|
||||
{
|
||||
if (xpos++ > 78)
|
||||
if (cl_term->xpos++ > cl_term->width - 2)
|
||||
{
|
||||
grub_putchar ('\n');
|
||||
grub_putcode ('\n', cl_term->term);
|
||||
|
||||
xpos = 1;
|
||||
if (ypos == (unsigned) (grub_getxy () & 0xFF))
|
||||
ystart--;
|
||||
cl_term->xpos = 1;
|
||||
if (cl_term->ypos == (unsigned) (cl_term->height))
|
||||
cl_term->ystart--;
|
||||
else
|
||||
ypos++;
|
||||
cl_term->ypos++;
|
||||
}
|
||||
|
||||
if (c)
|
||||
grub_putchar (c);
|
||||
grub_putcode (c, cl_term->term);
|
||||
else
|
||||
grub_putchar (*p);
|
||||
grub_putcode (*p, cl_term->term);
|
||||
}
|
||||
}
|
||||
|
||||
void cl_insert (const char *str)
|
||||
void cl_print_all (int pos, grub_uint32_t c)
|
||||
{
|
||||
unsigned i;
|
||||
for (i = 0; i < nterms; i++)
|
||||
cl_print (&cl_terms[i], pos, c);
|
||||
}
|
||||
|
||||
void cl_insert (const grub_uint32_t *str)
|
||||
{
|
||||
grub_size_t len = grub_strlen (str);
|
||||
grub_size_t len = strlen_ucs4 (str);
|
||||
|
||||
if (len + llen < max_len)
|
||||
{
|
||||
|
@ -240,8 +284,8 @@ grub_cmdline_get (const char *prompt, char cmdline[], unsigned max_len,
|
|||
|
||||
llen += len;
|
||||
lpos += len;
|
||||
cl_print (lpos - len, echo_char);
|
||||
cl_set_pos ();
|
||||
cl_print_all (lpos - len, echo_char);
|
||||
cl_set_pos_all ();
|
||||
}
|
||||
|
||||
grub_refresh ();
|
||||
|
@ -254,182 +298,207 @@ grub_cmdline_get (const char *prompt, char cmdline[], unsigned max_len,
|
|||
grub_size_t saved_lpos = lpos;
|
||||
|
||||
lpos = llen - len;
|
||||
cl_set_pos ();
|
||||
cl_print (lpos, ' ');
|
||||
cl_set_pos_all ();
|
||||
cl_print_all (lpos, ' ');
|
||||
lpos = saved_lpos;
|
||||
cl_set_pos ();
|
||||
cl_set_pos_all ();
|
||||
|
||||
grub_memmove (buf + lpos, buf + lpos + len, llen - lpos + 1);
|
||||
llen -= len;
|
||||
cl_print (lpos, echo_char);
|
||||
cl_set_pos ();
|
||||
cl_print_all (lpos, echo_char);
|
||||
cl_set_pos_all ();
|
||||
}
|
||||
|
||||
grub_refresh ();
|
||||
}
|
||||
|
||||
void init_clterm (struct cmdline_term *cl_term_cur)
|
||||
{
|
||||
cl_term_cur->xpos = plen;
|
||||
cl_term_cur->ypos = (cl_term_cur->term->getxy () & 0xFF);
|
||||
cl_term_cur->ystart = cl_term_cur->ypos;
|
||||
cl_term_cur->width = grub_term_width (cl_term_cur->term);
|
||||
cl_term_cur->height = grub_term_height (cl_term_cur->term);
|
||||
}
|
||||
|
||||
void init_clterm_all (void)
|
||||
{
|
||||
unsigned i;
|
||||
for (i = 0; i < nterms; i++)
|
||||
init_clterm (&cl_terms[i]);
|
||||
}
|
||||
|
||||
plen = grub_strlen (prompt_translated);
|
||||
lpos = llen = 0;
|
||||
buf[0] = '\0';
|
||||
|
||||
if ((grub_getxy () >> 8) != 0)
|
||||
grub_putchar ('\n');
|
||||
grub_putchar ('\n');
|
||||
|
||||
grub_printf ("%s", prompt_translated);
|
||||
|
||||
xpos = plen;
|
||||
ystart = ypos = (grub_getxy () & 0xFF);
|
||||
{
|
||||
struct cmdline_term *cl_term_cur;
|
||||
struct grub_term_output *cur;
|
||||
nterms = 0;
|
||||
for (cur = grub_term_outputs; cur; cur = cur->next)
|
||||
if (cur->flags & GRUB_TERM_ACTIVE)
|
||||
nterms++;
|
||||
|
||||
cl_insert (cmdline);
|
||||
cl_terms = grub_malloc (sizeof (cl_terms[0]) * nterms);
|
||||
if (!cl_terms)
|
||||
return grub_errno;
|
||||
cl_term_cur = cl_terms;
|
||||
for (cur = grub_term_outputs; cur; cur = cur->next)
|
||||
if (cur->flags & GRUB_TERM_ACTIVE)
|
||||
{
|
||||
cl_term_cur->term = cur;
|
||||
init_clterm (cl_term_cur);
|
||||
cl_term_cur++;
|
||||
}
|
||||
}
|
||||
|
||||
if (history && hist_used == 0)
|
||||
grub_history_add (buf);
|
||||
|
||||
while ((key = GRUB_TERM_ASCII_CHAR (grub_getkey ())) != '\n' && key != '\r')
|
||||
{
|
||||
if (readline)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
case 1: /* Ctrl-a */
|
||||
lpos = 0;
|
||||
cl_set_pos ();
|
||||
break;
|
||||
|
||||
case 2: /* Ctrl-b */
|
||||
if (lpos > 0)
|
||||
{
|
||||
lpos--;
|
||||
cl_set_pos ();
|
||||
}
|
||||
break;
|
||||
|
||||
case 5: /* Ctrl-e */
|
||||
lpos = llen;
|
||||
cl_set_pos ();
|
||||
break;
|
||||
|
||||
case 6: /* Ctrl-f */
|
||||
if (lpos < llen)
|
||||
{
|
||||
lpos++;
|
||||
cl_set_pos ();
|
||||
}
|
||||
break;
|
||||
|
||||
case 9: /* Ctrl-i or TAB */
|
||||
{
|
||||
char *insert;
|
||||
int restore;
|
||||
|
||||
/* Backup the next character and make it 0 so it will
|
||||
be easy to use string functions. */
|
||||
char backup = buf[lpos];
|
||||
buf[lpos] = '\0';
|
||||
|
||||
|
||||
insert = grub_normal_do_completion (buf, &restore,
|
||||
print_completion);
|
||||
/* Restore the original string. */
|
||||
buf[lpos] = backup;
|
||||
|
||||
if (restore)
|
||||
{
|
||||
/* Restore the prompt. */
|
||||
grub_printf ("\n%s %s", prompt_translated, buf);
|
||||
xpos = plen;
|
||||
ystart = ypos = (grub_getxy () & 0xFF);
|
||||
}
|
||||
|
||||
if (insert)
|
||||
{
|
||||
cl_insert (insert);
|
||||
grub_free (insert);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 11: /* Ctrl-k */
|
||||
if (lpos < llen)
|
||||
{
|
||||
if (kill_buf)
|
||||
grub_free (kill_buf);
|
||||
|
||||
kill_buf = grub_strdup (buf + lpos);
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
|
||||
cl_delete (llen - lpos);
|
||||
}
|
||||
break;
|
||||
|
||||
case 14: /* Ctrl-n */
|
||||
{
|
||||
char *hist;
|
||||
|
||||
lpos = 0;
|
||||
|
||||
if (histpos > 0)
|
||||
{
|
||||
grub_history_replace (histpos, buf);
|
||||
histpos--;
|
||||
}
|
||||
|
||||
cl_delete (llen);
|
||||
hist = grub_history_get (histpos);
|
||||
cl_insert (hist);
|
||||
|
||||
break;
|
||||
}
|
||||
case 16: /* Ctrl-p */
|
||||
{
|
||||
char *hist;
|
||||
|
||||
lpos = 0;
|
||||
|
||||
if (histpos < hist_used - 1)
|
||||
{
|
||||
grub_history_replace (histpos, buf);
|
||||
histpos++;
|
||||
}
|
||||
|
||||
cl_delete (llen);
|
||||
hist = grub_history_get (histpos);
|
||||
|
||||
cl_insert (hist);
|
||||
}
|
||||
break;
|
||||
|
||||
case 21: /* Ctrl-u */
|
||||
if (lpos > 0)
|
||||
{
|
||||
grub_size_t n = lpos;
|
||||
|
||||
if (kill_buf)
|
||||
grub_free (kill_buf);
|
||||
|
||||
kill_buf = grub_malloc (n + 1);
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
if (kill_buf)
|
||||
{
|
||||
grub_memcpy (kill_buf, buf, n);
|
||||
kill_buf[n] = '\0';
|
||||
}
|
||||
|
||||
lpos = 0;
|
||||
cl_set_pos ();
|
||||
cl_delete (n);
|
||||
}
|
||||
break;
|
||||
|
||||
case 25: /* Ctrl-y */
|
||||
if (kill_buf)
|
||||
cl_insert (kill_buf);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
switch (key)
|
||||
{
|
||||
case 1: /* Ctrl-a */
|
||||
lpos = 0;
|
||||
cl_set_pos_all ();
|
||||
break;
|
||||
|
||||
case 2: /* Ctrl-b */
|
||||
if (lpos > 0)
|
||||
{
|
||||
lpos--;
|
||||
cl_set_pos_all ();
|
||||
}
|
||||
break;
|
||||
|
||||
case 5: /* Ctrl-e */
|
||||
lpos = llen;
|
||||
cl_set_pos_all ();
|
||||
break;
|
||||
|
||||
case 6: /* Ctrl-f */
|
||||
if (lpos < llen)
|
||||
{
|
||||
lpos++;
|
||||
cl_set_pos_all ();
|
||||
}
|
||||
break;
|
||||
|
||||
case 9: /* Ctrl-i or TAB */
|
||||
{
|
||||
grub_uint32_t *insert;
|
||||
int restore;
|
||||
|
||||
/* Backup the next character and make it 0 so it will
|
||||
be easy to use string functions. */
|
||||
char backup = buf[lpos];
|
||||
buf[lpos] = '\0';
|
||||
|
||||
|
||||
insert = grub_normal_do_completion (buf, &restore,
|
||||
print_completion);
|
||||
/* Restore the original string. */
|
||||
buf[lpos] = backup;
|
||||
|
||||
if (restore)
|
||||
{
|
||||
/* Restore the prompt. */
|
||||
grub_printf ("\n%s", prompt_translated);
|
||||
init_clterm_all ();
|
||||
cl_print_all (0, 0);
|
||||
}
|
||||
|
||||
if (insert)
|
||||
{
|
||||
cl_insert (insert);
|
||||
grub_free (insert);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 11: /* Ctrl-k */
|
||||
if (lpos < llen)
|
||||
{
|
||||
if (kill_buf)
|
||||
grub_free (kill_buf);
|
||||
|
||||
kill_buf = strdup_ucs4 (buf + lpos);
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
|
||||
cl_delete (llen - lpos);
|
||||
}
|
||||
break;
|
||||
|
||||
case 14: /* Ctrl-n */
|
||||
{
|
||||
grub_uint32_t *hist;
|
||||
|
||||
lpos = 0;
|
||||
|
||||
if (histpos > 0)
|
||||
{
|
||||
grub_history_replace (histpos, buf);
|
||||
histpos--;
|
||||
}
|
||||
|
||||
cl_delete (llen);
|
||||
hist = grub_history_get (histpos);
|
||||
cl_insert (hist);
|
||||
|
||||
break;
|
||||
}
|
||||
case 16: /* Ctrl-p */
|
||||
{
|
||||
grub_uint32_t *hist;
|
||||
|
||||
lpos = 0;
|
||||
|
||||
if (histpos < hist_used - 1)
|
||||
{
|
||||
grub_history_replace (histpos, buf);
|
||||
histpos++;
|
||||
}
|
||||
|
||||
cl_delete (llen);
|
||||
hist = grub_history_get (histpos);
|
||||
|
||||
cl_insert (hist);
|
||||
}
|
||||
break;
|
||||
|
||||
case 21: /* Ctrl-u */
|
||||
if (lpos > 0)
|
||||
{
|
||||
grub_size_t n = lpos;
|
||||
|
||||
if (kill_buf)
|
||||
grub_free (kill_buf);
|
||||
|
||||
kill_buf = grub_malloc (n + 1);
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
if (kill_buf)
|
||||
{
|
||||
grub_memcpy (kill_buf, buf, n);
|
||||
kill_buf[n] = '\0';
|
||||
}
|
||||
|
||||
lpos = 0;
|
||||
cl_set_pos_all ();
|
||||
cl_delete (n);
|
||||
}
|
||||
break;
|
||||
|
||||
case 25: /* Ctrl-y */
|
||||
if (kill_buf)
|
||||
cl_insert (kill_buf);
|
||||
break;
|
||||
|
||||
case '\e':
|
||||
return 0;
|
||||
|
||||
|
@ -437,7 +506,7 @@ grub_cmdline_get (const char *prompt, char cmdline[], unsigned max_len,
|
|||
if (lpos > 0)
|
||||
{
|
||||
lpos--;
|
||||
cl_set_pos ();
|
||||
cl_set_pos_all ();
|
||||
}
|
||||
else
|
||||
break;
|
||||
|
@ -451,7 +520,7 @@ grub_cmdline_get (const char *prompt, char cmdline[], unsigned max_len,
|
|||
default:
|
||||
if (grub_isprint (key))
|
||||
{
|
||||
char str[2];
|
||||
grub_uint32_t str[2];
|
||||
|
||||
str[0] = key;
|
||||
str[1] = '\0';
|
||||
|
@ -464,23 +533,21 @@ grub_cmdline_get (const char *prompt, char cmdline[], unsigned max_len,
|
|||
grub_putchar ('\n');
|
||||
grub_refresh ();
|
||||
|
||||
/* If ECHO_CHAR is NUL, remove leading spaces. */
|
||||
/* Remove leading spaces. */
|
||||
lpos = 0;
|
||||
if (! echo_char)
|
||||
while (buf[lpos] == ' ')
|
||||
lpos++;
|
||||
while (buf[lpos] == ' ')
|
||||
lpos++;
|
||||
|
||||
if (history)
|
||||
{
|
||||
histpos = 0;
|
||||
if (grub_strlen (buf) > 0)
|
||||
if (strlen_ucs4 (buf) > 0)
|
||||
{
|
||||
grub_uint32_t empty[] = { 0 };
|
||||
grub_history_replace (histpos, buf);
|
||||
grub_history_add ("");
|
||||
grub_history_add (empty);
|
||||
}
|
||||
}
|
||||
|
||||
grub_memcpy (cmdline, buf + lpos, llen - lpos + 1);
|
||||
|
||||
return 1;
|
||||
return grub_ucs4_to_utf8_alloc (buf + lpos, llen - lpos + 1);
|
||||
}
|
||||
|
|
|
@ -103,23 +103,36 @@ free_and_return:
|
|||
grub_free (fg_name);
|
||||
}
|
||||
|
||||
static grub_uint8_t color_normal, color_highlight;
|
||||
|
||||
static void
|
||||
set_colors (void)
|
||||
{
|
||||
struct grub_term_output *term;
|
||||
|
||||
for (term = grub_term_outputs; term; term = term->next)
|
||||
{
|
||||
if (! (term->flags & GRUB_TERM_ACTIVE))
|
||||
continue;
|
||||
|
||||
/* Reloads terminal `normal' and `highlight' colors. */
|
||||
if (term->setcolor)
|
||||
term->setcolor (color_normal, color_highlight);
|
||||
|
||||
/* Propagates `normal' color to terminal current color. */
|
||||
if (term->setcolorstate)
|
||||
term->setcolorstate (GRUB_TERM_COLOR_NORMAL);
|
||||
}
|
||||
}
|
||||
|
||||
/* Replace default `normal' colors with the ones specified by user (if any). */
|
||||
char *
|
||||
grub_env_write_color_normal (struct grub_env_var *var __attribute__ ((unused)),
|
||||
const char *val)
|
||||
{
|
||||
grub_uint8_t color_normal, color_highlight;
|
||||
|
||||
/* Use old settings in case grub_parse_color_name_pair() has no effect. */
|
||||
grub_getcolor (&color_normal, &color_highlight);
|
||||
|
||||
grub_parse_color_name_pair (&color_normal, val);
|
||||
|
||||
/* Reloads terminal `normal' and `highlight' colors. */
|
||||
grub_setcolor (color_normal, color_highlight);
|
||||
|
||||
/* Propagates `normal' color to terminal current color. */
|
||||
grub_setcolorstate (GRUB_TERM_COLOR_NORMAL);
|
||||
set_colors ();
|
||||
|
||||
return grub_strdup (val);
|
||||
}
|
||||
|
@ -129,21 +142,9 @@ char *
|
|||
grub_env_write_color_highlight (struct grub_env_var *var __attribute__ ((unused)),
|
||||
const char *val)
|
||||
{
|
||||
grub_uint8_t color_normal, color_highlight;
|
||||
|
||||
/* Use old settings in case grub_parse_color_name_pair() has no effect. */
|
||||
grub_getcolor (&color_normal, &color_highlight);
|
||||
|
||||
grub_parse_color_name_pair (&color_highlight, val);
|
||||
|
||||
/* Reloads terminal `normal' and `highlight' colors. */
|
||||
grub_setcolor (color_normal, color_highlight);
|
||||
|
||||
/* Propagates `normal' color to terminal current color.
|
||||
Note: Using GRUB_TERM_COLOR_NORMAL here rather than
|
||||
GRUB_TERM_COLOR_HIGHLIGHT is intentional. We don't want to switch
|
||||
to highlight state just because color was reloaded. */
|
||||
grub_setcolorstate (GRUB_TERM_COLOR_NORMAL);
|
||||
set_colors ();
|
||||
|
||||
return grub_strdup (val);
|
||||
}
|
||||
|
|
112
normal/main.c
112
normal/main.c
|
@ -372,7 +372,21 @@ read_config_file (const char *config)
|
|||
if (! file)
|
||||
return 0;
|
||||
|
||||
grub_reader_loop (getline);
|
||||
while (1)
|
||||
{
|
||||
char *line;
|
||||
|
||||
/* Print an error, if any. */
|
||||
grub_print_error ();
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
|
||||
if ((getline (&line, 0)) || (! line))
|
||||
break;
|
||||
|
||||
grub_parser_get_current ()->parse_line (line, getline);
|
||||
grub_free (line);
|
||||
}
|
||||
|
||||
grub_file_close (file);
|
||||
|
||||
if (old_parser)
|
||||
|
@ -383,7 +397,7 @@ read_config_file (const char *config)
|
|||
|
||||
/* Initialize the screen. */
|
||||
void
|
||||
grub_normal_init_page (void)
|
||||
grub_normal_init_page (struct grub_term_output *term)
|
||||
{
|
||||
int msg_len;
|
||||
int posx;
|
||||
|
@ -391,13 +405,12 @@ grub_normal_init_page (void)
|
|||
|
||||
char *msg_formatted = grub_malloc (grub_strlen(msg) +
|
||||
grub_strlen(PACKAGE_VERSION));
|
||||
grub_uint32_t *unicode_msg;
|
||||
grub_uint32_t *last_position;
|
||||
|
||||
grub_cls ();
|
||||
|
||||
grub_sprintf (msg_formatted, msg, PACKAGE_VERSION);
|
||||
|
||||
grub_uint32_t *unicode_msg;
|
||||
grub_uint32_t *last_position;
|
||||
|
||||
msg_len = grub_utf8_to_ucs4_alloc (msg_formatted,
|
||||
&unicode_msg, &last_position);
|
||||
|
@ -408,8 +421,8 @@ grub_normal_init_page (void)
|
|||
}
|
||||
|
||||
posx = grub_getstringwidth (unicode_msg, last_position);
|
||||
posx = (GRUB_TERM_WIDTH - posx) / 2;
|
||||
grub_gotoxy (posx, 1);
|
||||
posx = (grub_term_width (term) - posx) / 2;
|
||||
term->gotoxy (posx, 1);
|
||||
|
||||
grub_print_ucs4 (unicode_msg, last_position);
|
||||
grub_printf("\n\n");
|
||||
|
@ -493,48 +506,30 @@ quit:
|
|||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
grub_cmdline_run (int nested)
|
||||
{
|
||||
grub_reader_t reader;
|
||||
grub_err_t err = GRUB_ERR_NONE;
|
||||
|
||||
err = grub_auth_check_authentication (NULL);
|
||||
|
||||
if (err)
|
||||
{
|
||||
grub_print_error ();
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
return;
|
||||
}
|
||||
|
||||
reader = grub_reader_get_current ();
|
||||
|
||||
reader_nested = nested;
|
||||
if (reader->init)
|
||||
reader->init ();
|
||||
grub_reader_loop (0);
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_normal_reader_init (void)
|
||||
{
|
||||
grub_normal_init_page ();
|
||||
grub_setcursor (1);
|
||||
|
||||
struct grub_term_output *term;
|
||||
const char *msg = _("Minimal BASH-like line editing is supported. For "
|
||||
"the first word, TAB lists possible command completions. Anywhere "
|
||||
"else TAB lists possible device or file completions. %s");
|
||||
|
||||
const char *msg_esc = _("ESC at any time exits.");
|
||||
|
||||
char *msg_formatted = grub_malloc (sizeof (char) * (grub_strlen (msg) +
|
||||
grub_strlen(msg_esc) + 1));
|
||||
|
||||
grub_sprintf (msg_formatted, msg, reader_nested ? msg_esc : "");
|
||||
grub_print_message_indented (msg_formatted, 3, STANDARD_MARGIN);
|
||||
grub_puts ("\n");
|
||||
|
||||
for (term = grub_term_outputs; term; term = term->next)
|
||||
{
|
||||
if (! (term->flags & GRUB_TERM_ACTIVE))
|
||||
continue;
|
||||
grub_normal_init_page (term);
|
||||
if (term->setcursor)
|
||||
term->setcursor (1);
|
||||
|
||||
grub_print_message_indented (msg_formatted, 3, STANDARD_MARGIN);
|
||||
grub_puts ("\n");
|
||||
}
|
||||
grub_free (msg_formatted);
|
||||
|
||||
return 0;
|
||||
|
@ -567,12 +562,40 @@ grub_normal_read_line (char **line, int cont)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static struct grub_reader grub_normal_reader =
|
||||
{
|
||||
.name = "normal",
|
||||
.init = grub_normal_reader_init,
|
||||
.read_line = grub_normal_read_line
|
||||
};
|
||||
void
|
||||
grub_cmdline_run (int nested)
|
||||
{
|
||||
grub_err_t err = GRUB_ERR_NONE;
|
||||
|
||||
err = grub_auth_check_authentication (NULL);
|
||||
|
||||
if (err)
|
||||
{
|
||||
grub_print_error ();
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
return;
|
||||
}
|
||||
|
||||
reader_nested = nested;
|
||||
|
||||
grub_normal_reader_init ();
|
||||
|
||||
while (1)
|
||||
{
|
||||
char *line;
|
||||
|
||||
/* Print an error, if any. */
|
||||
grub_print_error ();
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
|
||||
grub_normal_read_line (&line, 0);
|
||||
if (! line)
|
||||
continue;
|
||||
|
||||
grub_parser_get_current ()->parse_line (line, grub_normal_read_line);
|
||||
grub_free (line);
|
||||
}
|
||||
}
|
||||
|
||||
static char *
|
||||
grub_env_write_pager (struct grub_env_var *var __attribute__ ((unused)),
|
||||
|
@ -592,8 +615,6 @@ GRUB_MOD_INIT(normal)
|
|||
|
||||
grub_set_history (GRUB_DEFAULT_HISTORY_SIZE);
|
||||
|
||||
grub_reader_register ("normal", &grub_normal_reader);
|
||||
grub_reader_set_current (&grub_normal_reader);
|
||||
grub_register_variable_hook ("pager", 0, grub_env_write_pager);
|
||||
|
||||
/* Register a command "normal" for the rescue mode. */
|
||||
|
@ -612,7 +633,6 @@ GRUB_MOD_INIT(normal)
|
|||
GRUB_MOD_FINI(normal)
|
||||
{
|
||||
grub_set_history (0);
|
||||
grub_reader_unregister (&grub_normal_reader);
|
||||
grub_register_variable_hook ("pager", 0, 0);
|
||||
grub_fs_autoload_hook = 0;
|
||||
free_handler_list ();
|
||||
|
|
128
normal/term.c
Normal file
128
normal/term.c
Normal file
|
@ -0,0 +1,128 @@
|
|||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2002,2003,2005,2007,2008,2009 Free Software Foundation, Inc.
|
||||
*
|
||||
* GRUB is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GRUB is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/* The amount of lines counted by the pager. */
|
||||
static int grub_more_lines;
|
||||
|
||||
/* If the more pager is active. */
|
||||
static int grub_more;
|
||||
|
||||
static void
|
||||
process_newline (void)
|
||||
{
|
||||
if (code == '\n')
|
||||
{
|
||||
grub_putcode ('\r');
|
||||
|
||||
grub_more_lines++;
|
||||
|
||||
if (grub_more && grub_more_lines == height - 1)
|
||||
{
|
||||
char key;
|
||||
int pos = term->getxy ();
|
||||
|
||||
/* Show --MORE-- on the lower left side of the screen. */
|
||||
term->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. */
|
||||
term->gotoxy (1, height - 1);
|
||||
grub_printf (" ");
|
||||
term->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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
grub_set_more (int onoff)
|
||||
{
|
||||
if (onoff == 1)
|
||||
grub_more++;
|
||||
else
|
||||
grub_more--;
|
||||
|
||||
grub_more_lines = 0;
|
||||
}
|
||||
|
||||
void
|
||||
grub_puts_terminal (const char *str, struct grub_term_output *term)
|
||||
{
|
||||
grub_uint32_t code;
|
||||
grub_ssize_t ret;
|
||||
const char *ptr = str;
|
||||
unsigned i;
|
||||
|
||||
while (*ptr)
|
||||
{
|
||||
ret = grub_utf8_to_ucs4 (&code, 1, ptr,
|
||||
grub_strlen (ptr), &ptr);
|
||||
if (ret < 0)
|
||||
{
|
||||
grub_putcode ('?', term);
|
||||
ptr++;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
grub_putcode (code, term);
|
||||
}
|
||||
}
|
||||
|
||||
grub_uint16_t *
|
||||
grub_term_save_pos (void)
|
||||
{
|
||||
struct grub_term_output *cur;
|
||||
unsigned cnt = 0;
|
||||
grub_uint16_t *ret, *ptr;
|
||||
|
||||
for (cur = grub_term_outputs; cur; cur = cur->next)
|
||||
if (cur->flags & GRUB_TERM_ACTIVE)
|
||||
cnt++;
|
||||
|
||||
ret = grub_malloc (cnt * sizeof (ret[0]));
|
||||
if (!ret)
|
||||
return NULL;
|
||||
|
||||
for (cur = grub_term_outputs; cur; cur = cur->next)
|
||||
if (cur->flags & GRUB_TERM_ACTIVE)
|
||||
*ptr++ = cur->getxy ();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void
|
||||
grub_term_restore_pos (grub_uint16_t *pos)
|
||||
{
|
||||
struct grub_term_output *cur;
|
||||
|
||||
if (!pos)
|
||||
return;
|
||||
|
||||
for (cur = grub_term_outputs; cur; cur = cur->next)
|
||||
if (cur->flags & GRUB_TERM_ACTIVE)
|
||||
cur->gotoxy ((*ptr & 0xff00) >> 8, *ptr & 0xff);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue