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
) ();
144 grub_getkeystatus (void)
146 if (grub_cur_term_input
->getkeystatus
)
147 return (grub_cur_term_input
->getkeystatus
) ();
155 return (grub_cur_term_output
->getxy
) ();
161 return (grub_cur_term_output
->getwh
) ();
165 grub_gotoxy (grub_uint8_t x
, grub_uint8_t y
)
167 (grub_cur_term_output
->gotoxy
) (x
, y
);
173 if ((grub_cur_term_output
->flags
& GRUB_TERM_DUMB
) || (grub_env_get ("debug")))
179 (grub_cur_term_output
->cls
) ();
183 grub_setcolorstate (grub_term_color_state state
)
185 if (grub_cur_term_output
->setcolorstate
)
186 (grub_cur_term_output
->setcolorstate
) (state
);
190 grub_setcolor (grub_uint8_t normal_color
, grub_uint8_t highlight_color
)
192 if (grub_cur_term_output
->setcolor
)
193 (grub_cur_term_output
->setcolor
) (normal_color
, highlight_color
);
197 grub_getcolor (grub_uint8_t
*normal_color
, grub_uint8_t
*highlight_color
)
199 if (grub_cur_term_output
->getcolor
)
200 (grub_cur_term_output
->getcolor
) (normal_color
, highlight_color
);
204 grub_setcursor (int on
)
206 int ret
= cursor_state
;
208 if (grub_cur_term_output
->setcursor
)
210 (grub_cur_term_output
->setcursor
) (on
);
218 grub_getcursor (void)
226 if (grub_cur_term_output
->refresh
)
227 (grub_cur_term_output
->refresh
) ();
231 grub_set_more (int onoff
)