1
/* terminfo.c - read a terminfo entry from the command line */
3
* GRUB -- GRand Unified Bootloader
4
* Copyright (C) 2002,2004 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.
20
* ######################################################################
22
* This file contains various functions dealing with different
23
* terminal capabilities. It knows the difference between a vt52 and vt100
24
* terminal (and much more) and is mainly used the terminal emulation
25
* in the serial driver.
33
/* Current terminal capabilities. Default is "vt100". */
34
struct terminfo term =
37
.cursor_address = "\e[%i%p1%d;%p2%dH",
38
.clear_screen = "\e[H\e[J",
39
.enter_standout_mode = "\e[7m",
40
.exit_standout_mode = "\e[m"
43
/* A number of escape sequences are provided in the string valued
44
capabilities for easy encoding of characters there. Both \E and \e
45
map to an ESCAPE character, ^x maps to a control-x for any
46
appropriate x, and the sequences \n \l \r \t \b \f \s give a
47
newline, line-feed, return, tab, backspace, form-feed, and space.
48
Other escapes include \^ for ^, \\ for \, \, for comma, \: for :,
49
and \0 for null. (\0 will produce \200, which does not terminate a
50
string but behaves as a null character on most terminals, provid�
51
ing CS7 is specified. See stty(1).) Finally, characters may be
52
given as three octal digits after a \. */
55
ti_unescape_memory (const char *in, const char *end)
57
static char out_buffer[256];
68
if (*in >= 'A' && *in <= 'Z')
80
if (c >= '0' && c <= '9')
86
n = (n << 4) | (c - '0');
89
while (c >= '0' && c <= '9');
91
*out++ = (char)(n & 0xff);
93
// redo last character
151
ti_unescape_string (const char *in)
153
return ti_unescape_memory (in, in + grub_strlen (in));
156
/* convert a memory region containing binary character into an external
157
* ascii representation. The binary characters will be replaced by an
158
* "ecsape notation". E.g. "033" will become "\e". */
160
ti_escape_memory (const char *in, const char *end)
162
static char out_buffer[256];
173
*out++ = '\\'; *out++ = 'e'; break;
175
*out++ = '\\'; *out++ = 's'; break;
177
*out++ = '\\'; *out++ = '\\'; break;
194
*out++ = '^'; *out++ = 'A' + c; break;
197
*out++ = ((c >> 8) & 7) + '0';
198
*out++ = ((c >> 4) & 7) + '0';
199
*out++ = ((c >> 0) & 7) + '0';
210
/* convert a string containing binary character into an external ascii
213
ti_escape_string (const char *in)
215
return ti_escape_memory (in, in + grub_strlen (in));
218
/* move the cursor to the given position starting with "0". */
220
ti_cursor_address (int x, int y)
222
grub_putstr (grub_tparm (term.cursor_address, y, x));
225
/* clear the screen. */
227
ti_clear_screen (void)
229
grub_putstr (grub_tparm (term.clear_screen));
232
/* enter reverse video */
234
ti_enter_standout_mode (void)
236
grub_putstr (grub_tparm (term.enter_standout_mode));
239
/* exit reverse video */
241
ti_exit_standout_mode (void)
243
grub_putstr (grub_tparm (term.exit_standout_mode));
246
/* set the current terminal emulation to use */
248
ti_set_term (const struct terminfo *new)
250
grub_memmove (&term, new, sizeof (struct terminfo));
253
/* get the current terminal emulation */
255
ti_get_term(struct terminfo *copy)
257
grub_memmove (copy, &term, sizeof (struct terminfo));