1 /* terminfo.c - simple terminfo module */
3 * GRUB -- GRand Unified Bootloader
4 * Copyright (C) 2003,2004,2005,2007 Free Software Foundation, Inc.
6 * GRUB 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 3 of the License, or
9 * (at your option) any later version.
11 * GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>.
21 * This file contains various functions dealing with different
22 * terminal capabilities. For example, vt52 and vt100.
25 #include <grub/types.h>
26 #include <grub/misc.h>
30 #include <grub/normal.h>
31 #include <grub/term.h>
32 #include <grub/terminfo.h>
33 #include <grub/tparm.h>
41 char *reverse_video_on
;
42 char *reverse_video_off
;
47 static struct terminfo term
;
49 /* Get current terminfo name. */
51 grub_terminfo_get_current (void)
56 /* Free *PTR and set *PTR to NULL, to prevent double-free. */
58 grub_terminfo_free (char **ptr
)
64 /* Set current terminfo type. */
66 grub_terminfo_set_current (const char *str
)
69 * Lookup user specified terminfo type. If found, set term variables
70 * as appropriate. Otherwise return an error.
72 * How should this be done?
73 * a. A static table included in this module.
74 * - I do not like this idea.
75 * b. A table stored in the configuration directory.
76 * - Users must convert their terminfo settings if we have not already.
77 * c. Look for terminfo files in the configuration directory.
78 * - /usr/share/terminfo is 6.3M on my system.
79 * - /usr/share/terminfo is not on most users boot partition.
80 * + Copying the terminfo files you want to use to the grub
81 * configuration directory is easier then (b).
85 /* Free previously allocated memory. */
86 grub_terminfo_free (&term
.name
);
87 grub_terminfo_free (&term
.gotoxy
);
88 grub_terminfo_free (&term
.cls
);
89 grub_terminfo_free (&term
.reverse_video_on
);
90 grub_terminfo_free (&term
.reverse_video_off
);
91 grub_terminfo_free (&term
.cursor_on
);
92 grub_terminfo_free (&term
.cursor_off
);
94 if (grub_strcmp ("vt100", str
) == 0)
96 term
.name
= grub_strdup ("vt100");
97 term
.gotoxy
= grub_strdup ("\e[%i%p1%d;%p2%dH");
98 term
.cls
= grub_strdup ("\e[H\e[J");
99 term
.reverse_video_on
= grub_strdup ("\e[7m");
100 term
.reverse_video_off
= grub_strdup ("\e[m");
101 term
.cursor_on
= grub_strdup ("\e[?25l");
102 term
.cursor_off
= grub_strdup ("\e[?25h");
106 return grub_error (GRUB_ERR_BAD_ARGUMENT
, "unknown terminfo type.");
109 /* Wrapper for grub_putchar to write strings. */
111 putstr (const char *str
)
114 grub_putchar (*str
++);
117 /* Move the cursor to the given position starting with "0". */
119 grub_terminfo_gotoxy (grub_uint8_t x
, grub_uint8_t y
)
121 putstr (grub_terminfo_tparm (term
.gotoxy
, y
, x
));
124 /* Clear the screen. */
126 grub_terminfo_cls (void)
128 putstr (grub_terminfo_tparm (term
.cls
));
131 /* Set reverse video mode on. */
133 grub_terminfo_reverse_video_on (void)
135 putstr (grub_terminfo_tparm (term
.reverse_video_on
));
138 /* Set reverse video mode off. */
140 grub_terminfo_reverse_video_off (void)
142 putstr (grub_terminfo_tparm (term
.reverse_video_off
));
147 grub_terminfo_cursor_on (void)
149 putstr (grub_terminfo_tparm (term
.cursor_on
));
154 grub_terminfo_cursor_off (void)
156 putstr (grub_terminfo_tparm (term
.cursor_off
));
162 grub_cmd_terminfo (struct grub_arg_list
*state
__attribute__ ((unused
)),
163 int argc
, char **args
)
167 grub_printf ("Current terminfo type: %s\n", grub_terminfo_get_current());
168 return GRUB_ERR_NONE
;
171 return grub_error (GRUB_ERR_BAD_ARGUMENT
, "too many parameters.");
173 return grub_terminfo_set_current (args
[0]);
176 GRUB_MOD_INIT(terminfo
)
178 (void) mod
; /* To stop warning. */
179 grub_register_command ("terminfo", grub_cmd_terminfo
, GRUB_COMMAND_FLAG_BOTH
,
180 "terminfo [TERM]", "Set terminfo type.", 0);
181 grub_terminfo_set_current ("vt100");
184 GRUB_MOD_FINI(terminfo
)
186 grub_unregister_command ("terminfo");