1
/* console.c -- Ncurses console for GRUB. */
3
* GRUB -- GRand Unified Bootloader
4
* Copyright (C) 2003,2005,2007,2008 Free Software Foundation, Inc.
6
* GRUB is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
11
* GRUB is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
21
#include <config-util.h>
23
/* For compatibility. */
26
#endif /* ! A_NORMAL */
29
#endif /* ! A_STANDOUT */
31
#include <grub/emu/console.h>
32
#include <grub/term.h>
33
#include <grub/types.h>
35
#if defined(HAVE_NCURSES_CURSES_H)
36
# include <ncurses/curses.h>
37
#elif defined(HAVE_NCURSES_H)
39
#elif defined(HAVE_CURSES_H)
45
static int grub_console_attr = A_NORMAL;
47
grub_uint8_t grub_console_cur_color = 7;
49
static const grub_uint8_t grub_console_standard_color = 0x7;
53
static grub_uint8_t color_map[NUM_COLORS] =
68
grub_ncurses_putchar (struct grub_term_output *term __attribute__ ((unused)),
69
const struct grub_unicode_glyph *c)
71
addch (c->base | grub_console_attr);
75
grub_ncurses_setcolorstate (struct grub_term_output *term,
76
grub_term_color_state state)
80
case GRUB_TERM_COLOR_STANDARD:
81
grub_console_cur_color = grub_console_standard_color;
82
grub_console_attr = A_NORMAL;
84
case GRUB_TERM_COLOR_NORMAL:
85
grub_console_cur_color = term->normal_color;
86
grub_console_attr = A_NORMAL;
88
case GRUB_TERM_COLOR_HIGHLIGHT:
89
grub_console_cur_color = term->highlight_color;
90
grub_console_attr = A_STANDOUT;
100
fg = (grub_console_cur_color & 7);
101
bg = (grub_console_cur_color >> 4) & 7;
103
grub_console_attr = (grub_console_cur_color & 8) ? A_BOLD : A_NORMAL;
104
color_set ((bg << 3) + fg, 0);
109
grub_ncurses_getkey (struct grub_term_input *term __attribute__ ((unused)))
113
wtimeout (stdscr, 100);
121
c = GRUB_TERM_KEY_LEFT;
125
c = GRUB_TERM_KEY_RIGHT;
129
c = GRUB_TERM_KEY_UP;
133
c = GRUB_TERM_KEY_DOWN;
141
c = GRUB_TERM_KEY_DC;
145
/* XXX: For some reason ncurses on xterm does not return
152
c = GRUB_TERM_KEY_HOME;
156
c = GRUB_TERM_KEY_END;
160
c = GRUB_TERM_KEY_NPAGE;
164
c = GRUB_TERM_KEY_PPAGE;
172
grub_ncurses_getxy (struct grub_term_output *term __attribute__ ((unused)))
177
getyx (stdscr, y, x);
183
grub_ncurses_getwh (struct grub_term_output *term __attribute__ ((unused)))
188
getmaxyx (stdscr, y, x);
194
grub_ncurses_gotoxy (struct grub_term_output *term __attribute__ ((unused)),
195
grub_uint8_t x, grub_uint8_t y)
201
grub_ncurses_cls (struct grub_term_output *term __attribute__ ((unused)))
208
grub_ncurses_setcursor (struct grub_term_output *term __attribute__ ((unused)),
211
curs_set (on ? 1 : 0);
215
grub_ncurses_refresh (struct grub_term_output *term __attribute__ ((unused)))
221
grub_ncurses_init (struct grub_term_output *term __attribute__ ((unused)))
226
scrollok (stdscr, TRUE);
229
intrflush (stdscr, FALSE);
230
keypad (stdscr, TRUE);
236
if ((COLORS >= NUM_COLORS) && (COLOR_PAIRS >= NUM_COLORS * NUM_COLORS))
241
for (i = 0; i < NUM_COLORS; i++)
242
for (j = 0; j < NUM_COLORS; j++)
243
init_pair(n++, color_map[j], color_map[i]);
253
grub_ncurses_fini (struct grub_term_output *term __attribute__ ((unused)))
260
static struct grub_term_input grub_ncurses_term_input =
263
.getkey = grub_ncurses_getkey,
266
static struct grub_term_output grub_ncurses_term_output =
269
.init = grub_ncurses_init,
270
.fini = grub_ncurses_fini,
271
.putchar = grub_ncurses_putchar,
272
.getxy = grub_ncurses_getxy,
273
.getwh = grub_ncurses_getwh,
274
.gotoxy = grub_ncurses_gotoxy,
275
.cls = grub_ncurses_cls,
276
.setcolorstate = grub_ncurses_setcolorstate,
277
.setcursor = grub_ncurses_setcursor,
278
.refresh = grub_ncurses_refresh,
279
.flags = GRUB_TERM_CODE_TYPE_ASCII
283
grub_console_init (void)
285
grub_term_register_output ("console", &grub_ncurses_term_output);
286
grub_term_register_input ("console", &grub_ncurses_term_input);
290
grub_console_fini (void)
292
grub_ncurses_fini (&grub_ncurses_term_output);