blob: 6429221019c4751d26da23d3ab42a38aa6759487 [file] [log] [blame]
Joseph Pranevich791cd6a1998-12-02 19:58:08 +00001/* ncurses.c */
2
3#include "config.h"
4
5#ifdef WINE_NCURSES
6
7/* This is the console driver for systems that support the ncurses
8 interface.
9*/
10
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.
14*/
15
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.
19*/
20
21#include "console.h"
22#include "debug.h"
23#undef ERR /* Use ncurses's err() */
24#include <curses.h>
25
Joseph Pranevich55768381998-12-09 15:43:03 +000026SCREEN *ncurses_screen;
27
Joseph Pranevich791cd6a1998-12-02 19:58:08 +000028void NCURSES_Start()
29{
30 /* This should be the root driver so we can ignore anything
31 already in the struct. */
32
33 driver.norefresh = FALSE;
34
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;
42
43 driver.checkForKeystroke = NCURSES_CheckForKeystroke;
44 driver.getKeystroke = NCURSES_GetKeystroke;
45
46 driver.refresh = NCURSES_Refresh;
47}
48
49void NCURSES_Init()
50{
Joseph Pranevich55768381998-12-09 15:43:03 +000051 ncurses_screen = newterm("xterm", driver.console_out,
52 driver.console_in);
53 set_term(ncurses_screen);
Joseph Pranevich791cd6a1998-12-02 19:58:08 +000054 cbreak();
55 noecho();
56 nonl();
57 intrflush(stdscr, FALSE);
58 keypad(stdscr, TRUE);
59 nodelay(stdscr, TRUE);
60}
61
62void NCURSES_Write(char output, int fg, int bg, int attribute)
63{
64 /* We can discard all extended information. */
Joseph Pranevich55768381998-12-09 15:43:03 +000065 waddch(stdscr, output);
Joseph Pranevich791cd6a1998-12-02 19:58:08 +000066}
67
68void NCURSES_Close()
69{
70 endwin();
71}
72
73void NCURSES_GetKeystroke(char *scan, char *ascii)
74{
75 while (!NCURSES_CheckForKeystroke(scan, ascii))
76 {} /* Wait until keystroke is detected */
77
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. */
Joseph Pranevich55768381998-12-09 15:43:03 +000081 wgetch(stdscr);
Joseph Pranevich791cd6a1998-12-02 19:58:08 +000082}
83
84int NCURSES_CheckForKeystroke(char *scan, char *ascii)
85{
86 /* We don't currently support scan codes here */
87 /* FIXME */
88 int temp;
Joseph Pranevich55768381998-12-09 15:43:03 +000089 temp = wgetch(stdscr);
Joseph Pranevich791cd6a1998-12-02 19:58:08 +000090 if (temp == ERR)
91 {
92 return FALSE;
93 }
94 else
95 {
96 ungetch(temp); /* Keystroke not removed from buffer */
97 *ascii = (char) temp;
98 return TRUE;
99 }
100}
101
102void NCURSES_MoveCursor(char row, char col)
103{
Joseph Pranevich55768381998-12-09 15:43:03 +0000104 wmove(stdscr, row, col);
Joseph Pranevich791cd6a1998-12-02 19:58:08 +0000105}
106
107void NCURSES_GetCursorPosition(char *row, char *col)
108{
109 int trow, tcol;
110
111 getyx(stdscr, trow, tcol); /* MACRO, no need to pass pointer */
112
113 *row = (char) trow;
114 *col = (char) tcol;
115}
116
117void NCURSES_GetCharacterAtCursor(char *ch, int *fg_color, int
118 *bg_color, int *attribute)
119{
120 /* We will eventually have to convert the color data */
Joseph Pranevich55768381998-12-09 15:43:03 +0000121 *ch = (char) winch(stdscr);
Joseph Pranevich791cd6a1998-12-02 19:58:08 +0000122 *fg_color = 0;
123 *bg_color = 0;
124 *attribute = 0;
125};
126
127void NCURSES_Refresh()
128{
Joseph Pranevich55768381998-12-09 15:43:03 +0000129 wrefresh(stdscr);
Joseph Pranevich791cd6a1998-12-02 19:58:08 +0000130}
131
132void NCURSES_ClearScreen()
133{
Joseph Pranevich55768381998-12-09 15:43:03 +0000134 werase(stdscr);
Joseph Pranevich791cd6a1998-12-02 19:58:08 +0000135}
136
137#endif /* WINE_NCURSES */