2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2002,2003,2005,2007 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>
22 #include <grub/misc.h>
25 /* The list of terminals. */
26 static grub_term_t grub_term_list
;
28 /* The current terminal. */
29 static grub_term_t grub_cur_term
;
31 /* The amount of lines counted by the pager. */
32 static int grub_more_lines
;
34 /* If the more pager is active. */
37 /* The current cursor state. */
38 static int cursor_state
= 1;
41 grub_term_register (grub_term_t term
)
43 term
->next
= grub_term_list
;
44 grub_term_list
= term
;
48 grub_term_unregister (grub_term_t term
)
52 for (p
= &grub_term_list
, q
= *p
; q
; p
= &(q
->next
), q
= q
->next
)
61 grub_term_iterate (int (*hook
) (grub_term_t term
))
65 for (p
= grub_term_list
; p
; p
= p
->next
)
71 grub_term_set_current (grub_term_t term
)
73 if (grub_cur_term
&& grub_cur_term
->fini
)
74 if ((grub_cur_term
->fini
) () != GRUB_ERR_NONE
)
78 if ((term
->init
) () != GRUB_ERR_NONE
)
83 grub_setcursor (grub_getcursor ());
88 grub_term_get_current (void)
93 /* Put a Unicode character. */
95 grub_putcode (grub_uint32_t code
)
97 int height
= grub_getwh () & 255;
99 if (code
== '\t' && grub_cur_term
->getxy
)
103 n
= 8 - ((grub_getxy () >> 8) & 7);
110 (grub_cur_term
->putchar
) (code
);
118 if (grub_more
&& grub_more_lines
== height
- 1)
121 int pos
= grub_getxy ();
123 /* Show --MORE-- on the lower left side of the screen. */
124 grub_gotoxy (1, height
- 1);
125 grub_setcolorstate (GRUB_TERM_COLOR_HIGHLIGHT
);
126 grub_printf ("--MORE--");
127 grub_setcolorstate (GRUB_TERM_COLOR_STANDARD
);
129 key
= grub_getkey ();
131 /* Remove the message. */
132 grub_gotoxy (1, height
- 1);
134 grub_gotoxy (pos
>> 8, pos
& 0xFF);
136 /* Scroll one lines or an entire page, depending on the key. */
137 if (key
== '\r' || key
=='\n')
145 /* Put a character. C is one byte of a UTF-8 stream.
146 This function gathers bytes until a valid Unicode character is found. */
150 static grub_size_t size
= 0;
151 static grub_uint8_t buf
[6];
156 ret
= grub_utf8_to_ucs4 (&code
, buf
, size
);
170 /* Return the number of columns occupied by the character code CODE. */
172 grub_getcharwidth (grub_uint32_t code
)
174 return (grub_cur_term
->getcharwidth
) (code
);
180 return (grub_cur_term
->getkey
) ();
186 return (grub_cur_term
->checkkey
) ();
192 return (grub_cur_term
->getxy
) ();
198 return (grub_cur_term
->getwh
) ();
202 grub_gotoxy (grub_uint8_t x
, grub_uint8_t y
)
204 (grub_cur_term
->gotoxy
) (x
, y
);
210 if ((grub_cur_term
->flags
& GRUB_TERM_DUMB
) || (grub_env_get ("debug")))
216 (grub_cur_term
->cls
) ();
220 grub_setcolorstate (grub_term_color_state state
)
222 if (grub_cur_term
->setcolorstate
)
223 (grub_cur_term
->setcolorstate
) (state
);
227 grub_setcolor (grub_uint8_t normal_color
, grub_uint8_t highlight_color
)
229 if (grub_cur_term
->setcolor
)
230 (grub_cur_term
->setcolor
) (normal_color
, highlight_color
);
234 grub_getcolor (grub_uint8_t
*normal_color
, grub_uint8_t
*highlight_color
)
236 if (grub_cur_term
->getcolor
)
237 (grub_cur_term
->getcolor
) (normal_color
, highlight_color
);
241 grub_setcursor (int on
)
243 int ret
= cursor_state
;
245 if (grub_cur_term
->setcursor
)
247 (grub_cur_term
->setcursor
) (on
);
255 grub_getcursor (void)
263 if (grub_cur_term
->refresh
)
264 (grub_cur_term
->refresh
) ();
268 grub_set_more (int onoff
)