]> git.proxmox.com Git - grub2.git/blob - grub-core/kern/term.c
* grub-core/kern/mm.c (grub_memalign): Disable auto-unloadding of
[grub2.git] / grub-core / kern / term.c
1 /*
2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2002,2003,2005,2007,2008,2009 Free Software Foundation, Inc.
4 *
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.
9 *
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.
14 *
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/>.
17 */
18
19 #include <grub/term.h>
20 #include <grub/err.h>
21 #include <grub/mm.h>
22 #include <grub/misc.h>
23 #include <grub/env.h>
24 #include <grub/time.h>
25
26 struct grub_term_output *grub_term_outputs_disabled;
27 struct grub_term_input *grub_term_inputs_disabled;
28 struct grub_term_output *grub_term_outputs;
29 struct grub_term_input *grub_term_inputs;
30
31 void (*grub_term_poll_usb) (void) = NULL;
32
33 /* Put a Unicode character. */
34 static void
35 grub_putcode_dumb (grub_uint32_t code,
36 struct grub_term_output *term)
37 {
38 struct grub_unicode_glyph c =
39 {
40 .base = code,
41 .variant = 0,
42 .attributes = 0,
43 .ncomb = 0,
44 .combining = 0,
45 .estimated_width = 1
46 };
47
48 if (code == '\t' && term->getxy)
49 {
50 int n;
51
52 n = 8 - ((term->getxy (term) >> 8) & 7);
53 while (n--)
54 grub_putcode_dumb (' ', term);
55
56 return;
57 }
58
59 (term->putchar) (term, &c);
60 if (code == '\n')
61 grub_putcode_dumb ('\r', term);
62 }
63
64 static void
65 grub_xputs_dumb (const char *str)
66 {
67 for (; *str; str++)
68 {
69 grub_term_output_t term;
70 grub_uint32_t code = *str;
71 if (code > 0x7f)
72 code = '?';
73
74 FOR_ACTIVE_TERM_OUTPUTS(term)
75 grub_putcode_dumb (code, term);
76 }
77 }
78
79 void (*grub_xputs) (const char *str) = grub_xputs_dumb;
80
81 static int pending_key = GRUB_TERM_NO_KEY;
82
83 int
84 grub_checkkey (void)
85 {
86 grub_term_input_t term;
87
88 if (pending_key != GRUB_TERM_NO_KEY)
89 return pending_key;
90
91 if (grub_term_poll_usb)
92 grub_term_poll_usb ();
93
94 FOR_ACTIVE_TERM_INPUTS(term)
95 {
96 pending_key = term->getkey (term);
97 if (pending_key != GRUB_TERM_NO_KEY)
98 return pending_key;
99 }
100
101 return -1;
102 }
103
104 int
105 grub_getkey (void)
106 {
107 int ret;
108
109 grub_refresh ();
110
111 grub_checkkey ();
112 while (pending_key == GRUB_TERM_NO_KEY)
113 {
114 grub_cpu_idle ();
115 grub_checkkey ();
116 }
117 ret = pending_key;
118 pending_key = GRUB_TERM_NO_KEY;
119 return ret;
120 }
121
122
123 void
124 grub_refresh (void)
125 {
126 struct grub_term_output *term;
127
128 FOR_ACTIVE_TERM_OUTPUTS(term)
129 grub_term_refresh (term);
130 }