]> git.proxmox.com Git - grub2.git/blob - include/grub/term.h
2005-02-19 Yoshinori K. Okuji <okuji@enbug.org>
[grub2.git] / include / grub / term.h
1 /*
2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2002,2003,2005 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 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program 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, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #ifndef GRUB_TERM_HEADER
21 #define GRUB_TERM_HEADER 1
22
23 #include <grub/err.h>
24 #include <grub/symbol.h>
25 #include <grub/types.h>
26
27 /* These are used to represent the various color states we use. */
28 typedef enum
29 {
30 /* The color used to display all text that does not use the
31 user defined colors below. */
32 GRUB_TERM_COLOR_STANDARD,
33 /* The user defined colors for normal text. */
34 GRUB_TERM_COLOR_NORMAL,
35 /* The user defined colors for highlighted text. */
36 GRUB_TERM_COLOR_HIGHLIGHT
37 }
38 grub_term_color_state;
39
40 /* Flags for representing the capabilities of a terminal. */
41 /* Some notes about the flags:
42 - These flags are used by higher-level functions but not terminals
43 themselves.
44 - If a terminal is dumb, you may assume that only putchar, getkey and
45 checkkey are called.
46 - Some fancy features (setcolorstate, setcolor and setcursor) can be set
47 to NULL. */
48
49 /* Set when input characters shouldn't be echoed back. */
50 #define GRUB_TERM_NO_ECHO (1 << 0)
51 /* Set when the editing feature should be disabled. */
52 #define GRUB_TERM_NO_EDIT (1 << 1)
53 /* Set when the terminal cannot do fancy things. */
54 #define GRUB_TERM_DUMB (1 << 2)
55 /* Set when the terminal needs to be initialized. */
56 #define GRUB_TERM_NEED_INIT (1 << 16)
57
58
59 /* Unicode characters for fancy graphics. */
60 #define GRUB_TERM_DISP_LEFT 0x2190
61 #define GRUB_TERM_DISP_UP 0x2191
62 #define GRUB_TERM_DISP_RIGHT 0x2192
63 #define GRUB_TERM_DISP_DOWN 0x2193
64 #define GRUB_TERM_DISP_HLINE 0x2501
65 #define GRUB_TERM_DISP_VLINE 0x2503
66 #define GRUB_TERM_DISP_UL 0x250F
67 #define GRUB_TERM_DISP_UR 0x2513
68 #define GRUB_TERM_DISP_LL 0x2517
69 #define GRUB_TERM_DISP_LR 0x251B
70
71
72 /* Menu-related geometrical constants. */
73
74 /* FIXME: These should be dynamically obtained from a terminal. */
75 #define GRUB_TERM_WIDTH 80
76 #define GRUB_TERM_HEIGHT 25
77
78 /* The number of lines of "GRUB version..." at the top. */
79 #define GRUB_TERM_INFO_HEIGHT 1
80
81 /* The number of columns/lines between messages/borders/etc. */
82 #define GRUB_TERM_MARGIN 1
83
84 /* The number of columns of scroll information. */
85 #define GRUB_TERM_SCROLL_WIDTH 1
86
87 /* The Y position of the top border. */
88 #define GRUB_TERM_TOP_BORDER_Y (GRUB_TERM_MARGIN + GRUB_TERM_INFO_HEIGHT \
89 + GRUB_TERM_MARGIN)
90
91 /* The X position of the left border. */
92 #define GRUB_TERM_LEFT_BORDER_X GRUB_TERM_MARGIN
93
94 /* The width of the border. */
95 #define GRUB_TERM_BORDER_WIDTH (GRUB_TERM_WIDTH \
96 - GRUB_TERM_MARGIN * 3 \
97 - GRUB_TERM_SCROLL_WIDTH)
98
99 /* The number of lines of messages at the bottom. */
100 #define GRUB_TERM_MESSAGE_HEIGHT 8
101
102 /* The height of the border. */
103 #define GRUB_TERM_BORDER_HEIGHT (GRUB_TERM_HEIGHT \
104 - GRUB_TERM_TOP_BORDER_Y \
105 - GRUB_TERM_MESSAGE_HEIGHT)
106
107 /* The number of entries shown at a time. */
108 #define GRUB_TERM_NUM_ENTRIES (GRUB_TERM_BORDER_HEIGHT - 2)
109
110 /* The Y position of the first entry. */
111 #define GRUB_TERM_FIRST_ENTRY_Y (GRUB_TERM_TOP_BORDER_Y + 1)
112
113 /* The max column number of an entry. The last "-1" is for a
114 continuation marker. */
115 #define GRUB_TERM_ENTRY_WIDTH (GRUB_TERM_BORDER_WIDTH - 2 \
116 - GRUB_TERM_MARGIN * 2 - 1)
117
118 /* The standard X position of the cursor. */
119 #define GRUB_TERM_CURSOR_X (GRUB_TERM_LEFT_BORDER_X \
120 + GRUB_TERM_BORDER_WIDTH \
121 - GRUB_TERM_MARGIN \
122 - 1)
123
124
125 struct grub_term
126 {
127 /* The terminal name. */
128 const char *name;
129
130 /* Initialize the terminal. */
131 grub_err_t (*init) (void);
132
133 /* Clean up the terminal. */
134 grub_err_t (*fini) (void);
135
136 /* Put a character. C is encoded in Unicode. */
137 void (*putchar) (grub_uint32_t c);
138
139 /* Check if any input character is available. */
140 int (*checkkey) (void);
141
142 /* Get a character. */
143 int (*getkey) (void);
144
145 /* Get the cursor position. The return value is ((X << 8) | Y). */
146 grub_uint16_t (*getxy) (void);
147
148 /* Go to the position (X, Y). */
149 void (*gotoxy) (grub_uint8_t x, grub_uint8_t y);
150
151 /* Clear the screen. */
152 void (*cls) (void);
153
154 /* Set the current color to be used */
155 void (*setcolorstate) (grub_term_color_state state);
156
157 /* Set the normal color and the highlight color. The format of each
158 color is VGA's. */
159 void (*setcolor) (grub_uint8_t normal_color, grub_uint8_t highlight_color);
160
161 /* Turn on/off the cursor. */
162 void (*setcursor) (int on);
163
164 /* Update the screen. */
165 void (*refresh) (void);
166
167 /* The feature flags defined above. */
168 grub_uint32_t flags;
169
170 /* The next terminal. */
171 struct grub_term *next;
172 };
173 typedef struct grub_term *grub_term_t;
174
175 void EXPORT_FUNC(grub_term_register) (grub_term_t term);
176 void EXPORT_FUNC(grub_term_unregister) (grub_term_t term);
177 void EXPORT_FUNC(grub_term_iterate) (int (*hook) (grub_term_t term));
178
179 grub_err_t EXPORT_FUNC(grub_term_set_current) (grub_term_t term);
180 grub_term_t EXPORT_FUNC(grub_term_get_current) (void);
181
182 void EXPORT_FUNC(grub_putchar) (int c);
183 void EXPORT_FUNC(grub_putcode) (grub_uint32_t code);
184 int EXPORT_FUNC(grub_getkey) (void);
185 int EXPORT_FUNC(grub_checkkey) (void);
186 grub_uint16_t EXPORT_FUNC(grub_getxy) (void);
187 void EXPORT_FUNC(grub_gotoxy) (grub_uint8_t x, grub_uint8_t y);
188 void EXPORT_FUNC(grub_cls) (void);
189 void EXPORT_FUNC(grub_setcolorstate) (grub_term_color_state state);
190 void EXPORT_FUNC(grub_setcolor) (grub_uint8_t normal_color,
191 grub_uint8_t highlight_color);
192 int EXPORT_FUNC(grub_setcursor) (int on);
193 void EXPORT_FUNC(grub_refresh) (void);
194 void EXPORT_FUNC(grub_set_more) (int onoff);
195
196 /* For convenience. */
197 #define GRUB_TERM_ASCII_CHAR(c) ((c) & 0xff)
198
199 #endif /* ! GRUB_TERM_HEADER */