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>
22 #include <grub/misc.h>
25 /* The amount of lines counted by the pager. */
26 static int grub_more_lines
;
28 /* If the more pager is active. */
31 /* The current cursor state. */
32 static int cursor_state
= 1;
34 struct grub_handler_class grub_term_input_class
=
36 .name
= "terminal_input"
39 struct grub_handler_class grub_term_output_class
=
41 .name
= "terminal_output"
44 #define grub_cur_term_input grub_term_get_current_input ()
45 #define grub_cur_term_output grub_term_get_current_output ()
47 /* Put a Unicode character. */
49 grub_putcode (grub_uint32_t code
)
51 int height
= grub_getwh () & 255;
53 if (code
== '\t' && grub_cur_term_output
->getxy
)
57 n
= 8 - ((grub_getxy () >> 8) & 7);
64 (grub_cur_term_output
->putchar
) (code
);
72 if (grub_more
&& grub_more_lines
== height
- 1)
75 int pos
= grub_getxy ();
77 /* Show --MORE-- on the lower left side of the screen. */
78 grub_gotoxy (1, height
- 1);
79 grub_setcolorstate (GRUB_TERM_COLOR_HIGHLIGHT
);
80 grub_printf ("--MORE--");
81 grub_setcolorstate (GRUB_TERM_COLOR_STANDARD
);
85 /* Remove the message. */
86 grub_gotoxy (1, height
- 1);
88 grub_gotoxy (pos
>> 8, pos
& 0xFF);
90 /* Scroll one lines or an entire page, depending on the key. */
91 if (key
== '\r' || key
=='\n')
99 /* Put a character. C is one byte of a UTF-8 stream.
100 This function gathers bytes until a valid Unicode character is found. */
104 static grub_size_t size
= 0;
105 static grub_uint8_t buf
[6];
110 ret
= grub_utf8_to_ucs4 (&code
, 1, buf
, size
, 0);
124 /* Return the number of columns occupied by the character code CODE. */
126 grub_getcharwidth (grub_uint32_t code
)
128 return (grub_cur_term_output
->getcharwidth
) (code
);
134 return (grub_cur_term_input
->getkey
) ();
140 return (grub_cur_term_input
->checkkey
) ();
146 return (grub_cur_term_output
->getxy
) ();
152 return (grub_cur_term_output
->getwh
) ();
156 grub_gotoxy (grub_uint8_t x
, grub_uint8_t y
)
158 (grub_cur_term_output
->gotoxy
) (x
, y
);
164 if ((grub_cur_term_output
->flags
& GRUB_TERM_DUMB
) || (grub_env_get ("debug")))
170 (grub_cur_term_output
->cls
) ();
174 grub_setcolorstate (grub_term_color_state state
)
176 if (grub_cur_term_output
->setcolorstate
)
177 (grub_cur_term_output
->setcolorstate
) (state
);
181 grub_setcolor (grub_uint8_t normal_color
, grub_uint8_t highlight_color
)
183 if (grub_cur_term_output
->setcolor
)
184 (grub_cur_term_output
->setcolor
) (normal_color
, highlight_color
);
188 grub_getcolor (grub_uint8_t
*normal_color
, grub_uint8_t
*highlight_color
)
190 if (grub_cur_term_output
->getcolor
)
191 (grub_cur_term_output
->getcolor
) (normal_color
, highlight_color
);
195 grub_setcursor (int on
)
197 int ret
= cursor_state
;
199 if (grub_cur_term_output
->setcursor
)
201 (grub_cur_term_output
->setcursor
) (on
);
209 grub_getcursor (void)
217 if (grub_cur_term_output
->refresh
)
218 (grub_cur_term_output
->refresh
) ();
222 grub_set_more (int onoff
)