65
66
/* Set when input characters shouldn't be echoed back. */
66
#define GRUB_TERM_NO_ECHO (1 << 0)
67
#define GRUB_TERM_NO_ECHO (1 << 0)
67
68
/* Set when the editing feature should be disabled. */
68
#define GRUB_TERM_NO_EDIT (1 << 1)
69
#define GRUB_TERM_NO_EDIT (1 << 1)
69
70
/* Set when the terminal cannot do fancy things. */
70
#define GRUB_TERM_DUMB (1 << 2)
71
#define GRUB_TERM_DUMB (1 << 2)
72
/* Which encoding does terminal expect stream to be. */
73
#define GRUB_TERM_CODE_TYPE_SHIFT 3
74
#define GRUB_TERM_CODE_TYPE_MASK (7 << GRUB_TERM_CODE_TYPE_SHIFT)
75
/* Only ASCII characters accepted. */
76
#define GRUB_TERM_CODE_TYPE_ASCII (0 << GRUB_TERM_CODE_TYPE_SHIFT)
77
/* Expects CP-437 characters (ASCII + pseudographics). */
78
#define GRUB_TERM_CODE_TYPE_CP437 (1 << GRUB_TERM_CODE_TYPE_SHIFT)
79
/* UTF-8 stream in logical order. Usually used for terminals
80
which just forward the stream to another computer. */
81
#define GRUB_TERM_CODE_TYPE_UTF8_LOGICAL (2 << GRUB_TERM_CODE_TYPE_SHIFT)
82
/* UTF-8 in visual order. Like UTF-8 logical but for buggy endpoints. */
83
#define GRUB_TERM_CODE_TYPE_UTF8_VISUAL (3 << GRUB_TERM_CODE_TYPE_SHIFT)
84
/* Glyph description in visual order. */
85
#define GRUB_TERM_CODE_TYPE_VISUAL_GLYPHS (4 << GRUB_TERM_CODE_TYPE_SHIFT)
73
88
/* Bitmasks for modifier keys returned by grub_getkeystatus. */
75
90
#define GRUB_TERM_STATUS_CTRL (1 << 1)
76
91
#define GRUB_TERM_STATUS_ALT (1 << 2)
79
/* Unicode characters for fancy graphics. */
80
#define GRUB_TERM_DISP_LEFT 0x2190
81
#define GRUB_TERM_DISP_UP 0x2191
82
#define GRUB_TERM_DISP_RIGHT 0x2192
83
#define GRUB_TERM_DISP_DOWN 0x2193
84
#define GRUB_TERM_DISP_HLINE 0x2501
85
#define GRUB_TERM_DISP_VLINE 0x2503
86
#define GRUB_TERM_DISP_UL 0x250F
87
#define GRUB_TERM_DISP_UR 0x2513
88
#define GRUB_TERM_DISP_LL 0x2517
89
#define GRUB_TERM_DISP_LR 0x251B
92
93
/* Menu-related geometrical constants. */
94
95
/* The number of lines of "GRUB version..." at the top. */
122
123
const char *name;
124
125
/* Initialize the terminal. */
125
grub_err_t (*init) (void);
126
grub_err_t (*init) (struct grub_term_input *term);
127
128
/* Clean up the terminal. */
128
grub_err_t (*fini) (void);
129
grub_err_t (*fini) (struct grub_term_input *term);
130
131
/* Check if any input character is available. */
131
int (*checkkey) (void);
132
int (*checkkey) (struct grub_term_input *term);
133
134
/* Get a character. */
134
int (*getkey) (void);
135
int (*getkey) (struct grub_term_input *term);
136
137
/* Get keyboard modifier status. */
137
int (*getkeystatus) (void);
138
int (*getkeystatus) (struct grub_term_input *term);
139
142
typedef struct grub_term_input *grub_term_input_t;
147
150
const char *name;
149
152
/* Initialize the terminal. */
150
grub_err_t (*init) (void);
153
grub_err_t (*init) (struct grub_term_output *term);
152
155
/* Clean up the terminal. */
153
grub_err_t (*fini) (void);
156
grub_err_t (*fini) (struct grub_term_output *term);
155
158
/* Put a character. C is encoded in Unicode. */
156
void (*putchar) (grub_uint32_t c);
159
void (*putchar) (struct grub_term_output *term,
160
const struct grub_unicode_glyph *c);
158
162
/* Get the number of columns occupied by a given character C. C is
159
163
encoded in Unicode. */
160
grub_ssize_t (*getcharwidth) (grub_uint32_t c);
164
grub_ssize_t (*getcharwidth) (struct grub_term_output *term,
165
const struct grub_unicode_glyph *c);
162
167
/* Get the screen size. The return value is ((Width << 8) | Height). */
163
grub_uint16_t (*getwh) (void);
168
grub_uint16_t (*getwh) (struct grub_term_output *term);
165
170
/* Get the cursor position. The return value is ((X << 8) | Y). */
166
grub_uint16_t (*getxy) (void);
171
grub_uint16_t (*getxy) (struct grub_term_output *term);
168
173
/* Go to the position (X, Y). */
169
void (*gotoxy) (grub_uint8_t x, grub_uint8_t y);
174
void (*gotoxy) (struct grub_term_output *term,
175
grub_uint8_t x, grub_uint8_t y);
171
177
/* Clear the screen. */
178
void (*cls) (struct grub_term_output *term);
174
180
/* Set the current color to be used */
175
void (*setcolorstate) (grub_term_color_state state);
177
/* Set the normal color and the highlight color. The format of each
179
void (*setcolor) (grub_uint8_t normal_color, grub_uint8_t highlight_color);
181
/* Get the normal color and the highlight color. The format of each
183
void (*getcolor) (grub_uint8_t *normal_color, grub_uint8_t *highlight_color);
181
void (*setcolorstate) (struct grub_term_output *term,
182
grub_term_color_state state);
185
184
/* Turn on/off the cursor. */
186
void (*setcursor) (int on);
185
void (*setcursor) (struct grub_term_output *term, int on);
188
187
/* Update the screen. */
189
void (*refresh) (void);
188
void (*refresh) (struct grub_term_output *term);
191
190
/* The feature flags defined above. */
192
191
grub_uint32_t flags;
193
/* Current color state. */
194
grub_uint8_t normal_color;
195
grub_uint8_t highlight_color;
194
199
typedef struct grub_term_output *grub_term_output_t;
201
#define GRUB_TERM_DEFAULT_NORMAL_COLOR 0x07
202
#define GRUB_TERM_DEFAULT_HIGHLIGHT_COLOR 0x70
203
#define GRUB_TERM_DEFAULT_STANDARD_COLOR 0x07
196
205
extern struct grub_term_output *EXPORT_VAR(grub_term_outputs_disabled);
197
206
extern struct grub_term_input *EXPORT_VAR(grub_term_inputs_disabled);
198
207
extern struct grub_term_output *EXPORT_VAR(grub_term_outputs);
210
219
/* If this is the first terminal, enable automatically. */
211
if (! term->init || term->init () == GRUB_ERR_NONE)
220
if (! term->init || term->init (term) == GRUB_ERR_NONE)
212
221
grub_list_push (GRUB_AS_LIST_P (&grub_term_inputs), GRUB_AS_LIST (term));
216
225
static inline void
226
grub_term_register_input_active (const char *name __attribute__ ((unused)),
227
grub_term_input_t term)
229
if (! term->init || term->init (term) == GRUB_ERR_NONE)
230
grub_list_push (GRUB_AS_LIST_P (&grub_term_inputs), GRUB_AS_LIST (term));
217
234
grub_term_register_output (const char *name __attribute__ ((unused)),
218
235
grub_term_output_t term)
225
242
/* If this is the first terminal, enable automatically. */
226
if (! term->init || term->init () == GRUB_ERR_NONE)
243
if (! term->init || term->init (term) == GRUB_ERR_NONE)
227
244
grub_list_push (GRUB_AS_LIST_P (&grub_term_outputs),
228
245
GRUB_AS_LIST (term));
232
249
static inline void
250
grub_term_register_output_active (const char *name __attribute__ ((unused)),
251
grub_term_output_t term)
253
if (! term->init || term->init (term) == GRUB_ERR_NONE)
254
grub_list_push (GRUB_AS_LIST_P (&grub_term_outputs),
255
GRUB_AS_LIST (term));
233
259
grub_term_unregister_input (grub_term_input_t term)
235
261
grub_list_remove (GRUB_AS_LIST_P (&grub_term_inputs), GRUB_AS_LIST (term));
250
276
#define FOR_ACTIVE_TERM_OUTPUTS(var) FOR_LIST_ELEMENTS((var), (grub_term_outputs))
251
277
#define FOR_DISABLED_TERM_OUTPUTS(var) FOR_LIST_ELEMENTS((var), (grub_term_outputs_disabled))
253
void EXPORT_FUNC(grub_putchar) (int c);
254
void EXPORT_FUNC(grub_putcode) (grub_uint32_t code,
255
struct grub_term_output *term);
279
void grub_putcode (grub_uint32_t code, struct grub_term_output *term);
256
280
int EXPORT_FUNC(grub_getkey) (void);
257
281
int EXPORT_FUNC(grub_checkkey) (void);
258
282
int EXPORT_FUNC(grub_getkeystatus) (void);
259
void EXPORT_FUNC(grub_cls) (void);
260
void EXPORT_FUNC(grub_setcolorstate) (grub_term_color_state state);
283
void grub_cls (void);
261
284
void EXPORT_FUNC(grub_refresh) (void);
262
285
void grub_puts_terminal (const char *str, struct grub_term_output *term);
263
286
grub_uint16_t *grub_term_save_pos (void);
314
337
static inline grub_uint16_t
315
338
grub_term_getxy (struct grub_term_output *term)
317
return term->getxy ();
340
return term->getxy (term);
320
343
static inline void
321
344
grub_term_refresh (struct grub_term_output *term)
323
346
if (term->refresh)
347
term->refresh (term);
327
350
static inline void
328
351
grub_term_gotoxy (struct grub_term_output *term, grub_uint8_t x, grub_uint8_t y)
353
term->gotoxy (term, x, y);
333
356
static inline void
335
358
grub_term_color_state state)
337
360
if (term->setcolorstate)
338
term->setcolorstate (state);
341
/* Set the normal color and the highlight color. The format of each
361
term->setcolorstate (term, state);
365
grub_setcolorstate (grub_term_color_state state)
367
struct grub_term_output *term;
369
FOR_ACTIVE_TERM_OUTPUTS(term)
370
grub_term_setcolorstate (term, state);
373
/* Set the normal color and the highlight color. The format of each
343
375
static inline void
344
376
grub_term_setcolor (struct grub_term_output *term,
345
377
grub_uint8_t normal_color, grub_uint8_t highlight_color)
348
term->setcolor (normal_color, highlight_color);
379
term->normal_color = normal_color;
380
term->highlight_color = highlight_color;
351
383
/* Turn on/off the cursor. */
403
#ifdef HAVE_UNIFONT_WIDTHSPEC
406
grub_unicode_estimate_width (const struct grub_unicode_glyph *c);
410
static inline grub_ssize_t
411
grub_unicode_estimate_width (const struct grub_unicode_glyph *c __attribute__ ((unused)))
413
if (grub_unicode_get_comb_type (c->base))
371
420
static inline grub_ssize_t
372
grub_term_getcharwidth (struct grub_term_output *term, grub_uint32_t c)
421
grub_term_getcharwidth (struct grub_term_output *term,
422
const struct grub_unicode_glyph *c)
374
424
if (term->getcharwidth)
375
return term->getcharwidth (c);
425
return term->getcharwidth (term, c);
426
else if (((term->flags & GRUB_TERM_CODE_TYPE_MASK)
427
== GRUB_TERM_CODE_TYPE_UTF8_LOGICAL)
428
|| ((term->flags & GRUB_TERM_CODE_TYPE_MASK)
429
== GRUB_TERM_CODE_TYPE_UTF8_VISUAL)
430
|| ((term->flags & GRUB_TERM_CODE_TYPE_MASK)
431
== GRUB_TERM_CODE_TYPE_VISUAL_GLYPHS))
432
return grub_unicode_estimate_width (c);
381
438
grub_term_getcolor (struct grub_term_output *term,
382
439
grub_uint8_t *normal_color, grub_uint8_t *highlight_color)
385
term->getcolor (normal_color, highlight_color);
388
*normal_color = 0x07;
389
*highlight_color = 0x07;
441
*normal_color = term->normal_color;
442
*highlight_color = term->highlight_color;
393
extern void (*EXPORT_VAR (grub_newline_hook)) (void);
395
445
struct grub_term_autoload
397
447
struct grub_term_autoload *next;