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>
24 #include <grub/cpu/time.h>
26 struct grub_term_output
*grub_term_outputs
;
27 struct grub_term_input
*grub_term_inputs
;
29 void (*grub_newline_hook
) (void) = NULL
;
31 /* Put a Unicode character. */
33 grub_putcode (grub_uint32_t code
, struct grub_term_output
*term
)
37 height
= grub_term_height (term
);
39 if (code
== '\t' && term
->getxy
)
43 n
= 8 - ((term
->getxy () >> 8) & 7);
45 grub_putcode (' ', term
);
51 (term
->putchar
) ('\r');
52 (term
->putchar
) (code
);
55 /* Put a character. C is one byte of a UTF-8 stream.
56 This function gathers bytes until a valid Unicode character is found. */
60 static grub_size_t size
= 0;
61 static grub_uint8_t buf
[6];
66 ret
= grub_utf8_to_ucs4 (&code
, 1, buf
, size
, 0);
70 struct grub_term_output
*term
;
72 FOR_ACTIVE_TERM_OUTPUTS(term
)
73 grub_putcode (code
, term
);
75 if (ret
== '\n' && grub_newline_hook
)
82 grub_term_input_t term
;
86 FOR_ACTIVE_TERM_INPUTS(term
)
88 int key
= term
->checkkey ();
90 return term
->getkey ();
100 grub_term_input_t term
;
102 FOR_ACTIVE_TERM_INPUTS(term
)
104 int key
= term
->checkkey ();
113 grub_getkeystatus (void)
116 grub_term_input_t term
;
118 FOR_ACTIVE_TERM_INPUTS(term
)
120 if (term
->getkeystatus
)
121 status
|= term
->getkeystatus ();
130 struct grub_term_output
*term
;
132 FOR_ACTIVE_TERM_OUTPUTS(term
)
134 if ((term
->flags
& GRUB_TERM_DUMB
) || (grub_env_get ("debug")))
136 grub_putcode ('\n', term
);
145 grub_setcolorstate (grub_term_color_state state
)
147 struct grub_term_output
*term
;
149 FOR_ACTIVE_TERM_OUTPUTS(term
)
150 grub_term_setcolorstate (term
, state
);
156 struct grub_term_output
*term
;
158 FOR_ACTIVE_TERM_OUTPUTS(term
)
159 grub_term_refresh (term
);