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.
24 #include "debugtools.h"
27 DEFAULT_DEBUG_CHANNEL(console
)
29 #undef ERR /* Use ncurses's err() */
38 SCREEN
*ncurses_screen
;
40 static int get_color_pair(int fg_color
, int bg_color
);
42 const char *color_names
[] = {"null", "black", "blue", "green",
43 "cyan", "magenta", "brown", "red", "light gray", "dark gray",
44 "light blue", "light green", "light red", "light magenta",
45 "light cyan", "yellow", "white"};
49 /* This should be the root driver so we can ignore anything
50 already in the struct. */
52 driver
.norefresh
= FALSE
;
54 driver
.init
= NCURSES_Init
;
55 driver
.write
= NCURSES_Write
;
56 driver
.close
= NCURSES_Close
;
57 driver
.moveCursor
= NCURSES_MoveCursor
;
58 driver
.getCursorPosition
= NCURSES_GetCursorPosition
;
59 driver
.getCharacterAtCursor
= NCURSES_GetCharacterAtCursor
;
60 driver
.clearScreen
= NCURSES_ClearScreen
;
61 driver
.allocColor
= NCURSES_AllocColor
;
63 driver
.setBackgroundColor
= NCURSES_SetBackgroundColor
;
65 #ifdef HAVE_RESIZETERM
66 driver
.notifyResizeScreen
= NCURSES_NotifyResizeScreen
;
67 #endif /* HAVE_RESIZETERM */
69 driver
.checkForKeystroke
= NCURSES_CheckForKeystroke
;
70 driver
.getKeystroke
= NCURSES_GetKeystroke
;
72 driver
.refresh
= NCURSES_Refresh
;
77 char terminal_type
[80];
79 PROFILE_GetWineIniString("console", "TerminalType",
80 "xterm", terminal_type
, 79);
82 ncurses_screen
= newterm(terminal_type
, driver
.console_out
,
84 set_term(ncurses_screen
);
89 intrflush(stdscr
, FALSE
);
91 nodelay(stdscr
, TRUE
);
94 void NCURSES_Write(char output
, int fg
, int bg
, int attribute
)
100 fg
= COLOR_WHITE
; /* Default */
103 bg
= COLOR_BLACK
; /* Default */
105 pair
= get_color_pair(fg
, bg
);
107 if (waddch(stdscr
, output
| COLOR_PAIR(pair
)) == ERR
)
109 NCURSES_GetCursorPosition(&row
, &col
);
110 FIXME("NCURSES: waddch() failed at %d, %d.\n", row
, col
);
119 void NCURSES_GetKeystroke(char *scan
, char *ascii
)
121 while (!NCURSES_CheckForKeystroke(scan
, ascii
))
122 {} /* Wait until keystroke is detected */
124 /* When it is detected, we will already have the right value
125 in scan and ascii, but we need to take this keystroke
126 out of the buffer. */
130 int NCURSES_CheckForKeystroke(char *scan
, char *ascii
)
132 /* We don't currently support scan codes here */
135 temp
= wgetch(stdscr
);
142 ungetch(temp
); /* Keystroke not removed from buffer */
143 *ascii
= (char) temp
;
148 void NCURSES_MoveCursor(char row
, char col
)
150 if (wmove(stdscr
, row
, col
) == ERR
)
151 FIXME("NCURSES: wmove() failed to %d, %d.\n", row
, col
);
154 void NCURSES_GetCursorPosition(char *row
, char *col
)
158 getyx(stdscr
, trow
, tcol
); /* MACRO, no need to pass pointer */
164 void NCURSES_GetCharacterAtCursor(char *ch
, int *fg_color
, int
165 *bg_color
, int *attribute
)
167 /* If any of the pointers are NULL, ignore them */
168 /* We will eventually have to convert the color data */
170 *ch
= (char) winch(stdscr
);
172 *fg_color
= WINE_WHITE
;
174 *bg_color
= WINE_BLACK
;
179 void NCURSES_Refresh()
184 void NCURSES_ClearScreen()
189 int NCURSES_AllocColor(int color
)
191 /* Currently support only internal colors */
194 case WINE_BLACK
: return COLOR_BLACK
;
195 case WINE_WHITE
: return COLOR_WHITE
;
196 case WINE_RED
: return COLOR_RED
;
197 case WINE_GREEN
: return COLOR_GREEN
;
198 case WINE_YELLOW
: return COLOR_YELLOW
;
199 case WINE_BLUE
: return COLOR_BLUE
;
200 case WINE_MAGENTA
: return COLOR_MAGENTA
;
201 case WINE_CYAN
: return COLOR_CYAN
;
204 FIXME("Unable to allocate color %d (%s)\n", color
,
207 /* Don't allocate a color... yet */
211 void NCURSES_SetBackgroundColor(int fg
, int bg
)
215 pair
= get_color_pair(fg
, bg
);
217 wbkgd(stdscr
, COLOR_PAIR(pair
));
221 void NCURSES_GetBackgroundColor(int *fg
, int *bg
)
224 short pair
, sfg
, sbg
;
226 background
= getbkgd(stdscr
);
228 pair
= (!A_CHARTEXT
& background
);
230 pair_content(pair
, &sfg
, &sbg
);
235 #endif /* HAVE_GETBKGD */
237 #ifdef HAVE_RESIZETERM
239 void NCURSES_NotifyResizeScreen(int x
, int y
)
241 /* Note: This function gets called *after* another driver in the chain
242 calls ResizeScreen(). It is meant to resize the ncurses internal
243 data structures to know about the new window dimensions. */
245 TRACE("Terminal resized to y: %d, x: %d\n", y
, x
);
250 #endif /* HAVE_RESIZETERM */
252 static int get_color_pair(int fg_color
, int bg_color
)
254 /* ncurses internally uses "color pairs" in addition to the "pallet" */
255 /* This isn't the best way to do this. Or even close */
257 static int current
= 0;
258 static int fg
[255]; /* 16 x 16 is enough */
262 /* The first pair is hardwired into ncurses */
266 for (x
= 0; x
<= current
; x
++)
268 if ((fg_color
== fg
[x
]) && (bg_color
== bg
[x
]))
270 TRACE("Color pair: already allocated\n");
275 /* Need to allocate new color */
277 fg
[current
] = fg_color
;
278 bg
[current
] = bg_color
;
279 TRACE("Color pair: allocated.\n");
280 return init_pair(current
, fg_color
, bg_color
);
283 #endif /* WINE_NCURSES */