2
* GRUB -- GRand Unified Bootloader
3
* Copyright (C) 2002,2003,2005 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 2 of the License, or
8
* (at your option) any later version.
10
* This program 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, write to the Free Software
17
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
#include <grub/term.h>
23
#include <grub/misc.h>
26
/* The list of terminals. */
27
static grub_term_t grub_term_list;
29
/* The current terminal. */
30
static grub_term_t grub_cur_term;
32
/* The amount of lines counted by the pager. */
33
static int grub_more_lines;
35
/* If the more pager is active. */
38
/* The current cursor state. */
39
static int cursor_state = 1;
42
grub_term_register (grub_term_t term)
44
term->next = grub_term_list;
45
grub_term_list = term;
49
grub_term_unregister (grub_term_t term)
53
for (p = &grub_term_list, q = *p; q; p = &(q->next), q = q->next)
62
grub_term_iterate (int (*hook) (grub_term_t term))
66
for (p = grub_term_list; p; p = p->next)
72
grub_term_set_current (grub_term_t term)
74
if (grub_cur_term && grub_cur_term->fini)
75
if ((grub_cur_term->fini) () != GRUB_ERR_NONE)
79
if ((term->init) () != GRUB_ERR_NONE)
84
grub_setcursor (grub_getcursor ());
89
grub_term_get_current (void)
94
/* Put a Unicode character. */
96
grub_putcode (grub_uint32_t code)
98
int height = grub_getwh () & 255;
100
if (code == '\t' && grub_cur_term->getxy)
104
n = 8 - ((grub_getxy () >> 8) & 7);
111
(grub_cur_term->putchar) (code);
119
if (grub_more && grub_more_lines == height - 1)
122
int pos = grub_getxy ();
124
/* Show --MORE-- on the lower left side of the screen. */
125
grub_gotoxy (1, height - 1);
126
grub_setcolorstate (GRUB_TERM_COLOR_HIGHLIGHT);
127
grub_printf ("--MORE--");
128
grub_setcolorstate (GRUB_TERM_COLOR_STANDARD);
130
key = grub_getkey ();
132
/* Remove the message. */
133
grub_gotoxy (1, height - 1);
135
grub_gotoxy (pos >> 8, pos & 0xFF);
137
/* Scroll one lines or an entire page, depending on the key. */
138
if (key == '\r' || key =='\n')
146
/* Put a character. C is one byte of a UTF-8 stream.
147
This function gathers bytes until a valid Unicode character is found. */
151
static grub_size_t size = 0;
152
static grub_uint8_t buf[6];
157
ret = grub_utf8_to_ucs4 (&code, buf, size);
171
/* Return the number of columns occupied by the character code CODE. */
173
grub_getcharwidth (grub_uint32_t code)
175
return (grub_cur_term->getcharwidth) (code);
181
return (grub_cur_term->getkey) ();
187
return (grub_cur_term->checkkey) ();
193
return (grub_cur_term->getxy) ();
199
return (grub_cur_term->getwh) ();
203
grub_gotoxy (grub_uint8_t x, grub_uint8_t y)
205
(grub_cur_term->gotoxy) (x, y);
211
if ((grub_cur_term->flags & GRUB_TERM_DUMB) || (grub_env_get ("debug")))
217
(grub_cur_term->cls) ();
221
grub_setcolorstate (grub_term_color_state state)
223
if (grub_cur_term->setcolorstate)
224
(grub_cur_term->setcolorstate) (state);
228
grub_setcolor (grub_uint8_t normal_color, grub_uint8_t highlight_color)
230
if (grub_cur_term->setcolor)
231
(grub_cur_term->setcolor) (normal_color, highlight_color);
235
grub_setcursor (int on)
237
int ret = cursor_state;
239
if (grub_cur_term->setcursor)
241
(grub_cur_term->setcursor) (on);
249
grub_getcursor (void)
257
if (grub_cur_term->refresh)
258
(grub_cur_term->refresh) ();
262
grub_set_more (int onoff)