3 /* The primary purpose of this function is to provide CONSOLE_*
4 reotines that immediately call the appropiate driver handler.
5 This cleans up code in the individual modules considerably.
6 This could be done using a macro, but additional functionality
7 may be provided here in the future. */
17 static int pop_driver(char **, char **, int *);
19 static int console_initialized = FALSE;
21 int CONSOLE_Init(char *drivers)
23 /* When this function is called drivers should be a string
24 that consists of driver names followed by plus (+) signs
28 drivers = tty Load just the tty driver
29 drivers = ncurses+xterm Load ncurses then xterm
31 The "default" value is just tty.
37 /* Suitable defaults... */
38 driver.console_out = stdout;
39 driver.console_in = stdin;
41 while (pop_driver(&drivers, &single, &length))
43 if (!strncmp(single, "tty", length))
46 else if (!strncmp(single, "ncurses", length))
48 #endif /* WINE_NCURSES */
49 else if (!strncmp(single, "xterm", length))
58 /* For now, always return TRUE */
62 void CONSOLE_Write(char out, int fg_color, int bg_color, int attribute)
64 if (!console_initialized)
65 console_initialized = CONSOLE_Init(driver.driver_list);
69 driver.write(out, fg_color, bg_color, attribute);
70 if (!driver.norefresh)
81 void CONSOLE_MoveCursor(char row, char col)
83 if (!console_initialized)
84 console_initialized = CONSOLE_Init(driver.driver_list);
86 if (driver.moveCursor)
88 driver.moveCursor(row, col);
89 if (!driver.norefresh)
94 void CONSOLE_ClearWindow(char row1, char col1, char row2, char col2,
95 int bg_color, int attribute)
97 if (!console_initialized)
98 console_initialized = CONSOLE_Init(driver.driver_list);
100 if (driver.clearWindow)
102 driver.clearWindow(row1, col1, row2, col2, bg_color, attribute);
103 if (!driver.norefresh)
108 void CONSOLE_ScrollUpWindow(char row1, char col1, char row2, char col2,
109 char lines, int bg_color, int attribute)
111 if (!console_initialized)
112 console_initialized = CONSOLE_Init(driver.driver_list);
114 if (driver.scrollUpWindow)
116 driver.scrollUpWindow(row1, col1, row2, col2, lines, bg_color,
118 if (!driver.norefresh)
123 void CONSOLE_ScrollDownWindow(char row1, char col1, char row2, char col2,
124 char lines, int bg_color, int attribute)
126 if (!console_initialized)
127 console_initialized = CONSOLE_Init(driver.driver_list);
129 if (driver.scrollDownWindow)
131 driver.scrollDownWindow(row1, col1, row2, col2, lines, bg_color,
133 if (!driver.norefresh)
138 int CONSOLE_CheckForKeystroke(char *scan, char *ascii)
139 /* These functions need to go through a conversion layer. Scancodes
140 should *not* be determined by the driver, rather they should have
141 a conv_* function in int16.c. Yuck. */
143 if (!console_initialized)
144 console_initialized = CONSOLE_Init(driver.driver_list);
146 if (driver.checkForKeystroke)
147 return driver.checkForKeystroke(scan, ascii);
152 void CONSOLE_GetKeystroke(char *scan, char *ascii)
154 if (!console_initialized)
155 console_initialized = CONSOLE_Init(driver.driver_list);
157 if (driver.getKeystroke)
158 driver.getKeystroke(scan, ascii);
161 void CONSOLE_GetCursorPosition(char *row, char *col)
163 if (!console_initialized)
164 console_initialized = CONSOLE_Init(driver.driver_list);
166 if (driver.getCursorPosition)
167 driver.getCursorPosition(row, col);
170 void CONSOLE_GetCharacterAtCursor(char *ch, int *fg, int *bg, int *a)
172 if (!console_initialized)
173 console_initialized = CONSOLE_Init(driver.driver_list);
175 if (driver.getCharacterAtCursor)
176 driver.getCharacterAtCursor(ch, fg, bg, a);
179 void CONSOLE_Refresh()
181 if (!console_initialized)
182 console_initialized = CONSOLE_Init(driver.driver_list);
188 int CONSOLE_AllocColor(int color)
190 if (!console_initialized)
191 console_initialized = CONSOLE_Init(driver.driver_list);
193 if (driver.allocColor)
194 return driver.allocColor(color);
199 void CONSOLE_ClearScreen()
201 if (!console_initialized)
202 console_initialized = CONSOLE_Init(driver.driver_list);
204 if (driver.clearScreen)
206 driver.clearScreen();
207 if (!driver.norefresh)
212 char CONSOLE_GetCharacter()
214 if (!console_initialized)
215 console_initialized = CONSOLE_Init(driver.driver_list);
217 /* I'm not sure if we need this really. This is a function that can be
218 accelerated that returns the next *non extended* keystroke */
219 if (driver.getCharacter)
220 return driver.getCharacter();
222 return (char) 0; /* Sure, this will probably break programs... */
225 void CONSOLE_ResizeScreen(int x, int y)
227 if (!console_initialized)
228 console_initialized = CONSOLE_Init(driver.driver_list);
230 if (driver.resizeScreen)
231 driver.resizeScreen(x, y);
234 void CONSOLE_NotifyResizeScreen(int x, int y)
236 if (driver.notifyResizeScreen)
237 driver.notifyResizeScreen(x, y);
240 void CONSOLE_SetBackgroundColor(int fg, int bg)
242 if (!console_initialized)
243 console_initialized = CONSOLE_Init(driver.driver_list);
245 if (driver.setBackgroundColor)
246 driver.setBackgroundColor(fg, bg);
249 void CONSOLE_WriteRawString(char *str)
251 if (!console_initialized)
252 console_initialized = CONSOLE_Init(driver.driver_list);
254 /* This is a special function that is only for internal use and
255 does not actually call any of the console drivers. It's
256 primary purpose is to provide a way for higher-level drivers
257 to write directly to the underlying terminal without worry that
258 there will be any retranslation done by the assorted drivers. Care
259 should be taken to ensure that this only gets called when the thing
260 written does not actually produce any output or a CONSOLE_Redraw()
261 is called immediately afterwards.
262 CONSOLE_Redraw() is not yet implemented.
264 fprintf(driver.console_out, "%s", str);
267 /* This function is only at the CONSOLE level. */
268 /* Admittably, calling the variable norefresh might be a bit dumb...*/
269 void CONSOLE_SetRefresh(int setting)
272 driver.norefresh = FALSE;
274 driver.norefresh = TRUE;
277 /* This function is only at the CONSOLE level. */
278 int CONSOLE_GetRefresh()
280 if (driver.norefresh)
287 /* Utility functions... */
289 int pop_driver(char **drivers, char **single, int *length)
291 /* Take the string in drivers and extract the first "driver" entry */
292 /* Advance the pointer in drivers to the next entry, put the origional
293 pointer in single, and put the length in length. */
294 /* Return TRUE if we found one */
302 while ((*drivers[0] != NULL) && (*drivers[0] != '+'))
308 while (*drivers[0] == '+')