~ubuntu-branches/debian/stretch/grub2/stretch

« back to all changes in this revision

Viewing changes to include/grub/term.h

Tags: upstream-1.98+20100705
ImportĀ upstreamĀ versionĀ 1.98+20100705

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
#include <grub/err.h>
39
39
#include <grub/symbol.h>
40
40
#include <grub/types.h>
 
41
#include <grub/unicode.h>
41
42
#include <grub/list.h>
42
43
 
43
44
/* These are used to represent the various color states we use.  */
63
64
   to NULL.  */
64
65
 
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)
71
86
 
72
87
 
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)
77
92
 
78
 
 
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
90
 
 
91
 
 
92
93
/* Menu-related geometrical constants.  */
93
94
 
94
95
/* The number of lines of "GRUB version..." at the top.  */
122
123
  const char *name;
123
124
 
124
125
  /* Initialize the terminal.  */
125
 
  grub_err_t (*init) (void);
 
126
  grub_err_t (*init) (struct grub_term_input *term);
126
127
 
127
128
  /* Clean up the terminal.  */
128
 
  grub_err_t (*fini) (void);
 
129
  grub_err_t (*fini) (struct grub_term_input *term);
129
130
 
130
131
  /* Check if any input character is available.  */
131
 
  int (*checkkey) (void);
 
132
  int (*checkkey) (struct grub_term_input *term);
132
133
 
133
134
  /* Get a character.  */
134
 
  int (*getkey) (void);
 
135
  int (*getkey) (struct grub_term_input *term);
135
136
 
136
137
  /* Get keyboard modifier status.  */
137
 
  int (*getkeystatus) (void);
 
138
  int (*getkeystatus) (struct grub_term_input *term);
 
139
 
 
140
  void *data;
138
141
};
139
142
typedef struct grub_term_input *grub_term_input_t;
140
143
 
147
150
  const char *name;
148
151
 
149
152
  /* Initialize the terminal.  */
150
 
  grub_err_t (*init) (void);
 
153
  grub_err_t (*init) (struct grub_term_output *term);
151
154
 
152
155
  /* Clean up the terminal.  */
153
 
  grub_err_t (*fini) (void);
 
156
  grub_err_t (*fini) (struct grub_term_output *term);
154
157
 
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);
157
161
 
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);
161
166
 
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);
164
169
 
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);
167
172
 
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);
170
176
 
171
177
  /* Clear the screen.  */
172
 
  void (*cls) (void);
 
178
  void (*cls) (struct grub_term_output *term);
173
179
 
174
180
  /* Set the current color to be used */
175
 
  void (*setcolorstate) (grub_term_color_state state);
176
 
 
177
 
  /* Set the normal color and the highlight color. The format of each
178
 
     color is VGA's.  */
179
 
  void (*setcolor) (grub_uint8_t normal_color, grub_uint8_t highlight_color);
180
 
 
181
 
  /* Get the normal color and the highlight color. The format of each
182
 
     color is VGA's.  */
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);
184
183
 
185
184
  /* Turn on/off the cursor.  */
186
 
  void (*setcursor) (int on);
 
185
  void (*setcursor) (struct grub_term_output *term, int on);
187
186
 
188
187
  /* Update the screen.  */
189
 
  void (*refresh) (void);
 
188
  void (*refresh) (struct grub_term_output *term);
190
189
 
191
190
  /* The feature flags defined above.  */
192
191
  grub_uint32_t flags;
 
192
 
 
193
  /* Current color state.  */
 
194
  grub_uint8_t normal_color;
 
195
  grub_uint8_t highlight_color;
 
196
 
 
197
  void *data;
193
198
};
194
199
typedef struct grub_term_output *grub_term_output_t;
195
200
 
 
201
#define GRUB_TERM_DEFAULT_NORMAL_COLOR 0x07
 
202
#define GRUB_TERM_DEFAULT_HIGHLIGHT_COLOR 0x70
 
203
#define GRUB_TERM_DEFAULT_STANDARD_COLOR 0x07
 
204
 
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);
208
217
  else
209
218
    {
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));
213
222
    }
214
223
}
215
224
 
216
225
static inline void
 
226
grub_term_register_input_active (const char *name __attribute__ ((unused)),
 
227
                                 grub_term_input_t term)
 
228
{
 
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));
 
231
}
 
232
 
 
233
static inline void
217
234
grub_term_register_output (const char *name __attribute__ ((unused)),
218
235
                           grub_term_output_t term)
219
236
{
223
240
  else
224
241
    {
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));
229
246
    }
230
247
}
231
248
 
232
249
static inline void
 
