1
/* terminfo.c - simple terminfo module */
3
* GRUB -- GRand Unified Bootloader
4
* Copyright (C) 2003,2004,2005 Free Software Foundation, Inc.
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22
* This file contains various functions dealing with different
23
* terminal capabilities. For example, vt52 and vt100.
26
#include <grub/types.h>
27
#include <grub/misc.h>
31
#include <grub/normal.h>
32
#include <grub/term.h>
33
#include <grub/terminfo.h>
34
#include <grub/tparm.h>
42
char *reverse_video_on;
43
char *reverse_video_off;
48
static struct terminfo term;
50
/* Get current terminfo name. */
52
grub_terminfo_get_current (void)
57
/* Free *PTR and set *PTR to NULL, to prevent double-free. */
59
grub_terminfo_free (char **ptr)
65
/* Set current terminfo type. */
67
grub_terminfo_set_current (const char *str)
70
* Lookup user specified terminfo type. If found, set term variables
71
* as appropriate. Otherwise return an error.
73
* How should this be done?
74
* a. A static table included in this module.
75
* - I do not like this idea.
76
* b. A table stored in the configuration directory.
77
* - Users must convert their terminfo settings if we have not already.
78
* c. Look for terminfo files in the configuration directory.
79
* - /usr/share/terminfo is 6.3M on my system.
80
* - /usr/share/terminfo is not on most users boot partition.
81
* + Copying the terminfo files you want to use to the grub
82
* configuration directory is easier then (b).
86
/* Free previously allocated memory. */
87
grub_terminfo_free (&term.name);
88
grub_terminfo_free (&term.gotoxy);
89
grub_terminfo_free (&term.cls);
90
grub_terminfo_free (&term.reverse_video_on);
91
grub_terminfo_free (&term.reverse_video_off);
92
grub_terminfo_free (&term.cursor_on);
93
grub_terminfo_free (&term.cursor_off);
95
if (grub_strcmp ("vt100", str) == 0)
97
term.name = grub_strdup ("vt100");
98
term.gotoxy = grub_strdup ("\e[%i%p1%d;%p2%dH");
99
term.cls = grub_strdup ("\e[H\e[J");
100
term.reverse_video_on = grub_strdup ("\e[7m");
101
term.reverse_video_off = grub_strdup ("\e[m");
102
term.cursor_on = grub_strdup ("\e[?25l");
103
term.cursor_off = grub_strdup ("\e[?25h");
107
return grub_error (GRUB_ERR_BAD_ARGUMENT, "unknown terminfo type.");
110
/* Wrapper for grub_putchar to write strings. */
112
putstr (const char *str)
115
grub_putchar (*str++);
118
/* Move the cursor to the given position starting with "0". */
120
grub_terminfo_gotoxy (grub_uint8_t x, grub_uint8_t y)
122
putstr (grub_terminfo_tparm (term.gotoxy, y, x));
125
/* Clear the screen. */
127
grub_terminfo_cls (void)
129
putstr (grub_terminfo_tparm (term.cls));
132
/* Set reverse video mode on. */
134
grub_terminfo_reverse_video_on (void)
136
putstr (grub_terminfo_tparm (term.reverse_video_on));
139
/* Set reverse video mode off. */
141
grub_terminfo_reverse_video_off (void)
143
putstr (grub_terminfo_tparm (term.reverse_video_off));
148
grub_terminfo_cursor_on (void)
150
putstr (grub_terminfo_tparm (term.cursor_on));
155
grub_terminfo_cursor_off (void)
157
putstr (grub_terminfo_tparm (term.cursor_off));
163
grub_cmd_terminfo (struct grub_arg_list *state __attribute__ ((unused)),
164
int argc, char **args)
168
grub_printf ("Current terminfo type: %s\n", grub_terminfo_get_current());
169
return GRUB_ERR_NONE;
172
return grub_error (GRUB_ERR_BAD_ARGUMENT, "too many parameters.");
174
return grub_terminfo_set_current (args[0]);
177
GRUB_MOD_INIT(terminfo)
179
(void) mod; /* To stop warning. */
180
grub_register_command ("terminfo", grub_cmd_terminfo, GRUB_COMMAND_FLAG_BOTH,
181
"terminfo [TERM]", "Set terminfo type.", 0);
182
grub_terminfo_set_current ("vt100");
185
GRUB_MOD_FINI(terminfo)
187
grub_unregister_command ("terminfo");