2005-09-03 16:54:27 +00:00
|
|
|
|
/* terminfo.c - simple terminfo module */
|
|
|
|
|
/*
|
|
|
|
|
* GRUB -- GRand Unified Bootloader
|
2007-07-21 23:32:33 +00:00
|
|
|
|
* Copyright (C) 2003,2004,2005,2007 Free Software Foundation, Inc.
|
2005-09-03 16:54:27 +00:00
|
|
|
|
*
|
2007-07-21 23:32:33 +00:00
|
|
|
|
* GRUB is free software: you can redistribute it and/or modify
|
2005-09-03 16:54:27 +00:00
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
2007-07-21 23:32:33 +00:00
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
2005-09-03 16:54:27 +00:00
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
2007-07-21 23:32:33 +00:00
|
|
|
|
* GRUB is distributed in the hope that it will be useful,
|
2005-09-03 16:54:27 +00:00
|
|
|
|
* 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
|
2007-07-21 23:32:33 +00:00
|
|
|
|
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
2005-09-03 16:54:27 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This file contains various functions dealing with different
|
|
|
|
|
* terminal capabilities. For example, vt52 and vt100.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <grub/types.h>
|
|
|
|
|
#include <grub/misc.h>
|
|
|
|
|
#include <grub/mm.h>
|
|
|
|
|
#include <grub/err.h>
|
|
|
|
|
#include <grub/dl.h>
|
|
|
|
|
#include <grub/term.h>
|
|
|
|
|
#include <grub/terminfo.h>
|
|
|
|
|
#include <grub/tparm.h>
|
2010-09-20 14:27:33 +00:00
|
|
|
|
#include <grub/extcmd.h>
|
2010-05-01 18:28:07 +00:00
|
|
|
|
#include <grub/i18n.h>
|
2010-05-06 19:11:59 +00:00
|
|
|
|
#include <grub/time.h>
|
2012-09-14 10:23:36 +00:00
|
|
|
|
#if defined(__powerpc__) && defined(GRUB_MACHINE_IEEE1275)
|
2012-06-20 20:19:26 +00:00
|
|
|
|
#include <grub/ieee1275/ieee1275.h>
|
|
|
|
|
#endif
|
2005-09-03 16:54:27 +00:00
|
|
|
|
|
2011-04-11 21:01:51 +00:00
|
|
|
|
GRUB_MOD_LICENSE ("GPLv3+");
|
|
|
|
|
|
2013-05-10 12:07:41 +00:00
|
|
|
|
#define ANSI_CSI 0x9b
|
|
|
|
|
#define ANSI_CSI_STR "\x9b"
|
2011-05-13 14:36:05 +00:00
|
|
|
|
|
2010-05-07 13:44:43 +00:00
|
|
|
|
static struct grub_term_output *terminfo_outputs;
|
2005-09-03 16:54:27 +00:00
|
|
|
|
|
|
|
|
|
/* Get current terminfo name. */
|
|
|
|
|
char *
|
2010-05-07 13:44:43 +00:00
|
|
|
|
grub_terminfo_get_current (struct grub_term_output *term)
|
2005-09-03 16:54:27 +00:00
|
|
|
|
{
|
2010-05-07 13:44:43 +00:00
|
|
|
|
struct grub_terminfo_output_state *data
|
|
|
|
|
= (struct grub_terminfo_output_state *) term->data;
|
|
|
|
|
return data->name;
|
2005-09-03 16:54:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Free *PTR and set *PTR to NULL, to prevent double-free. */
|
|
|
|
|
static void
|
|
|
|
|
grub_terminfo_free (char **ptr)
|
|
|
|
|
{
|
|
|
|
|
grub_free (*ptr);
|
|
|
|
|
*ptr = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-07 13:44:43 +00:00
|
|
|
|
static void
|
|
|
|
|
grub_terminfo_all_free (struct grub_term_output *term)
|
|
|
|
|
{
|
|
|
|
|
struct grub_terminfo_output_state *data
|
|
|
|
|
= (struct grub_terminfo_output_state *) term->data;
|
|
|
|
|
|
|
|
|
|
/* Free previously allocated memory. */
|
|
|
|
|
grub_terminfo_free (&data->name);
|
|
|
|
|
grub_terminfo_free (&data->gotoxy);
|
|
|
|
|
grub_terminfo_free (&data->cls);
|
|
|
|
|
grub_terminfo_free (&data->reverse_video_on);
|
|
|
|
|
grub_terminfo_free (&data->reverse_video_off);
|
|
|
|
|
grub_terminfo_free (&data->cursor_on);
|
|
|
|
|
grub_terminfo_free (&data->cursor_off);
|
|
|
|
|
}
|
|
|
|
|
|
2005-09-03 16:54:27 +00:00
|
|
|
|
/* Set current terminfo type. */
|
|
|
|
|
grub_err_t
|
2010-05-07 13:44:43 +00:00
|
|
|
|
grub_terminfo_set_current (struct grub_term_output *term,
|
|
|
|
|
const char *str)
|
2005-09-03 16:54:27 +00:00
|
|
|
|
{
|
2010-05-07 13:44:43 +00:00
|
|
|
|
struct grub_terminfo_output_state *data
|
|
|
|
|
= (struct grub_terminfo_output_state *) term->data;
|
2005-09-03 16:54:27 +00:00
|
|
|
|
/* TODO
|
|
|
|
|
* Lookup user specified terminfo type. If found, set term variables
|
|
|
|
|
* as appropriate. Otherwise return an error.
|
|
|
|
|
*
|
|
|
|
|
* How should this be done?
|
|
|
|
|
* a. A static table included in this module.
|
|
|
|
|
* - I do not like this idea.
|
|
|
|
|
* b. A table stored in the configuration directory.
|
|
|
|
|
* - Users must convert their terminfo settings if we have not already.
|
|
|
|
|
* c. Look for terminfo files in the configuration directory.
|
|
|
|
|
* - /usr/share/terminfo is 6.3M on my system.
|
|
|
|
|
* - /usr/share/terminfo is not on most users boot partition.
|
|
|
|
|
* + Copying the terminfo files you want to use to the grub
|
|
|
|
|
* configuration directory is easier then (b).
|
|
|
|
|
* d. Your idea here.
|
|
|
|
|
*/
|
|
|
|
|
|
2010-05-07 13:44:43 +00:00
|
|
|
|
grub_terminfo_all_free (term);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
|
2005-09-03 16:54:27 +00:00
|
|
|
|
if (grub_strcmp ("vt100", str) == 0)
|
|
|
|
|
{
|
2010-05-07 13:44:43 +00:00
|
|
|
|
data->name = grub_strdup ("vt100");
|
|
|
|
|
data->gotoxy = grub_strdup ("\e[%i%p1%d;%p2%dH");
|
|
|
|
|
data->cls = grub_strdup ("\e[H\e[J");
|
|
|
|
|
data->reverse_video_on = grub_strdup ("\e[7m");
|
|
|
|
|
data->reverse_video_off = grub_strdup ("\e[m");
|
|
|
|
|
data->cursor_on = grub_strdup ("\e[?25h");
|
|
|
|
|
data->cursor_off = grub_strdup ("\e[?25l");
|
|
|
|
|
data->setcolor = NULL;
|
|
|
|
|
return grub_errno;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (grub_strcmp ("vt100-color", str) == 0)
|
|
|
|
|
{
|
|
|
|
|
data->name = grub_strdup ("vt100-color");
|
|
|
|
|
data->gotoxy = grub_strdup ("\e[%i%p1%d;%p2%dH");
|
|
|
|
|
data->cls = grub_strdup ("\e[H\e[J");
|
|
|
|
|
data->reverse_video_on = grub_strdup ("\e[7m");
|
|
|
|
|
data->reverse_video_off = grub_strdup ("\e[m");
|
|
|
|
|
data->cursor_on = grub_strdup ("\e[?25h");
|
|
|
|
|
data->cursor_off = grub_strdup ("\e[?25l");
|
|
|
|
|
data->setcolor = grub_strdup ("\e[3%p1%dm\e[4%p2%dm");
|
|
|
|
|
return grub_errno;
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-13 14:36:05 +00:00
|
|
|
|
if (grub_strcmp ("arc", str) == 0)
|
|
|
|
|
{
|
|
|
|
|
data->name = grub_strdup ("arc");
|
2013-05-10 12:07:41 +00:00
|
|
|
|
data->gotoxy = grub_strdup (ANSI_CSI_STR "%i%p1%d;%p2%dH");
|
|
|
|
|
data->cls = grub_strdup (ANSI_CSI_STR "2J");
|
|
|
|
|
data->reverse_video_on = grub_strdup (ANSI_CSI_STR "7m");
|
|
|
|
|
data->reverse_video_off = grub_strdup (ANSI_CSI_STR "0m");
|
2011-05-13 14:36:05 +00:00
|
|
|
|
data->cursor_on = 0;
|
|
|
|
|
data->cursor_off = 0;
|
2013-05-10 12:07:41 +00:00
|
|
|
|
data->setcolor = grub_strdup (ANSI_CSI_STR "3%p1%dm"
|
|
|
|
|
ANSI_CSI_STR "4%p2%dm");
|
2011-05-13 14:36:05 +00:00
|
|
|
|
return grub_errno;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-18 09:52:19 +00:00
|
|
|
|
if (grub_strcmp ("ieee1275", str) == 0
|
|
|
|
|
|| grub_strcmp ("ieee1275-nocursor", str) == 0)
|
2010-05-07 13:44:43 +00:00
|
|
|
|
{
|
|
|
|
|
data->name = grub_strdup ("ieee1275");
|
|
|
|
|
data->gotoxy = grub_strdup ("\e[%i%p1%d;%p2%dH");
|
|
|
|
|
/* Clear the screen. Using serial console, screen(1) only recognizes the
|
|
|
|
|
* ANSI escape sequence. Using video console, Apple Open Firmware
|
|
|
|
|
* (version 3.1.1) only recognizes the literal ^L. So use both. */
|
|
|
|
|
data->cls = grub_strdup ("\e[2J");
|
|
|
|
|
data->reverse_video_on = grub_strdup ("\e[7m");
|
|
|
|
|
data->reverse_video_off = grub_strdup ("\e[m");
|
2012-09-18 09:52:19 +00:00
|
|
|
|
if (grub_strcmp ("ieee1275", str) == 0)
|
|
|
|
|
{
|
|
|
|
|
data->cursor_on = grub_strdup ("\e[?25h");
|
|
|
|
|
data->cursor_off = grub_strdup ("\e[?25l");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
data->cursor_on = 0;
|
|
|
|
|
data->cursor_off = 0;
|
|
|
|
|
}
|
2010-05-07 13:44:43 +00:00
|
|
|
|
data->setcolor = grub_strdup ("\e[3%p1%dm\e[4%p2%dm");
|
|
|
|
|
return grub_errno;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (grub_strcmp ("dumb", str) == 0)
|
|
|
|
|
{
|
|
|
|
|
data->name = grub_strdup ("dumb");
|
|
|
|
|
data->gotoxy = NULL;
|
|
|
|
|
data->cls = NULL;
|
|
|
|
|
data->reverse_video_on = NULL;
|
|
|
|
|
data->reverse_video_off = NULL;
|
|
|
|
|
data->cursor_on = NULL;
|
|
|
|
|
data->cursor_off = NULL;
|
|
|
|
|
data->setcolor = NULL;
|
2005-09-03 16:54:27 +00:00
|
|
|
|
return grub_errno;
|
|
|
|
|
}
|
2009-06-10 21:04:23 +00:00
|
|
|
|
|
2012-02-12 14:25:25 +00:00
|
|
|
|
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("unknown terminfo type `%s'"),
|
|
|
|
|
str);
|
2005-09-03 16:54:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-05-07 13:44:43 +00:00
|
|
|
|
grub_err_t
|
|
|
|
|
grub_terminfo_output_register (struct grub_term_output *term,
|
|
|
|
|
const char *type)
|
|
|
|
|
{
|
|
|
|
|
grub_err_t err;
|
|
|
|
|
struct grub_terminfo_output_state *data;
|
|
|
|
|
|
|
|
|
|
err = grub_terminfo_set_current (term, type);
|
|
|
|
|
|
|
|
|
|
if (err)
|
|
|
|
|
return err;
|
|
|
|
|
|
|
|
|
|
data = (struct grub_terminfo_output_state *) term->data;
|
|
|
|
|
data->next = terminfo_outputs;
|
|
|
|
|
terminfo_outputs = term;
|
|
|
|
|
|
|
|
|
|
return GRUB_ERR_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
grub_err_t
|
|
|
|
|
grub_terminfo_output_unregister (struct grub_term_output *term)
|
|
|
|
|
{
|
|
|
|
|
struct grub_term_output **ptr;
|
|
|
|
|
|
|
|
|
|
for (ptr = &terminfo_outputs; *ptr;
|
|
|
|
|
ptr = &((struct grub_terminfo_output_state *) (*ptr)->data)->next)
|
|
|
|
|
if (*ptr == term)
|
|
|
|
|
{
|
|
|
|
|
grub_terminfo_all_free (term);
|
|
|
|
|
*ptr = ((struct grub_terminfo_output_state *) (*ptr)->data)->next;
|
|
|
|
|
return GRUB_ERR_NONE;
|
|
|
|
|
}
|
2012-02-12 18:16:49 +00:00
|
|
|
|
return grub_error (GRUB_ERR_BUG, "terminal not found");
|
2010-05-07 13:44:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-09-03 16:54:27 +00:00
|
|
|
|
/* Wrapper for grub_putchar to write strings. */
|
|
|
|
|
static void
|
2010-05-07 13:44:43 +00:00
|
|
|
|
putstr (struct grub_term_output *term, const char *str)
|
2005-09-03 16:54:27 +00:00
|
|
|
|
{
|
2010-05-07 13:44:43 +00:00
|
|
|
|
struct grub_terminfo_output_state *data
|
|
|
|
|
= (struct grub_terminfo_output_state *) term->data;
|
2005-09-03 16:54:27 +00:00
|
|
|
|
while (*str)
|
2010-07-17 23:37:19 +00:00
|
|
|
|
data->put (term, *str++);
|
2010-05-07 13:44:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-10-19 21:59:32 +00:00
|
|
|
|
struct grub_term_coordinate
|
2010-05-07 13:44:43 +00:00
|
|
|
|
grub_terminfo_getxy (struct grub_term_output *term)
|
|
|
|
|
{
|
|
|
|
|
struct grub_terminfo_output_state *data
|
|
|
|
|
= (struct grub_terminfo_output_state *) term->data;
|
|
|
|
|
|
2013-10-19 21:59:32 +00:00
|
|
|
|
return data->pos;
|
2010-05-07 13:44:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
grub_terminfo_gotoxy (struct grub_term_output *term,
|
2013-10-19 21:59:32 +00:00
|
|
|
|
struct grub_term_coordinate pos)
|
2010-05-07 13:44:43 +00:00
|
|
|
|
{
|
|
|
|
|
struct grub_terminfo_output_state *data
|
|
|
|
|
= (struct grub_terminfo_output_state *) term->data;
|
|
|
|
|
|
2013-10-19 21:59:32 +00:00
|
|
|
|
if (pos.x > grub_term_width (term) || pos.y > grub_term_height (term))
|
2010-03-15 20:14:11 +00:00
|
|
|
|
{
|
2013-10-19 21:59:32 +00:00
|
|
|
|
grub_error (GRUB_ERR_BUG, "invalid point (%u,%u)", pos.x, pos.y);
|
2010-05-07 13:44:43 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (data->gotoxy)
|
2013-10-19 21:59:32 +00:00
|
|
|
|
putstr (term, grub_terminfo_tparm (data->gotoxy, pos.y, pos.x));
|
2010-05-07 13:44:43 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
2013-10-19 21:59:32 +00:00
|
|
|
|
if ((pos.y == data->pos.y) && (pos.x == data->pos.x - 1))
|
2010-07-17 23:37:19 +00:00
|
|
|
|
data->put (term, '\b');
|
2010-03-15 20:14:11 +00:00
|
|
|
|
}
|
2010-05-07 13:44:43 +00:00
|
|
|
|
|
2013-10-19 21:59:32 +00:00
|
|
|
|
data->pos = pos;
|
2005-09-03 16:54:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-05-07 13:44:43 +00:00
|
|
|
|
/* Clear the screen. */
|
2005-09-03 16:54:27 +00:00
|
|
|
|
void
|
2010-05-07 13:44:43 +00:00
|
|
|
|
grub_terminfo_cls (struct grub_term_output *term)
|
2005-09-03 16:54:27 +00:00
|
|
|
|
{
|
2010-05-07 13:44:43 +00:00
|
|
|
|
struct grub_terminfo_output_state *data
|
|
|
|
|
= (struct grub_terminfo_output_state *) term->data;
|
|
|
|
|
|
|
|
|
|
putstr (term, grub_terminfo_tparm (data->cls));
|
2013-10-19 21:59:32 +00:00
|
|
|
|
grub_terminfo_gotoxy (term, (struct grub_term_coordinate) { 0, 0 });
|
2005-09-03 16:54:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2010-05-07 13:44:43 +00:00
|
|
|
|
grub_terminfo_setcolorstate (struct grub_term_output *term,
|
|
|
|
|
const grub_term_color_state state)
|
2005-09-03 16:54:27 +00:00
|
|
|
|
{
|
2010-05-07 13:44:43 +00:00
|
|
|
|
struct grub_terminfo_output_state *data
|
|
|
|
|
= (struct grub_terminfo_output_state *) term->data;
|
|
|
|
|
|
|
|
|
|
if (data->setcolor)
|
|
|
|
|
{
|
|
|
|
|
int fg;
|
|
|
|
|
int bg;
|
2010-05-07 16:07:05 +00:00
|
|
|
|
/* Map from VGA to terminal colors. */
|
|
|
|
|
const int colormap[8]
|
|
|
|
|
= { 0, /* Black. */
|
|
|
|
|
4, /* Blue. */
|
|
|
|
|
2, /* Green. */
|
|
|
|
|
6, /* Cyan. */
|
|
|
|
|
1, /* Red. */
|
|
|
|
|
5, /* Magenta. */
|
|
|
|
|
3, /* Yellow. */
|
|
|
|
|
7, /* White. */
|
|
|
|
|
};
|
2010-05-07 13:44:43 +00:00
|
|
|
|
|
|
|
|
|
switch (state)
|
|
|
|
|
{
|
|
|
|
|
case GRUB_TERM_COLOR_STANDARD:
|
|
|
|
|
case GRUB_TERM_COLOR_NORMAL:
|
2013-01-21 16:53:41 +00:00
|
|
|
|
fg = grub_term_normal_color & 0x0f;
|
|
|
|
|
bg = grub_term_normal_color >> 4;
|
2010-05-07 13:44:43 +00:00
|
|
|
|
break;
|
|
|
|
|
case GRUB_TERM_COLOR_HIGHLIGHT:
|
2013-01-21 16:53:41 +00:00
|
|
|
|
fg = grub_term_highlight_color & 0x0f;
|
|
|
|
|
bg = grub_term_highlight_color >> 4;
|
2010-05-07 13:44:43 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-07 16:07:05 +00:00
|
|
|
|
putstr (term, grub_terminfo_tparm (data->setcolor, colormap[fg & 7],
|
|
|
|
|
colormap[bg & 7]));
|
2010-05-07 13:44:43 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (state)
|
|
|
|
|
{
|
|
|
|
|
case GRUB_TERM_COLOR_STANDARD:
|
|
|
|
|
case GRUB_TERM_COLOR_NORMAL:
|
|
|
|
|
putstr (term, grub_terminfo_tparm (data->reverse_video_off));
|
|
|
|
|
break;
|
|
|
|
|
case GRUB_TERM_COLOR_HIGHLIGHT:
|
|
|
|
|
putstr (term, grub_terminfo_tparm (data->reverse_video_on));
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2005-09-03 16:54:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2010-05-07 13:44:43 +00:00
|
|
|
|
grub_terminfo_setcursor (struct grub_term_output *term, const int on)
|
2005-09-03 16:54:27 +00:00
|
|
|
|
{
|
2010-05-07 13:44:43 +00:00
|
|
|
|
struct grub_terminfo_output_state *data
|
|
|
|
|
= (struct grub_terminfo_output_state *) term->data;
|
|
|
|
|
|
|
|
|
|
if (on)
|
|
|
|
|
putstr (term, grub_terminfo_tparm (data->cursor_on));
|
|
|
|
|
else
|
|
|
|
|
putstr (term, grub_terminfo_tparm (data->cursor_off));
|
2005-09-03 16:54:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-05-07 13:44:43 +00:00
|
|
|
|
/* The terminfo version of putchar. */
|
2005-09-03 16:54:27 +00:00
|
|
|
|
void
|
2010-05-07 13:44:43 +00:00
|
|
|
|
grub_terminfo_putchar (struct grub_term_output *term,
|
|
|
|
|
const struct grub_unicode_glyph *c)
|
2005-09-03 16:54:27 +00:00
|
|
|
|
{
|
2010-05-07 13:44:43 +00:00
|
|
|
|
struct grub_terminfo_output_state *data
|
|
|
|
|
= (struct grub_terminfo_output_state *) term->data;
|
|
|
|
|
|
|
|
|
|
/* Keep track of the cursor. */
|
|
|
|
|
switch (c->base)
|
|
|
|
|
{
|
|
|
|
|
case '\a':
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case '\b':
|
|
|
|
|
case 127:
|
2013-10-19 21:59:32 +00:00
|
|
|
|
if (data->pos.x > 0)
|
|
|
|
|
data->pos.x--;
|
2010-05-07 13:44:43 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case '\n':
|
2013-10-19 21:59:32 +00:00
|
|
|
|
if (data->pos.y < grub_term_height (term) - 1)
|
|
|
|
|
data->pos.y++;
|
2010-05-07 13:44:43 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case '\r':
|
2013-10-19 21:59:32 +00:00
|
|
|
|
data->pos.x = 0;
|
2010-05-07 13:44:43 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
2013-10-19 21:59:32 +00:00
|
|
|
|
if ((int) data->pos.x + c->estimated_width >= (int) grub_term_width (term) + 1)
|
2010-05-07 13:44:43 +00:00
|
|
|
|
{
|
2013-10-19 21:59:32 +00:00
|
|
|
|
data->pos.x = 0;
|
|
|
|
|
if (data->pos.y < grub_term_height (term) - 1)
|
|
|
|
|
data->pos.y++;
|
2010-07-17 23:37:19 +00:00
|
|
|
|
data->put (term, '\r');
|
|
|
|
|
data->put (term, '\n');
|
2010-05-07 13:44:43 +00:00
|
|
|
|
}
|
2013-10-19 21:59:32 +00:00
|
|
|
|
data->pos.x += c->estimated_width;
|
2010-05-07 13:44:43 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-17 23:37:19 +00:00
|
|
|
|
data->put (term, c->base);
|
2005-09-03 16:54:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-10-19 21:59:32 +00:00
|
|
|
|
struct grub_term_coordinate
|
2010-09-20 14:27:33 +00:00
|
|
|
|
grub_terminfo_getwh (struct grub_term_output *term)
|
|
|
|
|
{
|
|
|
|
|
struct grub_terminfo_output_state *data
|
|
|
|
|
= (struct grub_terminfo_output_state *) term->data;
|
|
|
|
|
|
2013-10-19 21:59:32 +00:00
|
|
|
|
return data->size;
|
2010-09-20 14:27:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-05-07 13:44:43 +00:00
|
|
|
|
static void
|
2010-07-17 23:37:19 +00:00
|
|
|
|
grub_terminfo_readkey (struct grub_term_input *term, int *keys, int *len,
|
|
|
|
|
int (*readkey) (struct grub_term_input *term))
|
2010-05-06 19:11:59 +00:00
|
|
|
|
{
|
|
|
|
|
int c;
|
|
|
|
|
|
|
|
|
|
#define CONTINUE_READ \
|
|
|
|
|
{ \
|
|
|
|
|
grub_uint64_t start; \
|
|
|
|
|
/* On 9600 we have to wait up to 12 milliseconds. */ \
|
|
|
|
|
start = grub_get_time_ms (); \
|
|
|
|
|
do \
|
2010-07-17 23:37:19 +00:00
|
|
|
|
c = readkey (term); \
|
2012-04-26 16:57:22 +00:00
|
|
|
|
while (c == -1 && grub_get_time_ms () - start < 100); \
|
2010-05-06 19:11:59 +00:00
|
|
|
|
if (c == -1) \
|
|
|
|
|
return; \
|
|
|
|
|
\
|
|
|
|
|
keys[*len] = c; \
|
|
|
|
|
(*len)++; \
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-17 23:37:19 +00:00
|
|
|
|
c = readkey (term);
|
2010-05-06 19:11:59 +00:00
|
|
|
|
if (c < 0)
|
|
|
|
|
{
|
|
|
|
|
*len = 0;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
*len = 1;
|
|
|
|
|
keys[0] = c;
|
2013-05-10 12:07:41 +00:00
|
|
|
|
if (c != ANSI_CSI && c != '\e')
|
2010-05-06 19:11:59 +00:00
|
|
|
|
{
|
|
|
|
|
/* Backspace: Ctrl-h. */
|
|
|
|
|
if (c == 0x7f)
|
|
|
|
|
c = '\b';
|
2011-01-05 00:25:01 +00:00
|
|
|
|
if (c < 0x20 && c != '\t' && c!= '\b' && c != '\n' && c != '\r')
|
|
|
|
|
c = GRUB_TERM_CTRL | (c - 1 + 'a');
|
2010-05-06 19:11:59 +00:00
|
|
|
|
*len = 1;
|
|
|
|
|
keys[0] = c;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
static struct
|
|
|
|
|
{
|
|
|
|
|
char key;
|
2010-08-18 23:07:50 +00:00
|
|
|
|
unsigned ascii;
|
2010-05-06 19:11:59 +00:00
|
|
|
|
}
|
|
|
|
|
three_code_table[] =
|
|
|
|
|
{
|
2010-08-18 23:07:50 +00:00
|
|
|
|
{'4', GRUB_TERM_KEY_DC},
|
|
|
|
|
{'A', GRUB_TERM_KEY_UP},
|
|
|
|
|
{'B', GRUB_TERM_KEY_DOWN},
|
|
|
|
|
{'C', GRUB_TERM_KEY_RIGHT},
|
|
|
|
|
{'D', GRUB_TERM_KEY_LEFT},
|
|
|
|
|
{'F', GRUB_TERM_KEY_END},
|
|
|
|
|
{'H', GRUB_TERM_KEY_HOME},
|
|
|
|
|
{'K', GRUB_TERM_KEY_END},
|
|
|
|
|
{'P', GRUB_TERM_KEY_DC},
|
|
|
|
|
{'?', GRUB_TERM_KEY_PPAGE},
|
2011-05-13 14:38:23 +00:00
|
|
|
|
{'/', GRUB_TERM_KEY_NPAGE},
|
|
|
|
|
{'@', GRUB_TERM_KEY_INSERT},
|
2010-05-06 19:11:59 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static struct
|
|
|
|
|
{
|
|
|
|
|
char key;
|
2010-08-18 23:07:50 +00:00
|
|
|
|
unsigned ascii;
|
2010-05-06 19:11:59 +00:00
|
|
|
|
}
|
|
|
|
|
four_code_table[] =
|
|
|
|
|
{
|
2010-08-18 23:07:50 +00:00
|
|
|
|
{'1', GRUB_TERM_KEY_HOME},
|
|
|
|
|
{'3', GRUB_TERM_KEY_DC},
|
|
|
|
|
{'5', GRUB_TERM_KEY_PPAGE},
|
|
|
|
|
{'6', GRUB_TERM_KEY_NPAGE}
|
2010-05-06 19:11:59 +00:00
|
|
|
|
};
|
2011-05-13 14:38:23 +00:00
|
|
|
|
char fx_key[] =
|
|
|
|
|
{ 'P', 'Q', 'w', 'x', 't', 'u',
|
|
|
|
|
'q', 'r', 'p', 'M', 'A', 'B' };
|
|
|
|
|
unsigned fx_code[] =
|
|
|
|
|
{ GRUB_TERM_KEY_F1, GRUB_TERM_KEY_F2, GRUB_TERM_KEY_F3,
|
|
|
|
|
GRUB_TERM_KEY_F4, GRUB_TERM_KEY_F5, GRUB_TERM_KEY_F6,
|
|
|
|
|
GRUB_TERM_KEY_F7, GRUB_TERM_KEY_F8, GRUB_TERM_KEY_F9,
|
|
|
|
|
GRUB_TERM_KEY_F10, GRUB_TERM_KEY_F11, GRUB_TERM_KEY_F12 };
|
2010-05-06 19:11:59 +00:00
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
|
|
if (c == '\e')
|
|
|
|
|
{
|
|
|
|
|
CONTINUE_READ;
|
|
|
|
|
|
2013-09-27 22:55:38 +00:00
|
|
|
|
if (c == 'O')
|
|
|
|
|
{
|
|
|
|
|
CONTINUE_READ;
|
|
|
|
|
|
|
|
|
|
switch (c)
|
|
|
|
|
{
|
|
|
|
|
case 'H':
|
|
|
|
|
keys[0] = GRUB_TERM_KEY_HOME;
|
|
|
|
|
*len = 1;
|
|
|
|
|
return;
|
|
|
|
|
case 'F':
|
|
|
|
|
keys[0] = GRUB_TERM_KEY_END;
|
|
|
|
|
*len = 1;
|
|
|
|
|
return;
|
|
|
|
|
default:
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-06 19:11:59 +00:00
|
|
|
|
if (c != '[')
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CONTINUE_READ;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE (three_code_table); i++)
|
|
|
|
|
if (three_code_table[i].key == c)
|
|
|
|
|
{
|
|
|
|
|
keys[0] = three_code_table[i].ascii;
|
|
|
|
|
*len = 1;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-13 14:38:23 +00:00
|
|
|
|
switch (c)
|
|
|
|
|
{
|
|
|
|
|
case 'O':
|
|
|
|
|
CONTINUE_READ;
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE (fx_key); i++)
|
|
|
|
|
if (fx_key[i] == c)
|
|
|
|
|
{
|
|
|
|
|
keys[0] = fx_code[i];
|
|
|
|
|
*len = 1;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
case '0':
|
2010-05-06 19:11:59 +00:00
|
|
|
|
{
|
2011-05-13 14:38:23 +00:00
|
|
|
|
int num = 0;
|
2010-05-06 19:11:59 +00:00
|
|
|
|
CONTINUE_READ;
|
2011-05-13 14:38:23 +00:00
|
|
|
|
if (c != '0' && c != '1')
|
2010-05-06 19:11:59 +00:00
|
|
|
|
return;
|
2011-05-13 14:38:23 +00:00
|
|
|
|
num = (c - '0') * 10;
|
|
|
|
|
CONTINUE_READ;
|
|
|
|
|
if (c < '0' || c > '9')
|
|
|
|
|
return;
|
|
|
|
|
num += (c - '0');
|
|
|
|
|
if (num == 0 || num > 12)
|
|
|
|
|
return;
|
|
|
|
|
CONTINUE_READ;
|
|
|
|
|
if (c != 'q')
|
|
|
|
|
return;
|
|
|
|
|
keys[0] = fx_code[num - 1];
|
2010-05-06 19:11:59 +00:00
|
|
|
|
*len = 1;
|
|
|
|
|
return;
|
2011-05-13 14:38:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE (four_code_table); i++)
|
|
|
|
|
if (four_code_table[i].key == c)
|
|
|
|
|
{
|
|
|
|
|
CONTINUE_READ;
|
|
|
|
|
if (c != '~')
|
|
|
|
|
return;
|
2013-09-27 23:03:31 +00:00
|
|
|
|
keys[0] = four_code_table[i].ascii;
|
2011-05-13 14:38:23 +00:00
|
|
|
|
*len = 1;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
2010-05-06 19:11:59 +00:00
|
|
|
|
}
|
|
|
|
|
#undef CONTINUE_READ
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-23 10:07:49 +00:00
|
|
|
|
/* The terminfo version of getkey. */
|
2010-05-07 13:44:43 +00:00
|
|
|
|
int
|
2010-08-23 10:07:49 +00:00
|
|
|
|
grub_terminfo_getkey (struct grub_term_input *termi)
|
2010-05-07 13:44:43 +00:00
|
|
|
|
{
|
|
|
|
|
struct grub_terminfo_input_state *data
|
|
|
|
|
= (struct grub_terminfo_input_state *) (termi->data);
|
|
|
|
|
if (data->npending)
|
2010-08-23 10:07:49 +00:00
|
|
|
|
{
|
2012-04-26 16:55:39 +00:00
|
|
|
|
int ret;
|
2010-08-23 10:07:49 +00:00
|
|
|
|
data->npending--;
|
2012-04-26 16:55:39 +00:00
|
|
|
|
ret = data->input_buf[0];
|
|
|
|
|
grub_memmove (data->input_buf, data->input_buf + 1, data->npending
|
|
|
|
|
* sizeof (data->input_buf[0]));
|
|
|
|
|
return ret;
|
2010-08-23 10:07:49 +00:00
|
|
|
|
}
|
2010-05-07 13:44:43 +00:00
|
|
|
|
|
2010-07-17 23:37:19 +00:00
|
|
|
|
grub_terminfo_readkey (termi, data->input_buf,
|
|
|
|
|
&data->npending, data->readkey);
|
2010-05-07 13:44:43 +00:00
|
|
|
|
|
2012-09-14 10:23:36 +00:00
|
|
|
|
#if defined(__powerpc__) && defined(GRUB_MACHINE_IEEE1275)
|
2012-06-20 20:19:26 +00:00
|
|
|
|
if (data->npending == 1 && data->input_buf[0] == '\e'
|
|
|
|
|
&& grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_BROKEN_REPEAT)
|
|
|
|
|
&& grub_get_time_ms () - data->last_key_time < 1000
|
|
|
|
|
&& (data->last_key & GRUB_TERM_EXTENDED))
|
|
|
|
|
{
|
|
|
|
|
data->npending = 0;
|
|
|
|
|
data->last_key_time = grub_get_time_ms ();
|
|
|
|
|
return data->last_key;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2010-05-07 13:44:43 +00:00
|
|
|
|
if (data->npending)
|
2010-08-23 10:07:49 +00:00
|
|
|
|
{
|
2012-04-26 16:55:39 +00:00
|
|
|
|
int ret;
|
2010-08-23 10:07:49 +00:00
|
|
|
|
data->npending--;
|
2012-04-26 16:55:39 +00:00
|
|
|
|
ret = data->input_buf[0];
|
2012-09-14 10:23:36 +00:00
|
|
|
|
#if defined(__powerpc__) && defined(GRUB_MACHINE_IEEE1275)
|
2012-06-20 20:19:26 +00:00
|
|
|
|
if (grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_BROKEN_REPEAT))
|
|
|
|
|
{
|
|
|
|
|
data->last_key = ret;
|
|
|
|
|
data->last_key_time = grub_get_time_ms ();
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2012-04-26 16:55:39 +00:00
|
|
|
|
grub_memmove (data->input_buf, data->input_buf + 1, data->npending
|
|
|
|
|
* sizeof (data->input_buf[0]));
|
|
|
|
|
return ret;
|
2010-08-23 10:07:49 +00:00
|
|
|
|
}
|
2010-05-07 13:44:43 +00:00
|
|
|
|
|
2010-08-23 10:53:42 +00:00
|
|
|
|
return GRUB_TERM_NO_KEY;
|
2010-05-07 13:44:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
grub_err_t
|
|
|
|
|
grub_terminfo_input_init (struct grub_term_input *termi)
|
|
|
|
|
{
|
|
|
|
|
struct grub_terminfo_input_state *data
|
|
|
|
|
= (struct grub_terminfo_input_state *) (termi->data);
|
|
|
|
|
data->npending = 0;
|
|
|
|
|
|
|
|
|
|
return GRUB_ERR_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-05 11:23:06 +00:00
|
|
|
|
grub_err_t
|
|
|
|
|
grub_terminfo_output_init (struct grub_term_output *term)
|
|
|
|
|
{
|
|
|
|
|
grub_terminfo_cls (term);
|
|
|
|
|
return GRUB_ERR_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
2005-09-03 16:54:27 +00:00
|
|
|
|
/* GRUB Command. */
|
|
|
|
|
|
2010-05-07 22:17:23 +00:00
|
|
|
|
static grub_err_t
|
|
|
|
|
print_terminfo (void)
|
|
|
|
|
{
|
|
|
|
|
const char *encoding_names[(GRUB_TERM_CODE_TYPE_MASK
|
|
|
|
|
>> GRUB_TERM_CODE_TYPE_SHIFT) + 1]
|
|
|
|
|
= {
|
|
|
|
|
/* VGA and glyph descriptor types are just for completeness,
|
|
|
|
|
they are not used on terminfo terminals.
|
|
|
|
|
*/
|
|
|
|
|
[GRUB_TERM_CODE_TYPE_ASCII >> GRUB_TERM_CODE_TYPE_SHIFT] = _("ASCII"),
|
2010-05-09 11:26:52 +00:00
|
|
|
|
[GRUB_TERM_CODE_TYPE_CP437 >> GRUB_TERM_CODE_TYPE_SHIFT] = "CP-437",
|
2010-05-07 22:17:23 +00:00
|
|
|
|
[GRUB_TERM_CODE_TYPE_UTF8_LOGICAL >> GRUB_TERM_CODE_TYPE_SHIFT]
|
|
|
|
|
= _("UTF-8"),
|
|
|
|
|
[GRUB_TERM_CODE_TYPE_UTF8_VISUAL >> GRUB_TERM_CODE_TYPE_SHIFT]
|
2012-03-05 15:42:26 +00:00
|
|
|
|
/* TRANSLATORS: visually ordered UTF-8 is a non-compliant encoding
|
|
|
|
|
based on UTF-8 with right-to-left languages written in reverse.
|
|
|
|
|
Used on some terminals. Normal UTF-8 is refered as
|
|
|
|
|
"logically-ordered UTF-8" by opposition. */
|
2012-02-08 18:26:01 +00:00
|
|
|
|
= _("visually-ordered UTF-8"),
|
2010-05-07 22:17:23 +00:00
|
|
|
|
[GRUB_TERM_CODE_TYPE_VISUAL_GLYPHS >> GRUB_TERM_CODE_TYPE_SHIFT]
|
|
|
|
|
= "Glyph descriptors",
|
2012-02-08 18:26:01 +00:00
|
|
|
|
_("Unknown encoding"), _("Unknown encoding"), _("Unknown encoding")
|
2010-05-07 22:17:23 +00:00
|
|
|
|
};
|
|
|
|
|
struct grub_term_output *cur;
|
|
|
|
|
|
2011-11-11 20:44:56 +00:00
|
|
|
|
grub_puts_ (N_("Current terminfo types:"));
|
2010-05-07 22:17:23 +00:00
|
|
|
|
for (cur = terminfo_outputs; cur;
|
|
|
|
|
cur = ((struct grub_terminfo_output_state *) cur->data)->next)
|
2012-06-26 21:32:00 +00:00
|
|
|
|
grub_printf ("%s: %s\t%s\t%dx%d\n", cur->name,
|
2010-05-07 22:17:23 +00:00
|
|
|
|
grub_terminfo_get_current(cur),
|
|
|
|
|
encoding_names[(cur->flags & GRUB_TERM_CODE_TYPE_MASK)
|
2012-06-26 21:32:00 +00:00
|
|
|
|
>> GRUB_TERM_CODE_TYPE_SHIFT],
|
2013-10-19 21:59:32 +00:00
|
|
|
|
((struct grub_terminfo_output_state *) cur->data)->pos.x,
|
|
|
|
|
((struct grub_terminfo_output_state *) cur->data)->pos.y);
|
2010-05-07 22:17:23 +00:00
|
|
|
|
|
|
|
|
|
return GRUB_ERR_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-20 14:27:33 +00:00
|
|
|
|
static const struct grub_arg_option options[] =
|
|
|
|
|
{
|
|
|
|
|
{"ascii", 'a', 0, N_("Terminal is ASCII-only [default]."), 0, ARG_TYPE_NONE},
|
|
|
|
|
{"utf8", 'u', 0, N_("Terminal is logical-ordered UTF-8."), 0, ARG_TYPE_NONE},
|
|
|
|
|
{"visual-utf8", 'v', 0, N_("Terminal is visually-ordered UTF-8."), 0,
|
|
|
|
|
ARG_TYPE_NONE},
|
2012-02-08 18:26:01 +00:00
|
|
|
|
{"geometry", 'g', 0, N_("Terminal has specified geometry."),
|
2012-03-06 13:11:10 +00:00
|
|
|
|
/* TRANSLATORS: "x" has to be entered in, like an identifier, so please don't
|
|
|
|
|
use better Unicode codepoints. */
|
2010-09-20 14:27:33 +00:00
|
|
|
|
N_("WIDTHxHEIGHT."), ARG_TYPE_STRING},
|
|
|
|
|
{0, 0, 0, 0, 0, 0}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum
|
|
|
|
|
{
|
|
|
|
|
OPTION_ASCII,
|
|
|
|
|
OPTION_UTF8,
|
|
|
|
|
OPTION_VISUAL_UTF8,
|
|
|
|
|
OPTION_GEOMETRY
|
|
|
|
|
};
|
|
|
|
|
|
2005-09-03 16:54:27 +00:00
|
|
|
|
static grub_err_t
|
2010-09-20 14:27:33 +00:00
|
|
|
|
grub_cmd_terminfo (grub_extcmd_context_t ctxt, int argc, char **args)
|
2005-09-03 16:54:27 +00:00
|
|
|
|
{
|
2010-05-07 13:44:43 +00:00
|
|
|
|
struct grub_term_output *cur;
|
2010-05-07 22:17:23 +00:00
|
|
|
|
int encoding = GRUB_TERM_CODE_TYPE_ASCII;
|
2010-09-20 14:27:33 +00:00
|
|
|
|
struct grub_arg_list *state = ctxt->state;
|
|
|
|
|
int w = 0, h = 0;
|
2010-05-07 13:44:43 +00:00
|
|
|
|
|
2005-09-03 16:54:27 +00:00
|
|
|
|
if (argc == 0)
|
2010-05-07 22:17:23 +00:00
|
|
|
|
return print_terminfo ();
|
|
|
|
|
|
2010-09-20 14:27:33 +00:00
|
|
|
|
if (state[OPTION_ASCII].set)
|
|
|
|
|
encoding = GRUB_TERM_CODE_TYPE_ASCII;
|
2010-05-07 13:44:43 +00:00
|
|
|
|
|
2010-09-20 14:27:33 +00:00
|
|
|
|
if (state[OPTION_UTF8].set)
|
|
|
|
|
encoding = GRUB_TERM_CODE_TYPE_UTF8_LOGICAL;
|
|
|
|
|
|
|
|
|
|
if (state[OPTION_VISUAL_UTF8].set)
|
|
|
|
|
encoding = GRUB_TERM_CODE_TYPE_UTF8_VISUAL;
|
2010-05-07 13:44:43 +00:00
|
|
|
|
|
2010-09-20 14:27:33 +00:00
|
|
|
|
if (state[OPTION_GEOMETRY].set)
|
|
|
|
|
{
|
|
|
|
|
char *ptr = state[OPTION_GEOMETRY].arg;
|
|
|
|
|
w = grub_strtoul (ptr, &ptr, 0);
|
|
|
|
|
if (grub_errno)
|
|
|
|
|
return grub_errno;
|
|
|
|
|
if (*ptr != 'x')
|
|
|
|
|
return grub_error (GRUB_ERR_BAD_ARGUMENT,
|
2012-02-12 14:25:25 +00:00
|
|
|
|
N_("incorrect terminal dimensions specification"));
|
2010-09-20 14:27:33 +00:00
|
|
|
|
ptr++;
|
|
|
|
|
h = grub_strtoul (ptr, &ptr, 0);
|
|
|
|
|
if (grub_errno)
|
|
|
|
|
return grub_errno;
|
|
|
|
|
}
|
2010-05-07 13:44:43 +00:00
|
|
|
|
|
|
|
|
|
for (cur = terminfo_outputs; cur;
|
|
|
|
|
cur = ((struct grub_terminfo_output_state *) cur->data)->next)
|
2012-01-29 16:01:27 +00:00
|
|
|
|
if (grub_strcmp (args[0], cur->name) == 0
|
|
|
|
|
|| (grub_strcmp (args[0], "ofconsole") == 0
|
|
|
|
|
&& grub_strcmp ("console", cur->name) == 0))
|
2010-05-07 22:17:23 +00:00
|
|
|
|
{
|
|
|
|
|
cur->flags = (cur->flags & ~GRUB_TERM_CODE_TYPE_MASK) | encoding;
|
2010-09-20 14:27:33 +00:00
|
|
|
|
|
|
|
|
|
if (w && h)
|
|
|
|
|
{
|
|
|
|
|
struct grub_terminfo_output_state *data
|
|
|
|
|
= (struct grub_terminfo_output_state *) cur->data;
|
2013-10-19 21:59:32 +00:00
|
|
|
|
data->pos.x = w;
|
|
|
|
|
data->pos.y = h;
|
2010-09-20 14:27:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (argc == 1)
|
2010-05-07 22:17:23 +00:00
|
|
|
|
return GRUB_ERR_NONE;
|
|
|
|
|
|
2010-09-20 14:27:33 +00:00
|
|
|
|
return grub_terminfo_set_current (cur, args[1]);
|
2010-05-07 22:17:23 +00:00
|
|
|
|
}
|
2010-09-20 14:27:33 +00:00
|
|
|
|
|
2010-05-07 13:44:43 +00:00
|
|
|
|
return grub_error (GRUB_ERR_BAD_ARGUMENT,
|
2012-02-12 14:25:25 +00:00
|
|
|
|
N_("terminal %s isn't found or it's not handled by terminfo"),
|
2010-09-20 14:27:33 +00:00
|
|
|
|
args[0]);
|
2005-09-03 16:54:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-09-20 14:27:33 +00:00
|
|
|
|
static grub_extcmd_t cmd;
|
2009-03-21 Bean <bean123ch@gmail.com>
* commands/blocklist.c: Add include file <grub/command.h>, remove
<grub/normal.h> and <grub/arg.h>.
(grub_cmd_blocklist): Use the new command interface.
(GRUB_MOD_INIT): Likewise.
(GRUB_MOD_FINI): Likewise.
* commands/boot.c: Likewise.
* commands/cat.c: Likewise.
* commands/cmp.c: Likewise.
* commands/configfile.c: Likewise.
* commands/crc.c: Likewise.
* commands/echo.c: Likewise.
* commands/halt.c: Likewise.
* commands/handler.c: Likewise.
* commands/hdparm.c: Likewise.
* commands/help.c: Likewise.
* commands/hexdump.c: Likewise.
* commands/loadenv.c: Likewise.
* commands/ls.c: Likewise.
* commands/lsmmap.c: Likewise.
* commands/lspci.c: Likewise.
* commands/loadenv.c: Likewise.
* commands/read.c: Likewise.
* commands/reboot.c: Likewise.
* commands/search.c: Likewise.
* commands/sleep.c: Likewise.
* commands/test.c: Likewise.
* commands/usbtest.c: Likewise.
* commands/videotest.c: Likewise.
* commands/i386/cpuid.c: Likewise.
* commands/i386/pc/halt.c: Likewise.
* commands/i386/pc/play.c: Likewise.
* commands/i386/pc/pxecmd.c: Likewise.
* commands/i386/pc/vbeinfo.c: Likewise.
* commands/i386/pc/vbetest.c: Likewise.
* commands/ieee1275/suspend.c: Likewise.
* disk/loopback.c: Likewise.
* font/font_cmd.c: Likewise.
* hello/hello.c: Likewise.
* loader/efi/appleloader.c: Likewise.
* loader/efi/chainloader.c: Likewise.
* loader/i386/bsd.c: Likewise.
* loader/i386/efi/linux.c: Likewise.
* loader/i386/ieee1275/linux.c: Likewise.
* loader/i386/linux.c: Likewise.
* loader/i386/pc/chainloader.c: Likewise.
* loader/i386/pc/linux.c: Likewise.
* loader/powerpc/ieee1275/linux.c: Likewise.
* loader/multiboot_loader.c: Likewise.
* term/gfxterm.c: Likewise.
* term/i386/pc/serial.c: Likewise.
* term/terminfo.c: Likewise.
* term/i386/pc/vesafb.c: Removed <grub/arg.h>.
* term/i386/pc/vga.c: Likewise.
* video/readers/jpeg.c: Likewise.
* video/readers/png.c: Likewise.
* video/readers/tga.c: Likewise.
* util/grub-fstest (cmd_loopback): Removed.
(cmd_blocklist): Likewise.
(cmd_ls): Likewise.
(grub_register_command): Likewise.
(grub_unregister_command): Likewise.
(execute_command): Use grub_command_find to locate command and execute
it.
* include/grub/efi/chainloader.h: Removed.
* loader/efi/chainloader_normal.c: Likewise.
* loader/i386/bsd_normal.c: Likewise.
* loader/i386/pc/chainloader_normal.c: Likewise.
* loader/i386/pc/multiboot_normal.c: Likewise.
* loader/linux_normal.c: Likewise.
* loader/multiboot_loader_normal.c: Likewise.
* loader/powerpc/ieee1275/linux_normal.c: Likewise.
* gencmdlist.sh: Scan new registration command grub_register_extcmd
and grub_register_command_p1.
* conf/common.rmk (grub_fstest_SOURCES): Add kern/list.c,
kern/command.c, lib/arg.c and commands/extcmd.c.
(pkglib_MODULES): Remove boot.mod, and minicmd.mod and extcmd.mod.
(minicmd_mod_SOURCES): New variable.
(minicmd_mod_CFLAGS): Likewise.
(minicmd_mod_LDFLAGS): Likewise.
(extcmd_mod_SOURCES): Likewise.
(extcmd_mod_CFLAGS): Likewise.
(extcmd_mod_LDFLAGS): Likewise.
(boot_mod_SOURCES): Removed.
(boot_mod_CFLAGS): Likewise.
(boot_mod_LDFLAGS): Likewise.
* conf/i386-pc.rmk (kernel_img_SOURCES): Add kern/command.c and
kern/corecmd.c.
(kernel_img_HEADERS): Add command.h.
(grub_emu_SOURCES): Remove commands/boot.c and normal/arg.c, add
commands/minicmd.c, kern/command.c, kern/corecmd.c, commands/extcmd.c
and lib/arg.c.
(pkglib_MODULES): Change _linux.mod, _chain.mod, _bsd.mod and
_multiboot.mod as linux.mod, chain.mod, bsd.mod and multiboot.mod,
remove the corresponding normal mode command.
(normal_mod_SOURCES): Remove normal/arg.c.
* conf/i386-coreboot.rmk: Likewise.
* conf/i386-efi.rmk: Likewise.
* conf/i386-ieee1275.rmk: Likewise.
* conf/powerpc-ieee1275.rmk: Likewise.
* conf/x86_64-efi.rmk: Likewise.
* include/grub/arg.h: Move from here ...
* include/grub/lib/arg.h: ... to here.
* normal/arg.c: Move from here ...
* lib/arg.c: ... to here.
* commands/extcmd.c: New file.
* commands/minicmd.c: Likewise.
* include/grub/command.h: Likewise.
* include/grub/extcmd.h: Likewise.
* kern/command.c: Likewise.
* kern/corecmd.c: Likewise.
* kern/list.c (grub_list_iterate): Return int instead of void.
(grub_list_insert): New function.
(grub_prio_list_insert): Likewise.
* kern/rescue.c (grub_rescue_command): Removed.
(grub_rescue_command_list): Likewise.
(grub_rescue_register_command): Likewise.
(grub_rescue_unregister_command): Likewise.
(grub_rescue_cmd_boot): Move to minicmd.c
(grub_rescue_cmd_help): Likewise.
(grub_rescue_cmd_info): Likewise.
(grub_rescue_cmd_boot): Likewise.
(grub_rescue_cmd_testload): Likewise.
(grub_rescue_cmd_dump): Likewise.
(grub_rescue_cmd_rmmod): Likewise.
(grub_rescue_cmd_lsmod): Likewise.
(grub_rescue_cmd_exit): Likewise.
(grub_rescue_print_devices): Moved to corecmd.c.
(grub_rescue_print_files): Likewise.
(grub_rescue_cmd_ls): Likewise.
(grub_rescue_cmd_insmod): Likewise.
(grub_rescue_cmd_set): Likewise.
(grub_rescue_cmd_unset): Likewise.
(attemp_normal_mode): Use grub_command_find to get normal module.
(grub_enter_rescue_mode): Use grub_register_core_commands to register
commands, remove grub_rescue_regiter_command calls.
* normal/command.c (grub_regiser_command): Removed.
(grub_unregister_command): Likewise.
(grub_command_find): Likewise.
(grub_iterate_commands): Likewise.
(rescue_command): Likewise.
(export_command): Moved to corecmd.c.
(set_command): Removed.
(unset_command): Likewise.
(insmod_command): Likewise.
(rmmod_command): Likewise.
(lsmod_command): Likewise.
(grub_command_init): Likewise.
* normal/completion.c (iterate_command): Use cmd->prio to check for
active command.
(complete_arguments): Use grub_extcmd_t structure to find options.
(grub_normal_do_completion): Change function grub_iterate_commands to
grub_command_iterate.
* normal/execute.c (grub_script_execute_cmd): No need to parse
argument here.
* normal/main.c (grub_dyncmd_dispatcher): New function.
(read_command_list): Register unload commands as dyncmd.
(grub_cmd_normal): Use new command interface, register rescue,
unregister normal at entry, register normal, unregister rescue at exit.
* include/grub/list.h (grub_list_test_t): New type.
(grub_list_iterate): Return int instead of void.
(grub_list_insert): New function.
(GRUB_AS_NAMED_LIST_P): New macro.
(GRUB_AS_PRIO_LIST): Likewise.
(GRUB_AS_PRIO_LIST_P): Likewise.
(GRUB_PRIO_LIST_PRIO_MASK): New constant.
(GRUB_PRIO_LIST_FLAG_ACTIVE): Likewise.
(grub_prio_list): New structure.
(grub_prio_list_insert): New function.
(grub_prio_list_remove): New inline function.
* include/grub/normal.h: Remove <grub/arg.h>, add <grub/command.h>.
(GRUB_COMMAND_FLAG_CMDLINE): Moved to command.h.
(GRUB_COMMAND_FLAG_MENU): Likewise.
(GRUB_COMMAND_FLAG_BOTH): Likewise.
(GRUB_COMMAND_FLAG_TITLE): Likewise.
(GRUB_COMMAND_FLAG_NO_ECHO): Likewise.
(GRUB_COMMAND_FLAG_NO_ARG_PARSE): Removed.
(GRUB_COMMAND_FLAG_NOT_LOADED): Likewise.
(grub_command): Likewise.
(grub_register_command): Likewise.
(grub_command_find): Likewise.
(grub_iterate_commands): Likewise.
(grub_command_init): Likewise.
(grub_arg_parse): Likewise.
(grub_arg_show_help): Likewise.
* include/grub/rescue.h (grub_rescue_register_command): Removed.
(grub_rescue_unregister_command): Likewise.
* include/grub/i386/bsd.h: Remove grub_rescue_cmd_freebsd,
grub_rescue_cmd_openbsd, grub_rescue_cmd_netbsd,
grub_rescue_cmd_freebsd_loadenv and grub_rescue_cmd_freebsd_module.
* include/grub/i386/efi/loader.h: Remove grub_rescue_cmd_linux and
grub_rescue_cmd_initrd.
* include/grub/i386/loader.h: Likewise.
* include/grub/x86_64/loader.h: Likewise.
* include/grub/i386/pc/chainloader.h: Remove grub_chainloader_cmd.
2009-03-21 08:39:59 +00:00
|
|
|
|
|
2005-11-13 Marco Gerards <mgerards@xs4all.nl>
* geninit.sh: New file.
* geninitheader.sh: Likewise.
* commands/boot.c (grub_boot_init, grub_boot_fini): Removed.
* commands/cat.c (grub_cat_init, grub_cat_fini): Likewise.
* commands/cmp.c (grub_cmp_init, grub_cmp_fini): Likewise.
* commands/configfile.c (grub_configfile_init)
(grub_configfile_fini): Likewise.
* commands/default.c (grub_default_init, grub_default_fini):
Likewise.
* commands/help.c (grub_help_init, grub_help_fini): Likewise.
* commands/ls.c (grub_ls_init, grub_ls_fini): Likewise.
* commands/search.c (grub_search_init, grub_search_fini): Likewise.
* commands/terminal.c (grub_terminal_init, grub_terminal_fini):
Likewise.
* commands/test.c (grub_test_init, grub_test_fini): Likewise.
* commands/timeout.c (grub_timeout_init, grub_timeout_fini):
Likewise.
* commands/i386/pc/halt.c (grub_halt_init, grub_halt_fini): Likewise.
* commands/iee1275/halt.c (grub_halt_init, grub_halt_fini):
Likewise.
* commands/i386/pc/reboot.c (grub_reboot_init, grub_reboot_fini):
Likewise.
* commands/iee1275/reboot.c (grub_reboot_init, grub_reboot_fini):
Likewise.
* disk/loopback.c (grub_loop_init, grub_loop_fini): Likewise.
* fs/affs.c (grub_affs_init, grub_affs_fini): Likewise.
* fs/ext2.c (grub_ext2_init, grub_ext2_fini): Likewise.
* fs/fat.c (grub_fat_init, grub_fat_fini): Likewise.
* fs/hfs.c (grub_hfs_init, grub_hfs_fini): Likewise.
* fs/iso9660.c (grub_iso9660_init, grub_iso9660_fini): Likewise.
* fs/jfs.c (grub_jfs_init, grub_jfs_fini): Likewise.
* fs/minix.c (grub_minix_init, grub_minix_fini): Likewise.
* fs/sfs.c (grub_sfs_init, grub_sfs_fini): Likewise.
* fs/ufs.c (grub_ufs_init, grub_ufs_fini): Likewise.
* fs/xfs.c (grub_xfs_init, grub_xfs_fini): Likewise.
* normal/main.c (grub_normal_init, grub_normal_fini): Likewise.
* partmap/amiga.c (grub_amiga_partition_map_init)
(grub_amiga_partition_map_fini): Likewise.
* partmap/apple.c (grub_apple_partition_map_init)
(grub_apple_partition_map_fini): Likewise.
* partmap/pc.c (grub_pc_partition_map_init)
(grub_pc_partition_map_fini): Likewise.
* partmap/sun.c (grub_sun_partition_map_init,
grub_sun_partition_map_fini): Likewise.
* term/terminfo.c (grub_terminal_init, grub_terminal_fini):
Likewise.
* util/grub-emu.c: Include <grub_modules_init.h>.
(main): Don't initialize and de-initialize any modules directly,
use `grub_init_all' and `grub_fini_all' instead.
* term/i386/pc/vesafb.c (grub_vesafb_init): Renamed to
`grub_vesafb_mod_init'.
(grub_vesafb_fini): Renamed to `grub_vesafb_mod_fini'. Updated
all users.
* term/i386/pc/vga.c (grub_vga_init): Renamed to
`grub_vga_mod_init'. Updated all users.
(grub_vga_fini): Renamed to `grub_vga_mod_fini'.
* conf/i386-pc.rmk (grub_emu_SOURCES): Add `grub_emu_init.c'.
(grub_modules_init.lst, grub_modules_init.h, grub_emu_init.c): New
rules.
* include/grub/dl.h (GRUB_MOD_INIT): Add argument `name'.
Generate a function to initialize the module in utilities.
Updated all callers.
(GRUB_MOD_FINI): Add argument `name'. Generate a function to
initialize the module in utilities. Updated all callers.
2005-11-13 15:47:09 +00:00
|
|
|
|
GRUB_MOD_INIT(terminfo)
|
2005-09-03 16:54:27 +00:00
|
|
|
|
{
|
2010-09-20 14:27:33 +00:00
|
|
|
|
cmd = grub_register_extcmd ("terminfo", grub_cmd_terminfo, 0,
|
|
|
|
|
N_("[[-a|-u|-v] [-g WxH] TERM [TYPE]]"),
|
|
|
|
|
N_("Set terminfo type of TERM to TYPE.\n"),
|
|
|
|
|
options);
|
2005-09-03 16:54:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-11-13 Marco Gerards <mgerards@xs4all.nl>
* geninit.sh: New file.
* geninitheader.sh: Likewise.
* commands/boot.c (grub_boot_init, grub_boot_fini): Removed.
* commands/cat.c (grub_cat_init, grub_cat_fini): Likewise.
* commands/cmp.c (grub_cmp_init, grub_cmp_fini): Likewise.
* commands/configfile.c (grub_configfile_init)
(grub_configfile_fini): Likewise.
* commands/default.c (grub_default_init, grub_default_fini):
Likewise.
* commands/help.c (grub_help_init, grub_help_fini): Likewise.
* commands/ls.c (grub_ls_init, grub_ls_fini): Likewise.
* commands/search.c (grub_search_init, grub_search_fini): Likewise.
* commands/terminal.c (grub_terminal_init, grub_terminal_fini):
Likewise.
* commands/test.c (grub_test_init, grub_test_fini): Likewise.
* commands/timeout.c (grub_timeout_init, grub_timeout_fini):
Likewise.
* commands/i386/pc/halt.c (grub_halt_init, grub_halt_fini): Likewise.
* commands/iee1275/halt.c (grub_halt_init, grub_halt_fini):
Likewise.
* commands/i386/pc/reboot.c (grub_reboot_init, grub_reboot_fini):
Likewise.
* commands/iee1275/reboot.c (grub_reboot_init, grub_reboot_fini):
Likewise.
* disk/loopback.c (grub_loop_init, grub_loop_fini): Likewise.
* fs/affs.c (grub_affs_init, grub_affs_fini): Likewise.
* fs/ext2.c (grub_ext2_init, grub_ext2_fini): Likewise.
* fs/fat.c (grub_fat_init, grub_fat_fini): Likewise.
* fs/hfs.c (grub_hfs_init, grub_hfs_fini): Likewise.
* fs/iso9660.c (grub_iso9660_init, grub_iso9660_fini): Likewise.
* fs/jfs.c (grub_jfs_init, grub_jfs_fini): Likewise.
* fs/minix.c (grub_minix_init, grub_minix_fini): Likewise.
* fs/sfs.c (grub_sfs_init, grub_sfs_fini): Likewise.
* fs/ufs.c (grub_ufs_init, grub_ufs_fini): Likewise.
* fs/xfs.c (grub_xfs_init, grub_xfs_fini): Likewise.
* normal/main.c (grub_normal_init, grub_normal_fini): Likewise.
* partmap/amiga.c (grub_amiga_partition_map_init)
(grub_amiga_partition_map_fini): Likewise.
* partmap/apple.c (grub_apple_partition_map_init)
(grub_apple_partition_map_fini): Likewise.
* partmap/pc.c (grub_pc_partition_map_init)
(grub_pc_partition_map_fini): Likewise.
* partmap/sun.c (grub_sun_partition_map_init,
grub_sun_partition_map_fini): Likewise.
* term/terminfo.c (grub_terminal_init, grub_terminal_fini):
Likewise.
* util/grub-emu.c: Include <grub_modules_init.h>.
(main): Don't initialize and de-initialize any modules directly,
use `grub_init_all' and `grub_fini_all' instead.
* term/i386/pc/vesafb.c (grub_vesafb_init): Renamed to
`grub_vesafb_mod_init'.
(grub_vesafb_fini): Renamed to `grub_vesafb_mod_fini'. Updated
all users.
* term/i386/pc/vga.c (grub_vga_init): Renamed to
`grub_vga_mod_init'. Updated all users.
(grub_vga_fini): Renamed to `grub_vga_mod_fini'.
* conf/i386-pc.rmk (grub_emu_SOURCES): Add `grub_emu_init.c'.
(grub_modules_init.lst, grub_modules_init.h, grub_emu_init.c): New
rules.
* include/grub/dl.h (GRUB_MOD_INIT): Add argument `name'.
Generate a function to initialize the module in utilities.
Updated all callers.
(GRUB_MOD_FINI): Add argument `name'. Generate a function to
initialize the module in utilities. Updated all callers.
2005-11-13 15:47:09 +00:00
|
|
|
|
GRUB_MOD_FINI(terminfo)
|
2005-09-03 16:54:27 +00:00
|
|
|
|
{
|
2010-09-20 14:27:33 +00:00
|
|
|
|
grub_unregister_extcmd (cmd);
|
2005-09-03 16:54:27 +00:00
|
|
|
|
}
|