250
grub_term_register_output_active (const char *name __attribute__ ((unused)),
 
251
                                  grub_term_output_t term)
 
252
{
 
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));
 
256
}
 
257
 
 
258
static inline void
233
259
grub_term_unregister_input (grub_term_input_t term)
234
260
{
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))
252
278
 
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);
265
288
 
266
289
static inline unsigned grub_term_width (struct grub_term_output *term)
267
290
{
268
 
  return ((term->getwh()&0xFF00)>>8);
 
291
  return ((term->getwh(term)&0xFF00)>>8);
269
292
}
270
293
 
271
294
static inline unsigned grub_term_height (struct grub_term_output *term)
272
295
{
273
 
  return (term->getwh()&0xFF);
 
296
  return (term->getwh(term)&0xFF);
274
297
}
275
298
 
276
299
/* The width of the border.  */
314
337
static inline grub_uint16_t
315
338
grub_term_getxy (struct grub_term_output *term)
316
339
{
317
 
  return term->getxy ();
 
340
  return term->getxy (term);
318
341
}
319
342
 
320
343
static inline void
321
344
grub_term_refresh (struct grub_term_output *term)
322
345
{
323
346
  if (term->refresh)
324
 
    term->refresh ();
 
347
    term->refresh (term);
325
348
}
326
349
 
327
350
static inline void
328
351
grub_term_gotoxy (struct grub_term_output *term, grub_uint8_t x, grub_uint8_t y)
329
352
{
330
 
  term->gotoxy (x, y);
 
353
  term->gotoxy (term, x, y);
331
354
}
332
355
 
333
356
static inline void 
335
358
                         grub_term_color_state state)
336
359
{
337
360
  if (term->setcolorstate)
338
 
    term->setcolorstate (state);
339
 
}
340
 
 
341
 
  /* Set the normal color and the highlight color. The format of each
342
 
     color is VGA's.  */
 
361
    term->setcolorstate (term, state);
 
362
}
 
363
 
 
364
static inline void
 
365
grub_setcolorstate (grub_term_color_state state)
 
366
{
 
367
  struct grub_term_output *term;
 
368
  
 
369
  FOR_ACTIVE_TERM_OUTPUTS(term)
 
370
    grub_term_setcolorstate (term, state);
 
371
}
 
372
 
 
373
/* Set the normal color and the highlight color. The format of each
 
374
   color is VGA's.  */
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)
346
378
{
347
 
  if (term->setcolor)
348
 
    term->setcolor (normal_color, highlight_color);
 
379
  term->normal_color = normal_color;
 
380
  term->highlight_color = highlight_color;
349
381
}
350
382
 
351
383
/* Turn on/off the cursor.  */
353
385
grub_term_setcursor (struct grub_term_output *term, int on)
354
386
{
355
387
  if (term->setcursor)
356
 
    term->setcursor (on);
 
388
    term->setcursor (term, on);
357
389
}
358
390
 
359
391
static inline void 
360
392
grub_term_cls (struct grub_term_output *term)
361
393
{
362
394
  if (term->cls)
363
 
    (term->cls) ();
 
395
    (term->cls) (term);
364
396
  else
365
397
    {
366
398
      grub_putcode ('\n', term);
368
400
    }
369
401
}
370
402
 
 
403
#ifdef HAVE_UNIFONT_WIDTHSPEC
 
404
 
 
405
grub_ssize_t
 
406
grub_unicode_estimate_width (const struct grub_unicode_glyph *c);
 
407
 
 
408
#else
 
409
 
 
410
static inline grub_ssize_t
 
411
grub_unicode_estimate_width (const struct grub_unicode_glyph *c __attribute__ ((unused)))
 
412
{
 
413
  if (grub_unicode_get_comb_type (c->base))
 
414
    return 0;
 
415
  return 1;
 
416
}
 
417
 
 
418
#endif
 
419
 
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)
373
423
{
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);
376
433
  else
377
434
    return 1;
378
435
}
381
438
grub_term_getcolor (struct grub_term_output *term, 
382
439
                    grub_uint8_t *normal_color, grub_uint8_t *highlight_color)
383
440
{
384
 
  if (term->getcolor)
385
 
    term->getcolor (normal_color, highlight_color);
386
 
  else
387
 
    {
388
 
      *normal_color = 0x07;
389
 
      *highlight_color = 0x07;
390
 
    }
 
441
  *normal_color = term->normal_color;
 
442
  *highlight_color = term->highlight_color;
391
443
}
392
444
 
393
 
extern void (*EXPORT_VAR (grub_newline_hook)) (void);
394
 
 
395
445
struct grub_term_autoload
396
446
{
397
447
  struct grub_term_autoload *next;