~darkmuggle-deactivatedaccount/ubuntu/quantal/grub2/fix-872244

« back to all changes in this revision

Viewing changes to include/grub/term.h

  • Committer: Bazaar Package Importer
  • Author(s): Otavio Salvador
  • Date: 2006-01-05 15:20:40 UTC
  • mto: (17.3.1 squeeze) (1.9.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20060105152040-b72i5pq1a82z22yi
Tags: upstream-1.92
ImportĀ upstreamĀ versionĀ 1.92

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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: Ugly way to get them form terminal.  */
 
75
#define GRUB_TERM_WIDTH         ((grub_getwh()&0xFF00)>>8)
 
76
#define GRUB_TERM_HEIGHT        (grub_getwh()&0xFF)
 
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
  /* Get the number of columns occupied by a given character C. C is
 
140
     encoded in Unicode.  */
 
141
  grub_ssize_t (*getcharwidth) (grub_uint32_t c);
 
142
  
 
143
  /* Check if any input character is available.  */
 
144
  int (*checkkey) (void);
 
145
  
 
146
  /* Get a character.  */
 
147
  int (*getkey) (void);
 
148
  
 
149
  /* Get the screen size. The return value is ((Width << 8) | Height).  */
 
150
  grub_uint16_t (*getwh) (void);
 
151
 
 
152
  /* Get the cursor position. The return value is ((X << 8) | Y).  */
 
153
  grub_uint16_t (*getxy) (void);
 
154
  
 
155
  /* Go to the position (X, Y).  */
 
156
  void (*gotoxy) (grub_uint8_t x, grub_uint8_t y);
 
157
  
 
158
  /* Clear the screen.  */
 
159
  void (*cls) (void);
 
160
  
 
161
  /* Set the current color to be used */
 
162
  void (*setcolorstate) (grub_term_color_state state);
 
163
  
 
164
  /* Set the normal color and the highlight color. The format of each
 
165
     color is VGA's.  */
 
166
  void (*setcolor) (grub_uint8_t normal_color, grub_uint8_t highlight_color);
 
167
  
 
168
  /* Turn on/off the cursor.  */
 
169
  void (*setcursor) (int on);
 
170
 
 
171
  /* Update the screen.  */
 
172
  void (*refresh) (void);
 
173
 
 
174
  /* The feature flags defined above.  */
 
175
  grub_uint32_t flags;
 
176
  
 
177
  /* The next terminal.  */
 
178
  struct grub_term *next;
 
179
};
 
180
typedef struct grub_term *grub_term_t;
 
181
 
 
182
void EXPORT_FUNC(grub_term_register) (grub_term_t term);
 
183
void EXPORT_FUNC(grub_term_unregister) (grub_term_t term);
 
184
void EXPORT_FUNC(grub_term_iterate) (int (*hook) (grub_term_t term));
 
185
 
 
186
grub_err_t EXPORT_FUNC(grub_term_set_current) (grub_term_t term);
 
187
grub_term_t EXPORT_FUNC(grub_term_get_current) (void);
 
188
 
 
189
void EXPORT_FUNC(grub_putchar) (int c);
 
190
void EXPORT_FUNC(grub_putcode) (grub_uint32_t code);
 
191
grub_ssize_t EXPORT_FUNC(grub_getcharwidth) (grub_uint32_t code);
 
192
int EXPORT_FUNC(grub_getkey) (void);
 
193
int EXPORT_FUNC(grub_checkkey) (void);
 
194
grub_uint16_t EXPORT_FUNC(grub_getwh) (void);
 
195
grub_uint16_t EXPORT_FUNC(grub_getxy) (void);
 
196
void EXPORT_FUNC(grub_gotoxy) (grub_uint8_t x, grub_uint8_t y);
 
197
void EXPORT_FUNC(grub_cls) (void);
 
198
void EXPORT_FUNC(grub_setcolorstate) (grub_term_color_state state);
 
199
void EXPORT_FUNC(grub_setcolor) (grub_uint8_t normal_color,
 
200
                                 grub_uint8_t highlight_color);
 
201
int EXPORT_FUNC(grub_setcursor) (int on);
 
202
int EXPORT_FUNC(grub_getcursor) (void);
 
203
void EXPORT_FUNC(grub_refresh) (void);
 
204
void EXPORT_FUNC(grub_set_more) (int onoff);
 
205
 
 
206
/* For convenience.  */
 
207
#define GRUB_TERM_ASCII_CHAR(c) ((c) & 0xff)
 
208
 
 
209
#endif /* ! GRUB_TERM_HEADER */