Joseph Pranevich | 791cd6a | 1998-12-02 19:58:08 +0000 | [diff] [blame] | 1 | /* 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 Pranevich | 5576838 | 1998-12-09 15:43:03 +0000 | [diff] [blame] | 26 | SCREEN *ncurses_screen; |
| 27 | |
Joseph Pranevich | 791cd6a | 1998-12-02 19:58:08 +0000 | [diff] [blame] | 28 | void 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 | |
| 49 | void NCURSES_Init() |
| 50 | { |
Joseph Pranevich | 5576838 | 1998-12-09 15:43:03 +0000 | [diff] [blame] | 51 | ncurses_screen = newterm("xterm", driver.console_out, |
| 52 | driver.console_in); |
| 53 | set_term(ncurses_screen); |
Joseph Pranevich | 791cd6a | 1998-12-02 19:58:08 +0000 | [diff] [blame] | 54 | cbreak(); |
| 55 | noecho(); |
| 56 | nonl(); |
| 57 | intrflush(stdscr, FALSE); |
| 58 | keypad(stdscr, TRUE); |
| 59 | nodelay(stdscr, TRUE); |
| 60 | } |
| 61 | |
| 62 | void NCURSES_Write(char output, int fg, int bg, int attribute) |
| 63 | { |
| 64 | /* We can discard all extended information. */ |
Joseph Pranevich | 5576838 | 1998-12-09 15:43:03 +0000 | [diff] [blame] | 65 | waddch(stdscr, output); |
Joseph Pranevich | 791cd6a | 1998-12-02 19:58:08 +0000 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | void NCURSES_Close() |
| 69 | { |
| 70 | endwin(); |
| 71 | } |
| 72 | |
| 73 | void 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 Pranevich | 5576838 | 1998-12-09 15:43:03 +0000 | [diff] [blame] | 81 | wgetch(stdscr); |
Joseph Pranevich | 791cd6a | 1998-12-02 19:58:08 +0000 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | int NCURSES_CheckForKeystroke(char *scan, char *ascii) |
| 85 | { |
| 86 | /* We don't currently support scan codes here */ |
| 87 | /* FIXME */ |
| 88 | int temp; |
Joseph Pranevich | 5576838 | 1998-12-09 15:43:03 +0000 | [diff] [blame] | 89 | temp = wgetch(stdscr); |
Joseph Pranevich | 791cd6a | 1998-12-02 19:58:08 +0000 | [diff] [blame] | 90 | 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 | |
| 102 | void NCURSES_MoveCursor(char row, char col) |
| 103 | { |
Joseph Pranevich | 5576838 | 1998-12-09 15:43:03 +0000 | [diff] [blame] | 104 | wmove(stdscr, row, col); |
Joseph Pranevich | 791cd6a | 1998-12-02 19:58:08 +0000 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | void 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 | |
| 117 | void 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 Pranevich | 5576838 | 1998-12-09 15:43:03 +0000 | [diff] [blame] | 121 | *ch = (char) winch(stdscr); |
Joseph Pranevich | 791cd6a | 1998-12-02 19:58:08 +0000 | [diff] [blame] | 122 | *fg_color = 0; |
| 123 | *bg_color = 0; |
| 124 | *attribute = 0; |
| 125 | }; |
| 126 | |
| 127 | void NCURSES_Refresh() |
| 128 | { |
Joseph Pranevich | 5576838 | 1998-12-09 15:43:03 +0000 | [diff] [blame] | 129 | wrefresh(stdscr); |
Joseph Pranevich | 791cd6a | 1998-12-02 19:58:08 +0000 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | void NCURSES_ClearScreen() |
| 133 | { |
Joseph Pranevich | 5576838 | 1998-12-09 15:43:03 +0000 | [diff] [blame] | 134 | werase(stdscr); |
Joseph Pranevich | 791cd6a | 1998-12-02 19:58:08 +0000 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | #endif /* WINE_NCURSES */ |