+2010-09-20 Vladimir Serbinenko <phcoder@gmail.com>
+
+ 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.
+
2010-09-20 Vladimir Serbinenko <phcoder@gmail.com>
Handle legacy "terminal" command.
" default values are COM1, 9600, 8N1."},
/* FIXME: setkey unsupported. */ /* NUL_TERMINATE */
/* NOTE: setup unsupported. */
- /* FIXME: --no-echo, --no-edit, --lines, hercules unsupported. */
+ /* FIXME: --no-echo, --no-edit, hercules unsupported. */
/* NOTE: both terminals are activated so --silent and --timeout
are useless. */
{"terminal", NULL, NULL, 0, 0, {}, FLAG_TERMINAL | FLAG_IGNORE_REST,
}
grub_strcpy (outptr, "; ");
outptr += grub_strlen (outptr);
- if (serial && dumb)
- {
- grub_strcpy (outptr, "terminfo serial dumb; ");
- outptr += grub_strlen (outptr);
- }
-
- if (serial && !dumb)
+ if (serial)
{
- grub_strcpy (outptr, "terminfo serial vt100; ");
+ grub_snprintf (outptr, outbuf + sizeof (outbuf) - outptr,
+ "terminfo serial -g 80x%d %s; ",
+ lines, dumb ? "dumb" : "vt100");
outptr += grub_strlen (outptr);
}
grub_strcpy (outptr, "\n");
-
+
return grub_strdup (outbuf);
}
static grub_ieee1275_ihandle_t stdout_ihandle;
static grub_ieee1275_ihandle_t stdin_ihandle;
-static grub_uint8_t grub_ofconsole_width;
-static grub_uint8_t grub_ofconsole_height;
+extern struct grub_terminfo_output_state grub_ofconsole_terminfo_output;
struct color
{
if (! grub_ieee1275_get_property (options, "screen-#columns",
val, lval, 0))
- grub_ofconsole_width = (grub_uint8_t) grub_strtoul (val, 0, 10);
+ grub_ofconsole_terminfo_output->width
+ = (grub_uint8_t) grub_strtoul (val, 0, 10);
}
if (! grub_ieee1275_get_property_length (options, "screen-#rows", &lval)
&& lval >= 0 && lval < 1024)
char val[lval];
if (! grub_ieee1275_get_property (options, "screen-#rows",
val, lval, 0))
- grub_ofconsole_height = (grub_uint8_t) grub_strtoul (val, 0, 10);
+ grub_ofconsole_terminfo_output->height
+ = (grub_uint8_t) grub_strtoul (val, 0, 10);
}
}
/* Use a small console by default. */
- if (! grub_ofconsole_width)
- grub_ofconsole_width = 80;
- if (! grub_ofconsole_height)
- grub_ofconsole_height = 24;
-}
-
-static grub_uint16_t
-grub_ofconsole_getwh (struct grub_term_output *term __attribute__ ((unused)))
-{
- return (grub_ofconsole_width << 8) | grub_ofconsole_height;
+ if (! grub_ofconsole_terminfo_output->width)
+ grub_ofconsole_terminfo_output->width = 80;
+ if (! grub_ofconsole_terminfo_output->height)
+ grub_ofconsole_terminfo_output->height = 24;
}
static void
struct grub_terminfo_output_state grub_ofconsole_terminfo_output =
{
- .put = put
+ .put = put,
+ .width = 80,
+ .height = 24
};
static struct grub_term_input grub_ofconsole_term_input =
.init = grub_ofconsole_init_output,
.putchar = grub_terminfo_putchar,
.getxy = grub_terminfo_getxy,
- .getwh = grub_ofconsole_getwh,
+ .getwh = grub_terminfo_getwh,
.gotoxy = grub_terminfo_gotoxy,
.cls = grub_terminfo_cls,
.setcolorstate = grub_terminfo_setcolorstate,
struct grub_serial_port *port;
};
-static grub_uint16_t
-grub_serial_getwh (struct grub_term_output *term __attribute__ ((unused)))
-{
- const grub_uint8_t TEXT_WIDTH = 80;
- const grub_uint8_t TEXT_HEIGHT = 24;
- return (TEXT_WIDTH << 8) | TEXT_HEIGHT;
-}
-
static void
serial_put (grub_term_output_t term, const int c)
{
{
.tinfo =
{
- .put = serial_put
+ .put = serial_put,
+ .width = 80,
+ .height = 24
}
};
{
.name = "serial",
.putchar = grub_terminfo_putchar,
- .getwh = grub_serial_getwh,
+ .getwh = grub_terminfo_getwh,
.getxy = grub_terminfo_getxy,
.gotoxy = grub_terminfo_gotoxy,
.cls = grub_terminfo_cls,
#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>
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
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 (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;
- }
+ if (state[OPTION_ASCII].set)
+ encoding = GRUB_TERM_CODE_TYPE_ASCII;
- return grub_error (GRUB_ERR_BAD_ARGUMENT, "too many parameters");
- }
+ 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 (name == NULL)
- return grub_error (GRUB_ERR_BAD_ARGUMENT, "too few parameters");
+ 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,
+ "incorrect geometry specification");
+ ptr++;
+ h = grub_strtoul (ptr, &ptr, 0);
+ if (grub_errno)
+ return grub_errno;
+ }
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);
}
char *cursor_off;
char *setcolor;
+ unsigned int width, height;
+
unsigned int xpos, ypos;
void (*put) (struct grub_term_output *term, const int c);
int EXPORT_FUNC (grub_terminfo_getkey) (struct grub_term_input *term);
void EXPORT_FUNC (grub_terminfo_putchar) (struct grub_term_output *term,
const struct grub_unicode_glyph *c);
+grub_uint16_t EXPORT_FUNC (grub_terminfo_getwh) (struct grub_term_output *term);
+
grub_err_t EXPORT_FUNC (grub_terminfo_output_register) (struct grub_term_output *term,
const char *type);