2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2002,2003,2005,2007,2008 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 #ifndef GRUB_TERM_HEADER
20 #define GRUB_TERM_HEADER 1
22 /* Internal codes used by GRUB to represent terminal input. */
23 #define GRUB_TERM_LEFT 2
24 #define GRUB_TERM_RIGHT 6
25 #define GRUB_TERM_UP 16
26 #define GRUB_TERM_DOWN 14
27 #define GRUB_TERM_HOME 1
28 #define GRUB_TERM_END 5
29 #define GRUB_TERM_DC 4
30 #define GRUB_TERM_PPAGE 7
31 #define GRUB_TERM_NPAGE 3
32 #define GRUB_TERM_ESC '\e'
33 #define GRUB_TERM_TAB '\t'
34 #define GRUB_TERM_BACKSPACE 8
39 #include <grub/symbol.h>
40 #include <grub/types.h>
41 #include <grub/handler.h>
43 /* These are used to represent the various color states we use. */
46 /* The color used to display all text that does not use the
47 user defined colors below. */
48 GRUB_TERM_COLOR_STANDARD
,
49 /* The user defined colors for normal text. */
50 GRUB_TERM_COLOR_NORMAL
,
51 /* The user defined colors for highlighted text. */
52 GRUB_TERM_COLOR_HIGHLIGHT
54 grub_term_color_state
;
56 /* Flags for representing the capabilities of a terminal. */
57 /* Some notes about the flags:
58 - These flags are used by higher-level functions but not terminals
60 - If a terminal is dumb, you may assume that only putchar, getkey and
62 - Some fancy features (setcolorstate, setcolor and setcursor) can be set
65 /* Set when input characters shouldn't be echoed back. */
66 #define GRUB_TERM_NO_ECHO (1 << 0)
67 /* Set when the editing feature should be disabled. */
68 #define GRUB_TERM_NO_EDIT (1 << 1)
69 /* Set when the terminal cannot do fancy things. */
70 #define GRUB_TERM_DUMB (1 << 2)
71 /* Set when the terminal needs to be initialized. */
72 #define GRUB_TERM_NEED_INIT (1 << 16)
75 /* Unicode characters for fancy graphics. */
76 #define GRUB_TERM_DISP_LEFT 0x2190
77 #define GRUB_TERM_DISP_UP 0x2191
78 #define GRUB_TERM_DISP_RIGHT 0x2192
79 #define GRUB_TERM_DISP_DOWN 0x2193
80 #define GRUB_TERM_DISP_HLINE 0x2501
81 #define GRUB_TERM_DISP_VLINE 0x2503
82 #define GRUB_TERM_DISP_UL 0x250F
83 #define GRUB_TERM_DISP_UR 0x2513
84 #define GRUB_TERM_DISP_LL 0x2517
85 #define GRUB_TERM_DISP_LR 0x251B
88 /* Menu-related geometrical constants. */
90 /* FIXME: Ugly way to get them form terminal. */
91 #define GRUB_TERM_WIDTH ((grub_getwh()&0xFF00)>>8)
92 #define GRUB_TERM_HEIGHT (grub_getwh()&0xFF)
94 /* The number of lines of "GRUB version..." at the top. */
95 #define GRUB_TERM_INFO_HEIGHT 1
97 /* The number of columns/lines between messages/borders/etc. */
98 #define GRUB_TERM_MARGIN 1
100 /* The number of columns of scroll information. */
101 #define GRUB_TERM_SCROLL_WIDTH 1
103 /* The Y position of the top border. */
104 #define GRUB_TERM_TOP_BORDER_Y (GRUB_TERM_MARGIN + GRUB_TERM_INFO_HEIGHT \
107 /* The X position of the left border. */
108 #define GRUB_TERM_LEFT_BORDER_X GRUB_TERM_MARGIN
110 /* The width of the border. */
111 #define GRUB_TERM_BORDER_WIDTH (GRUB_TERM_WIDTH \
112 - GRUB_TERM_MARGIN * 3 \
113 - GRUB_TERM_SCROLL_WIDTH)
115 /* The number of lines of messages at the bottom. */
116 #define GRUB_TERM_MESSAGE_HEIGHT 8
118 /* The height of the border. */
119 #define GRUB_TERM_BORDER_HEIGHT (GRUB_TERM_HEIGHT \
120 - GRUB_TERM_TOP_BORDER_Y \
121 - GRUB_TERM_MESSAGE_HEIGHT)
123 /* The number of entries shown at a time. */
124 #define GRUB_TERM_NUM_ENTRIES (GRUB_TERM_BORDER_HEIGHT - 2)
126 /* The Y position of the first entry. */
127 #define GRUB_TERM_FIRST_ENTRY_Y (GRUB_TERM_TOP_BORDER_Y + 1)
129 /* The max column number of an entry. The last "-1" is for a
130 continuation marker. */
131 #define GRUB_TERM_ENTRY_WIDTH (GRUB_TERM_BORDER_WIDTH - 2 \
132 - GRUB_TERM_MARGIN * 2 - 1)
134 /* The standard X position of the cursor. */
135 #define GRUB_TERM_CURSOR_X (GRUB_TERM_LEFT_BORDER_X \
136 + GRUB_TERM_BORDER_WIDTH \
141 struct grub_term_input
143 /* The next terminal. */
144 struct grub_term_input
*next
;
146 /* The terminal name. */
149 /* Initialize the terminal. */
150 grub_err_t (*init
) (void);
152 /* Clean up the terminal. */
153 grub_err_t (*fini
) (void);
155 /* Check if any input character is available. */
156 int (*checkkey
) (void);
158 /* Get a character. */
159 int (*getkey
) (void);
161 typedef struct grub_term_input
*grub_term_input_t
;
163 struct grub_term_output
165 /* The next terminal. */
166 struct grub_term_output
*next
;
168 /* The terminal name. */
171 /* Initialize the terminal. */
172 grub_err_t (*init
) (void);
174 /* Clean up the terminal. */
175 grub_err_t (*fini
) (void);
177 /* Put a character. C is encoded in Unicode. */
178 void (*putchar
) (grub_uint32_t c
);
180 /* Get the number of columns occupied by a given character C. C is
181 encoded in Unicode. */
182 grub_ssize_t (*getcharwidth
) (grub_uint32_t c
);
184 /* Get the screen size. The return value is ((Width << 8) | Height). */
185 grub_uint16_t (*getwh
) (void);
187 /* Get the cursor position. The return value is ((X << 8) | Y). */
188 grub_uint16_t (*getxy
) (void);
190 /* Go to the position (X, Y). */
191 void (*gotoxy
) (grub_uint8_t x
, grub_uint8_t y
);
193 /* Clear the screen. */
196 /* Set the current color to be used */
197 void (*setcolorstate
) (grub_term_color_state state
);
199 /* Set the normal color and the highlight color. The format of each
201 void (*setcolor
) (grub_uint8_t normal_color
, grub_uint8_t highlight_color
);
203 /* Get the normal color and the highlight color. The format of each
205 void (*getcolor
) (grub_uint8_t
*normal_color
, grub_uint8_t
*highlight_color
);
207 /* Turn on/off the cursor. */
208 void (*setcursor
) (int on
);
210 /* Update the screen. */
211 void (*refresh
) (void);
213 /* The feature flags defined above. */
216 typedef struct grub_term_output
*grub_term_output_t
;
218 extern struct grub_handler_class
EXPORT_VAR(grub_term_input_class
);
219 extern struct grub_handler_class
EXPORT_VAR(grub_term_output_class
);
222 grub_term_register_input (const char *name
__attribute__ ((unused
)),
223 grub_term_input_t term
)
225 grub_handler_register (&grub_term_input_class
, GRUB_AS_HANDLER (term
));
229 grub_term_register_output (const char *name
__attribute__ ((unused
)),
230 grub_term_output_t term
)
232 grub_handler_register (&grub_term_output_class
, GRUB_AS_HANDLER (term
));
236 grub_term_unregister_input (grub_term_input_t term
)
238 grub_handler_unregister (&grub_term_input_class
, GRUB_AS_HANDLER (term
));
242 grub_term_unregister_output (grub_term_output_t term
)
244 grub_handler_unregister (&grub_term_output_class
, GRUB_AS_HANDLER (term
));
247 static inline grub_err_t
248 grub_term_set_current_input (grub_term_input_t term
)
250 return grub_handler_set_current (&grub_term_input_class
,
251 GRUB_AS_HANDLER (term
));
254 static inline grub_err_t
255 grub_term_set_current_output (grub_term_output_t term
)
257 return grub_handler_set_current (&grub_term_output_class
,
258 GRUB_AS_HANDLER (term
));
261 static inline grub_term_input_t
262 grub_term_get_current_input (void)
264 return (grub_term_input_t
) grub_term_input_class
.cur_handler
;
267 static inline grub_term_output_t
268 grub_term_get_current_output (void)
270 return (grub_term_output_t
) grub_term_output_class
.cur_handler
;
273 void EXPORT_FUNC(grub_putchar
) (int c
);
274 void EXPORT_FUNC(grub_putcode
) (grub_uint32_t code
);
275 grub_ssize_t
EXPORT_FUNC(grub_getcharwidth
) (grub_uint32_t code
);
276 int EXPORT_FUNC(grub_getkey
) (void);
277 int EXPORT_FUNC(grub_checkkey
) (void);
278 grub_uint16_t
EXPORT_FUNC(grub_getwh
) (void);
279 grub_uint16_t
EXPORT_FUNC(grub_getxy
) (void);
280 void EXPORT_FUNC(grub_gotoxy
) (grub_uint8_t x
, grub_uint8_t y
);
281 void EXPORT_FUNC(grub_cls
) (void);
282 void EXPORT_FUNC(grub_setcolorstate
) (grub_term_color_state state
);
283 void EXPORT_FUNC(grub_setcolor
) (grub_uint8_t normal_color
,
284 grub_uint8_t highlight_color
);
285 void EXPORT_FUNC(grub_getcolor
) (grub_uint8_t
*normal_color
,
286 grub_uint8_t
*highlight_color
);
287 int EXPORT_FUNC(grub_setcursor
) (int on
);
288 int EXPORT_FUNC(grub_getcursor
) (void);
289 void EXPORT_FUNC(grub_refresh
) (void);
290 void EXPORT_FUNC(grub_set_more
) (int onoff
);
292 /* For convenience. */
293 #define GRUB_TERM_ASCII_CHAR(c) ((c) & 0xff)
295 #endif /* ! ASM_FILE */
297 #endif /* ! GRUB_TERM_HEADER */