Reading joystick 5 when we only support 4 should fail instead of
[wine/multimedia.git] / console / ncurses.c
blob6429221019c4751d26da23d3ab42a38aa6759487
1 /* ncurses.c */
3 #include "config.h"
5 #ifdef WINE_NCURSES
7 /* This is the console driver for systems that support the ncurses
8 interface.
9 */
11 /* Actually, this should work for curses, as well. But there may be
12 individual functions that are unsupported in plain curses or other
13 variants. Those should be detected and special-cased by autoconf.
16 /* When creating new drivers, you need to assign all the functions that
17 that driver supports into the driver struct. If it is a supplementary
18 driver, it should make sure to perserve the old values.
21 #include "console.h"
22 #include "debug.h"
23 #undef ERR /* Use ncurses's err() */
24 #include <curses.h>
26 SCREEN *ncurses_screen;
28 void NCURSES_Start()
30 /* This should be the root driver so we can ignore anything
31 already in the struct. */
33 driver.norefresh = FALSE;
35 driver.init = NCURSES_Init;
36 driver.write = NCURSES_Write;
37 driver.close = NCURSES_Close;
38 driver.moveCursor = NCURSES_MoveCursor;
39 driver.getCursorPosition = NCURSES_GetCursorPosition;
40 driver.getCharacterAtCursor = NCURSES_GetCharacterAtCursor;
41 driver.clearScreen = NCURSES_ClearScreen;
43 driver.checkForKeystroke = NCURSES_CheckForKeystroke;
44 driver.getKeystroke = NCURSES_GetKeystroke;
46 driver.refresh = NCURSES_Refresh;
49 void NCURSES_Init()
51 ncurses_screen = newterm("xterm", driver.console_out,
52 driver.console_in);
53 set_term(ncurses_screen);
54 cbreak();
55 noecho();
56 nonl();
57 intrflush(stdscr, FALSE);
58 keypad(stdscr, TRUE);
59 nodelay(stdscr, TRUE);
62 void NCURSES_Write(char output, int fg, int bg, int attribute)
64 /* We can discard all extended information. */
65 waddch(stdscr, output);
68 void NCURSES_Close()
70 endwin();
73 void NCURSES_GetKeystroke(char *scan, char *ascii)
75 while (!NCURSES_CheckForKeystroke(scan, ascii))
76 {} /* Wait until keystroke is detected */
78 /* When it is detected, we will already have the right value
79 in scan and ascii, but we need to take this keystroke
80 out of the buffer. */
81 wgetch(stdscr);
84 int NCURSES_CheckForKeystroke(char *scan, char *ascii)
86 /* We don't currently support scan codes here */
87 /* FIXME */
88 int temp;
89 temp = wgetch(stdscr);
90 if (temp == ERR)
92 return FALSE;
94 else
96 ungetch(temp); /* Keystroke not removed from buffer */
97 *ascii = (char) temp;
98 return TRUE;
102 void NCURSES_MoveCursor(char row, char col)
104 wmove(stdscr, row, col);
107 void NCURSES_GetCursorPosition(char *row, char *col)
109 int trow, tcol;
111 getyx(stdscr, trow, tcol); /* MACRO, no need to pass pointer */
113 *row = (char) trow;
114 *col = (char) tcol;
117 void NCURSES_GetCharacterAtCursor(char *ch, int *fg_color, int
118 *bg_color, int *attribute)
120 /* We will eventually have to convert the color data */
121 *ch = (char) winch(stdscr);
122 *fg_color = 0;
123 *bg_color = 0;
124 *attribute = 0;
127 void NCURSES_Refresh()
129 wrefresh(stdscr);
132 void NCURSES_ClearScreen()
134 werase(stdscr);
137 #endif /* WINE_NCURSES */