1 /* console.c -- Ncurses console for GRUB. */
3 * GRUB -- GRand Unified Bootloader
4 * Copyright (C) 2003,2005 Free Software Foundation, Inc.
6 * This program 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 2 of the License, or
9 * (at your option) any later version.
11 * This program 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 this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #if defined(HAVE_NCURSES_CURSES_H)
24 # include <ncurses/curses.h>
25 #elif defined(HAVE_NCURSES_H)
27 #elif defined(HAVE_CURSES_H)
31 /* For compatibility. */
34 #endif /* ! A_NORMAL */
37 #endif /* ! A_STANDOUT */
39 #include <grub/machine/console.h>
40 #include <grub/term.h>
41 #include <grub/types.h>
43 static int grub_console_attr
= A_NORMAL
;
46 grub_ncurses_putchar (grub_uint32_t c
)
48 /* Better than nothing. */
51 case GRUB_TERM_DISP_LEFT
:
55 case GRUB_TERM_DISP_UP
:
59 case GRUB_TERM_DISP_RIGHT
:
63 case GRUB_TERM_DISP_DOWN
:
67 case GRUB_TERM_DISP_HLINE
:
71 case GRUB_TERM_DISP_VLINE
:
75 case GRUB_TERM_DISP_UL
:
76 case GRUB_TERM_DISP_UR
:
77 case GRUB_TERM_DISP_LL
:
78 case GRUB_TERM_DISP_LR
:
83 /* ncurses does not support Unicode. */
89 addch (c
| grub_console_attr
);
93 grub_ncurses_getcharwidth (grub_uint32_t code
__attribute__ ((unused
)))
99 grub_ncurses_setcolorstate (grub_term_color_state state
)
103 case GRUB_TERM_COLOR_STANDARD
:
104 grub_console_attr
= A_NORMAL
;
106 case GRUB_TERM_COLOR_NORMAL
:
107 grub_console_attr
= A_NORMAL
;
109 case GRUB_TERM_COLOR_HIGHLIGHT
:
110 grub_console_attr
= A_STANDOUT
;
117 /* XXX: This function is never called. */
119 grub_ncurses_setcolor (grub_uint8_t normal_color
, grub_uint8_t highlight_color
)
121 color_set (normal_color
<< 8 | highlight_color
, 0);
124 static int saved_char
= ERR
;
127 grub_ncurses_checkkey (void)
131 /* Check for SAVED_CHAR. This should not be true, because this
132 means checkkey is called twice continuously. */
133 if (saved_char
!= ERR
)
136 wtimeout (stdscr
, 100);
138 /* If C is not ERR, then put it back in the input queue. */
149 grub_ncurses_getkey (void)
153 /* If checkkey has already got a character, then return it. */
154 if (saved_char
!= ERR
)
161 wtimeout (stdscr
, -1);
168 c
= GRUB_CONSOLE_KEY_LEFT
;
172 c
= GRUB_CONSOLE_KEY_RIGHT
;
176 c
= GRUB_CONSOLE_KEY_UP
;
180 c
= GRUB_CONSOLE_KEY_DOWN
;
184 c
= GRUB_CONSOLE_KEY_IC
;
188 c
= GRUB_CONSOLE_KEY_DC
;
192 /* XXX: For some reason ncurses on xterm does not return
195 c
= GRUB_CONSOLE_KEY_BACKSPACE
;
199 c
= GRUB_CONSOLE_KEY_HOME
;
203 c
= GRUB_CONSOLE_KEY_END
;
207 c
= GRUB_CONSOLE_KEY_NPAGE
;
211 c
= GRUB_CONSOLE_KEY_PPAGE
;
219 grub_ncurses_getxy (void)
224 getyx (stdscr
, y
, x
);
230 grub_ncurses_getwh (void)
235 getmaxyx (stdscr
, y
, x
);
241 grub_ncurses_gotoxy (grub_uint8_t x
, grub_uint8_t y
)
247 grub_ncurses_cls (void)
254 grub_ncurses_setcursor (int on
)
256 curs_set (on
? 1 : 0);
260 grub_ncurses_refresh (void)
266 grub_ncurses_init (void)
271 scrollok (stdscr
, TRUE
);
274 intrflush (stdscr
, FALSE
);
275 keypad (stdscr
, TRUE
);
282 grub_ncurses_fini (void)
289 static struct grub_term grub_ncurses_term
=
292 .init
= grub_ncurses_init
,
293 .fini
= grub_ncurses_fini
,
294 .putchar
= grub_ncurses_putchar
,
295 .getcharwidth
= grub_ncurses_getcharwidth
,
296 .checkkey
= grub_ncurses_checkkey
,
297 .getkey
= grub_ncurses_getkey
,
298 .getxy
= grub_ncurses_getxy
,
299 .getwh
= grub_ncurses_getwh
,
300 .gotoxy
= grub_ncurses_gotoxy
,
301 .cls
= grub_ncurses_cls
,
302 .setcolorstate
= grub_ncurses_setcolorstate
,
303 .setcolor
= grub_ncurses_setcolor
,
304 .setcursor
= grub_ncurses_setcursor
,
305 .refresh
= grub_ncurses_refresh
,
311 grub_console_init (void)
313 grub_term_register (&grub_ncurses_term
);
314 grub_term_set_current (&grub_ncurses_term
);
318 grub_console_fini (void)
320 grub_ncurses_fini ();