Suport manual terminal geometry specification.
* grub-core/term/ieee1275/ofconsole.c (grub_ofconsole_dimensions): Save state in grub_ofconsole_terminfo_output. (grub_ofconsole_term): Use grub_terminfo_getwh. (grub_ofconsole_getwh): Removed. * grub-core/term/serial.c (grub_serial_getwh): Removed. (grub_serial_term): Use grub_terminfo_getwh. * grub-core/term/terminfo.c (grub_terminfo_getwh): New function. (options): New struct. (OPTION_*): New enum. (grub_cmd_terminfo): Transform into extcmd and handle new parameters. * include/grub/terminfo.h (grub_terminfo_output_state): New fields width and height. (grub_terminfo_getwh): New proto. * grub-core/lib/legacy_parse.c (grub_legacy_parse): Handle --lines.
This commit is contained in:
parent
1a8fed20ad
commit
a9cc5438a5
6 changed files with 119 additions and 89 deletions
|
@ -30,7 +30,7 @@
|
|||
#include <grub/term.h>
|
||||
#include <grub/terminfo.h>
|
||||
#include <grub/tparm.h>
|
||||
#include <grub/command.h>
|
||||
#include <grub/extcmd.h>
|
||||
#include <grub/i18n.h>
|
||||
#include <grub/time.h>
|
||||
|
||||
|
@ -358,6 +358,15 @@ grub_terminfo_putchar (struct grub_term_output *term,
|
|||
data->put (term, c->base);
|
||||
}
|
||||
|
||||
grub_uint16_t
|
||||
grub_terminfo_getwh (struct grub_term_output *term)
|
||||
{
|
||||
struct grub_terminfo_output_state *data
|
||||
= (struct grub_terminfo_output_state *) term->data;
|
||||
|
||||
return (data->width << 8) | data->height;
|
||||
}
|
||||
|
||||
#define ANSI_C0 0x9b
|
||||
|
||||
static void
|
||||
|
@ -537,85 +546,96 @@ print_terminfo (void)
|
|||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
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},
|
||||
{"geometry", 'g', 0, N_("Terminal has given geometry."),
|
||||
N_("WIDTHxHEIGHT."), ARG_TYPE_STRING},
|
||||
{0, 0, 0, 0, 0, 0}
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
OPTION_ASCII,
|
||||
OPTION_UTF8,
|
||||
OPTION_VISUAL_UTF8,
|
||||
OPTION_GEOMETRY
|
||||
};
|
||||
|
||||
static grub_err_t
|
||||
grub_cmd_terminfo (grub_command_t cmd __attribute__ ((unused)),
|
||||
int argc, char **args)
|
||||
grub_cmd_terminfo (grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
{
|
||||
struct grub_term_output *cur;
|
||||
int encoding = GRUB_TERM_CODE_TYPE_ASCII;
|
||||
int i;
|
||||
char *name = NULL, *type = NULL;
|
||||
struct grub_arg_list *state = ctxt->state;
|
||||
int w = 0, h = 0;
|
||||
|
||||
if (argc == 0)
|
||||
return print_terminfo ();
|
||||
|
||||
for (i = 0; i < argc; i++)
|
||||
if (state[OPTION_ASCII].set)
|
||||
encoding = GRUB_TERM_CODE_TYPE_ASCII;
|
||||
|
||||
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;
|
||||
|
||||
if (state[OPTION_GEOMETRY].set)
|
||||
{
|
||||
if (grub_strcmp (args[i], "-a") == 0
|
||||
|| grub_strcmp (args[i], "--ascii") == 0)
|
||||
{
|
||||
encoding = GRUB_TERM_CODE_TYPE_ASCII;
|
||||
continue;
|
||||
}
|
||||
if (grub_strcmp (args[i], "-u") == 0
|
||||
|| grub_strcmp (args[i], "--utf8") == 0)
|
||||
{
|
||||
encoding = GRUB_TERM_CODE_TYPE_UTF8_LOGICAL;
|
||||
continue;
|
||||
}
|
||||
if (grub_strcmp (args[i], "-v") == 0
|
||||
|| grub_strcmp (args[i], "--visual-utf8") == 0)
|
||||
{
|
||||
encoding = GRUB_TERM_CODE_TYPE_UTF8_VISUAL;
|
||||
continue;
|
||||
}
|
||||
if (!name)
|
||||
{
|
||||
name = args[i];
|
||||
continue;
|
||||
}
|
||||
if (!type)
|
||||
{
|
||||
type = args[i];
|
||||
continue;
|
||||
}
|
||||
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, "too many parameters");
|
||||
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,
|
||||
"incorrect geometry specification");
|
||||
ptr++;
|
||||
h = grub_strtoul (ptr, &ptr, 0);
|
||||
if (grub_errno)
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
if (name == NULL)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, "too few parameters");
|
||||
|
||||
for (cur = terminfo_outputs; cur;
|
||||
cur = ((struct grub_terminfo_output_state *) cur->data)->next)
|
||||
if (grub_strcmp (name, cur->name) == 0)
|
||||
if (grub_strcmp (args[0], cur->name) == 0)
|
||||
{
|
||||
cur->flags = (cur->flags & ~GRUB_TERM_CODE_TYPE_MASK) | encoding;
|
||||
if (!type)
|
||||
|
||||
if (w && h)
|
||||
{
|
||||
struct grub_terminfo_output_state *data
|
||||
= (struct grub_terminfo_output_state *) cur->data;
|
||||
data->width = w;
|
||||
data->height = h;
|
||||
}
|
||||
|
||||
if (argc == 1)
|
||||
return GRUB_ERR_NONE;
|
||||
|
||||
return grub_terminfo_set_current (cur, type);
|
||||
return grub_terminfo_set_current (cur, args[1]);
|
||||
}
|
||||
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT,
|
||||
"no terminal %s found or it's not handled by terminfo",
|
||||
name);
|
||||
args[0]);
|
||||
}
|
||||
|
||||
static grub_command_t cmd;
|
||||
static grub_extcmd_t cmd;
|
||||
|
||||
GRUB_MOD_INIT(terminfo)
|
||||
{
|
||||
cmd = grub_register_command ("terminfo", grub_cmd_terminfo,
|
||||
N_("[[-a|-u|-v] TERM [TYPE]]"),
|
||||
N_("Set terminfo type of TERM to TYPE.\n"
|
||||
"-a, --ascii Terminal is ASCII-only [default].\n"
|
||||
"-u, --utf8 Terminal is logical-ordered UTF-8.\n"
|
||||
"-v, --visual-utf8 Terminal is visually-ordered UTF-8.")
|
||||
|
||||
);
|
||||
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);
|
||||
}
|
||||
|
||||
GRUB_MOD_FINI(terminfo)
|
||||
{
|
||||
grub_unregister_command (cmd);
|
||||
grub_unregister_extcmd (cmd);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue