2
* GRUB -- GRand Unified Bootloader
3
* Copyright (C) 2002,2003,2005,2007,2008,2009 Free Software Foundation, Inc.
5
* GRUB is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation, either version 3 of the License, or
8
* (at your option) any later version.
10
* GRUB is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
19
#include <grub/term.h>
20
#include <grub/misc.h>
22
#include <grub/file.h>
25
#include <grub/normal.h>
27
/* The amount of lines counted by the pager. */
28
static unsigned grub_more_lines;
30
/* If the more pager is active. */
34
process_newline (void)
36
struct grub_term_output *cur;
39
FOR_ACTIVE_TERM_OUTPUTS(cur)
40
if (grub_term_height (cur) < height)
41
height = grub_term_height (cur);
44
if (grub_more && grub_more_lines >= height - 1)
49
pos = grub_term_save_pos ();
51
grub_setcolorstate (GRUB_TERM_COLOR_HIGHLIGHT);
52
grub_printf ("--MORE--");
53
grub_setcolorstate (GRUB_TERM_COLOR_STANDARD);
57
/* Remove the message. */
58
grub_term_restore_pos (pos);
60
grub_term_restore_pos (pos);
62
/* Scroll one lines or an entire page, depending on the key. */
63
if (key == '\r' || key =='\n')
64
grub_more_lines = height - 2;
71
grub_set_more (int onoff)
79
grub_newline_hook = process_newline;
83
grub_puts_terminal (const char *str, struct grub_term_output *term)
87
const grub_uint8_t *ptr = (const grub_uint8_t *) str;
88
const grub_uint8_t *end;
89
end = (const grub_uint8_t *) (str + grub_strlen (str));
93
ret = grub_utf8_to_ucs4 (&code, 1, ptr, end - ptr, &ptr);
94
grub_putcode (code, term);
99
grub_term_save_pos (void)
101
struct grub_term_output *cur;
103
grub_uint16_t *ret, *ptr;
105
FOR_ACTIVE_TERM_OUTPUTS(cur)
108
ret = grub_malloc (cnt * sizeof (ret[0]));
113
FOR_ACTIVE_TERM_OUTPUTS(cur)
114
*ptr++ = grub_term_getxy (cur);
120
grub_term_restore_pos (grub_uint16_t *pos)
122
struct grub_term_output *cur;
123
grub_uint16_t *ptr = pos;
128
FOR_ACTIVE_TERM_OUTPUTS(cur)
130
grub_term_gotoxy (cur, (*ptr & 0xff00) >> 8, *ptr & 0xff);
136
grub_terminal_autoload_free (void)
138
struct grub_term_autoload *cur, *next;
140
for (i = 0; i < 2; i++)
141
for (cur = i ? grub_term_input_autoload : grub_term_output_autoload;
145
grub_free (cur->name);
146
grub_free (cur->modname);
149
grub_term_input_autoload = NULL;
150
grub_term_output_autoload = NULL;
154
/* Read the file terminal.lst for auto-loading. */
156
read_terminal_list (void)
163
prefix = grub_env_get ("prefix");
166
grub_errno = GRUB_ERR_NONE;
170
filename = grub_xasprintf ("%s/terminal.lst", prefix);
173
grub_errno = GRUB_ERR_NONE;
177
file = grub_file_open (filename);
180
grub_errno = GRUB_ERR_NONE;
184
/* Override previous terminal.lst. */
185
grub_terminal_autoload_free ();
187
for (;; grub_free (buf))
190
struct grub_term_autoload *cur;
191
struct grub_term_autoload **target = NULL;
193
buf = grub_file_getline (file);
201
target = &grub_term_input_autoload;
205
target = &grub_term_output_autoload;
213
p = grub_strchr (name, ':');
221
cur = grub_malloc (sizeof (*cur));
224
grub_errno = GRUB_ERR_NONE;
228
cur->name = grub_strdup (name);
231
grub_errno = GRUB_ERR_NONE;
236
cur->modname = grub_strdup (p);
239
grub_errno = GRUB_ERR_NONE;
241
grub_free (cur->name);
248
grub_file_close (file);
250
grub_errno = GRUB_ERR_NONE;