2 /* Copyright 1999 - Joseph Pranevich */
6 #include "console.h" /* Must define WINE_NCURSES */
10 /* This is the console driver for systems that support the ncurses
14 /* Actually, this should work for curses, as well. But there may be
15 individual functions that are unsupported in plain curses or other
16 variants. Those should be detected and special-cased by autoconf.
19 /* When creating new drivers, you need to assign all the functions that
20 that driver supports into the driver struct. If it is a supplementary
21 driver, it should make sure to perserve the old values.
27 #undef ERR /* Use ncurses's err() */
36 SCREEN
*ncurses_screen
;
38 static int get_color_pair(int fg_color
, int bg_color
);
40 const char *color_names
[] = {"null", "black", "blue", "green",
41 "cyan", "magenta", "brown", "red", "light gray", "dark gray",
42 "light blue", "light green", "light red", "light magenta",
43 "light cyan", "yellow", "white"};
47 /* This should be the root driver so we can ignore anything
48 already in the struct. */
50 driver
.norefresh
= FALSE
;
52 driver
.init
= NCURSES_Init
;
53 driver
.write
= NCURSES_Write
;
54 driver
.close
= NCURSES_Close
;
55 driver
.moveCursor
= NCURSES_MoveCursor
;
56 driver
.getCursorPosition
= NCURSES_GetCursorPosition
;
57 driver
.getCharacterAtCursor
= NCURSES_GetCharacterAtCursor
;
58 driver
.clearScreen
= NCURSES_ClearScreen
;
59 driver
.allocColor
= NCURSES_AllocColor
;
61 driver
.setBackgroundColor
= NCURSES_SetBackgroundColor
;
63 #ifdef HAVE_RESIZETERM
64 driver
.notifyResizeScreen
= NCURSES_NotifyResizeScreen
;
65 #endif /* HAVE_RESIZETERM */
67 driver
.checkForKeystroke
= NCURSES_CheckForKeystroke
;
68 driver
.getKeystroke
= NCURSES_GetKeystroke
;
70 driver
.refresh
= NCURSES_Refresh
;
75 char terminal_type
[80];
77 PROFILE_GetWineIniString("console", "TerminalType",
78 "xterm", terminal_type
, 79);
80 ncurses_screen
= newterm(terminal_type
, driver
.console_out
,
82 set_term(ncurses_screen
);
87 intrflush(stdscr
, FALSE
);
89 nodelay(stdscr
, TRUE
);
92 void NCURSES_Write(char output
, int fg
, int bg
, int attribute
)
98 fg
= COLOR_WHITE
; /* Default */
101 bg
= COLOR_BLACK
; /* Default */
103 pair
= get_color_pair(fg
, bg
);
105 if (waddch(stdscr
, output
| COLOR_PAIR(pair
)) == ERR
)
107 NCURSES_GetCursorPosition(&row
, &col
);
108 FIXME(console
, "NCURSES: waddch() failed at %d, %d.\n", row
, col
);
117 void NCURSES_GetKeystroke(char *scan
, char *ascii
)
119 while (!NCURSES_CheckForKeystroke(scan
, ascii
))
120 {} /* Wait until keystroke is detected */
122 /* When it is detected, we will already have the right value
123 in scan and ascii, but we need to take this keystroke
124 out of the buffer. */
128 int NCURSES_CheckForKeystroke(char *scan
, char *ascii
)
130 /* We don't currently support scan codes here */
133 temp
= wgetch(stdscr
);
140 ungetch(temp
); /* Keystroke not removed from buffer */
141 *ascii
= (char) temp
;
146 void NCURSES_MoveCursor(char row
, char col
)
148 if (wmove(stdscr
, row
, col
) == ERR
)
149 FIXME(console
, "NCURSES: wmove() failed to %d, %d.\n", row
, col
);
152 void NCURSES_GetCursorPosition(char *row
, char *col
)
156 getyx(stdscr
, trow
, tcol
); /* MACRO, no need to pass pointer */
162 void NCURSES_GetCharacterAtCursor(char *ch
, int *fg_color
, int
163 *bg_color
, int *attribute
)
165 /* If any of the pointers are NULL, ignore them */
166 /* We will eventually have to convert the color data */
168 *ch
= (char) winch(stdscr
);
170 *fg_color
= WINE_WHITE
;
172 *bg_color
= WINE_BLACK
;
177 void NCURSES_Refresh()
182 void NCURSES_ClearScreen()
187 int NCURSES_AllocColor(int color
)
189 /* Currently support only internal colors */
192 case WINE_BLACK
: return COLOR_BLACK
;
193 case WINE_WHITE
: return COLOR_WHITE
;
194 case WINE_RED
: return COLOR_RED
;
195 case WINE_GREEN
: return COLOR_GREEN
;
196 case WINE_YELLOW
: return COLOR_YELLOW
;
197 case WINE_BLUE
: return COLOR_BLUE
;
198 case WINE_MAGENTA
: return COLOR_MAGENTA
;
199 case WINE_CYAN
: return COLOR_CYAN
;
202 FIXME(console
, "Unable to allocate color %d (%s)\n", color
,
205 /* Don't allocate a color... yet */
209 void NCURSES_SetBackgroundColor(int fg
, int bg
)
213 pair
= get_color_pair(fg
, bg
);
215 wbkgd(stdscr
, COLOR_PAIR(pair
));
219 void NCURSES_GetBackgroundColor(int *fg
, int *bg
)
222 short pair
, sfg
, sbg
;
224 background
= getbkgd(stdscr
);
226 pair
= (!A_CHARTEXT
& background
);
228 pair_content(pair
, &sfg
, &sbg
);
233 #endif /* HAVE_GETBKGD */
235 #ifdef HAVE_RESIZETERM
237 void NCURSES_NotifyResizeScreen(int x
, int y
)
239 /* Note: This function gets called *after* another driver in the chain
240 calls ResizeScreen(). It is meant to resize the ncurses internal
241 data structures to know about the new window dimensions. */
243 TRACE(console
, "Terminal resized to y: %d, x: %d\n", y
, x
);
248 #endif /* HAVE_RESIZETERM */
250 static int get_color_pair(int fg_color
, int bg_color
)
252 /* ncurses internally uses "color pairs" in addition to the "pallet" */
253 /* This isn't the best way to do this. Or even close */
255 static int current
= 0;
256 static int fg
[255]; /* 16 x 16 is enough */
260 /* The first pair is hardwired into ncurses */
264 for (x
= 0; x
<= current
; x
++)
266 if ((fg_color
== fg
[x
]) && (bg_color
== bg
[x
]))
268 TRACE(console
, "Color pair: already allocated\n");
273 /* Need to allocate new color */
275 fg
[current
] = fg_color
;
276 bg
[current
] = bg_color
;
277 TRACE(console
, "Color pair: allocated.\n");
278 return init_pair(current
, fg_color
, bg_color
);
281 #endif /* WINE_NCURSES */