1998-12-02 20:58:08 +01:00
|
|
|
/* ncurses.c */
|
1999-02-14 12:15:47 +01:00
|
|
|
/* Copyright 1999 - Joseph Pranevich */
|
1998-12-02 20:58:08 +01:00
|
|
|
|
1999-02-17 14:51:06 +01:00
|
|
|
#include <stdio.h>
|
1998-12-02 20:58:08 +01:00
|
|
|
#include "config.h"
|
1999-02-20 17:43:40 +01:00
|
|
|
#include "console.h" /* Must define WINE_NCURSES */
|
1998-12-02 20:58:08 +01:00
|
|
|
|
|
|
|
#ifdef WINE_NCURSES
|
|
|
|
|
|
|
|
/* This is the console driver for systems that support the ncurses
|
|
|
|
interface.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Actually, this should work for curses, as well. But there may be
|
|
|
|
individual functions that are unsupported in plain curses or other
|
|
|
|
variants. Those should be detected and special-cased by autoconf.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* When creating new drivers, you need to assign all the functions that
|
|
|
|
that driver supports into the driver struct. If it is a supplementary
|
|
|
|
driver, it should make sure to perserve the old values.
|
|
|
|
*/
|
|
|
|
|
1999-05-14 10:17:14 +02:00
|
|
|
#include "debugtools.h"
|
1999-02-20 17:43:40 +01:00
|
|
|
#include "options.h"
|
|
|
|
|
1999-04-19 16:56:29 +02:00
|
|
|
DEFAULT_DEBUG_CHANNEL(console)
|
|
|
|
|
1998-12-02 20:58:08 +01:00
|
|
|
#undef ERR /* Use ncurses's err() */
|
1999-01-28 10:09:03 +01:00
|
|
|
#ifdef HAVE_NCURSES_H
|
|
|
|
# include <ncurses.h>
|
1999-01-20 15:18:55 +01:00
|
|
|
#else
|
1999-01-28 10:09:03 +01:00
|
|
|
# ifdef HAVE_CURSES_H
|
|
|
|
# include <curses.h>
|
1999-01-20 15:18:55 +01:00
|
|
|
# endif
|
|
|
|
#endif
|
1998-12-02 20:58:08 +01:00
|
|
|
|
1998-12-09 16:43:03 +01:00
|
|
|
SCREEN *ncurses_screen;
|
|
|
|
|
1999-01-30 13:51:09 +01:00
|
|
|
static int get_color_pair(int fg_color, int bg_color);
|
|
|
|
|
1999-02-20 17:43:40 +01:00
|
|
|
const char *color_names[] = {"null", "black", "blue", "green",
|
|
|
|
"cyan", "magenta", "brown", "red", "light gray", "dark gray",
|
|
|
|
"light blue", "light green", "light red", "light magenta",
|
|
|
|
"light cyan", "yellow", "white"};
|
|
|
|
|
1998-12-02 20:58:08 +01:00
|
|
|
void NCURSES_Start()
|
|
|
|
{
|
|
|
|
/* This should be the root driver so we can ignore anything
|
|
|
|
already in the struct. */
|
|
|
|
|
|
|
|
driver.norefresh = FALSE;
|
|
|
|
|
|
|
|
driver.init = NCURSES_Init;
|
|
|
|
driver.write = NCURSES_Write;
|
|
|
|
driver.close = NCURSES_Close;
|
|
|
|
driver.moveCursor = NCURSES_MoveCursor;
|
|
|
|
driver.getCursorPosition = NCURSES_GetCursorPosition;
|
|
|
|
driver.getCharacterAtCursor = NCURSES_GetCharacterAtCursor;
|
|
|
|
driver.clearScreen = NCURSES_ClearScreen;
|
1999-01-30 13:51:09 +01:00
|
|
|
driver.allocColor = NCURSES_AllocColor;
|
1999-02-25 18:11:05 +01:00
|
|
|
#ifdef HAVE_GETBKGD
|
1999-01-30 13:51:09 +01:00
|
|
|
driver.setBackgroundColor = NCURSES_SetBackgroundColor;
|
1999-02-25 18:11:05 +01:00
|
|
|
#endif
|
1999-01-17 17:32:32 +01:00
|
|
|
#ifdef HAVE_RESIZETERM
|
1999-01-03 17:14:34 +01:00
|
|
|
driver.notifyResizeScreen = NCURSES_NotifyResizeScreen;
|
1999-02-20 17:43:40 +01:00
|
|
|
#endif /* HAVE_RESIZETERM */
|
1998-12-02 20:58:08 +01:00
|
|
|
|
|
|
|
driver.checkForKeystroke = NCURSES_CheckForKeystroke;
|
|
|
|
driver.getKeystroke = NCURSES_GetKeystroke;
|
|
|
|
|
|
|
|
driver.refresh = NCURSES_Refresh;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NCURSES_Init()
|
|
|
|
{
|
1999-02-20 17:43:40 +01:00
|
|
|
char terminal_type[80];
|
|
|
|
|
|
|
|
PROFILE_GetWineIniString("console", "TerminalType",
|
|
|
|
"xterm", terminal_type, 79);
|
|
|
|
|
|
|
|
ncurses_screen = newterm(terminal_type, driver.console_out,
|
1998-12-09 16:43:03 +01:00
|
|
|
driver.console_in);
|
|
|
|
set_term(ncurses_screen);
|
1999-01-30 13:51:09 +01:00
|
|
|
start_color();
|
|
|
|
raw();
|
1998-12-02 20:58:08 +01:00
|
|
|
noecho();
|
|
|
|
nonl();
|
1999-02-20 17:43:40 +01:00
|
|
|
intrflush(stdscr, FALSE);
|
1998-12-02 20:58:08 +01:00
|
|
|
keypad(stdscr, TRUE);
|
|
|
|
nodelay(stdscr, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NCURSES_Write(char output, int fg, int bg, int attribute)
|
|
|
|
{
|
1999-01-17 17:32:32 +01:00
|
|
|
char row, col;
|
1999-01-30 13:51:09 +01:00
|
|
|
int pair;
|
|
|
|
|
|
|
|
if (!fg)
|
|
|
|
fg = COLOR_WHITE; /* Default */
|
|
|
|
|
|
|
|
if (!bg)
|
|
|
|
bg = COLOR_BLACK; /* Default */
|
|
|
|
|
|
|
|
pair = get_color_pair(fg, bg);
|
1999-01-17 17:32:32 +01:00
|
|
|
|
1999-01-30 13:51:09 +01:00
|
|
|
if (waddch(stdscr, output | COLOR_PAIR(pair)) == ERR)
|
1999-01-17 17:32:32 +01:00
|
|
|
{
|
|
|
|
NCURSES_GetCursorPosition(&row, &col);
|
1999-05-14 10:17:14 +02:00
|
|
|
FIXME("NCURSES: waddch() failed at %d, %d.\n", row, col);
|
1999-01-17 17:32:32 +01:00
|
|
|
}
|
1998-12-02 20:58:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void NCURSES_Close()
|
|
|
|
{
|
|
|
|
endwin();
|
|
|
|
}
|
|
|
|
|
|
|
|
void NCURSES_GetKeystroke(char *scan, char *ascii)
|
|
|
|
{
|
|
|
|
while (!NCURSES_CheckForKeystroke(scan, ascii))
|
|
|
|
{} /* Wait until keystroke is detected */
|
|
|
|
|
|
|
|
/* When it is detected, we will already have the right value
|
|
|
|
in scan and ascii, but we need to take this keystroke
|
|
|
|
out of the buffer. */
|
1998-12-09 16:43:03 +01:00
|
|
|
wgetch(stdscr);
|
1998-12-02 20:58:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int NCURSES_CheckForKeystroke(char *scan, char *ascii)
|
|
|
|
{
|
|
|
|
/* We don't currently support scan codes here */
|
|
|
|
/* FIXME */
|
|
|
|
int temp;
|
1998-12-09 16:43:03 +01:00
|
|
|
temp = wgetch(stdscr);
|
1998-12-02 20:58:08 +01:00
|
|
|
if (temp == ERR)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ungetch(temp); /* Keystroke not removed from buffer */
|
|
|
|
*ascii = (char) temp;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void NCURSES_MoveCursor(char row, char col)
|
|
|
|
{
|
1999-01-03 17:14:34 +01:00
|
|
|
if (wmove(stdscr, row, col) == ERR)
|
1999-05-14 10:17:14 +02:00
|
|
|
FIXME("NCURSES: wmove() failed to %d, %d.\n", row, col);
|
1998-12-02 20:58:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void NCURSES_GetCursorPosition(char *row, char *col)
|
|
|
|
{
|
|
|
|
int trow, tcol;
|
|
|
|
|
|
|
|
getyx(stdscr, trow, tcol); /* MACRO, no need to pass pointer */
|
|
|
|
|
|
|
|
*row = (char) trow;
|
|
|
|
*col = (char) tcol;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NCURSES_GetCharacterAtCursor(char *ch, int *fg_color, int
|
|
|
|
*bg_color, int *attribute)
|
|
|
|
{
|
1999-02-14 12:15:47 +01:00
|
|
|
/* If any of the pointers are NULL, ignore them */
|
1998-12-02 20:58:08 +01:00
|
|
|
/* We will eventually have to convert the color data */
|
1999-02-14 12:15:47 +01:00
|
|
|
if (ch)
|
|
|
|
*ch = (char) winch(stdscr);
|
|
|
|
if (fg_color)
|
|
|
|
*fg_color = WINE_WHITE;
|
|
|
|
if (bg_color)
|
|
|
|
*bg_color = WINE_BLACK;
|
|
|
|
if (attribute)
|
|
|
|
*attribute = 0;
|
1998-12-02 20:58:08 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
void NCURSES_Refresh()
|
|
|
|
{
|
1998-12-09 16:43:03 +01:00
|
|
|
wrefresh(stdscr);
|
1998-12-02 20:58:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void NCURSES_ClearScreen()
|
|
|
|
{
|
1998-12-09 16:43:03 +01:00
|
|
|
werase(stdscr);
|
1998-12-02 20:58:08 +01:00
|
|
|
}
|
|
|
|
|
1999-01-30 13:51:09 +01:00
|
|
|
int NCURSES_AllocColor(int color)
|
|
|
|
{
|
|
|
|
/* Currently support only internal colors */
|
|
|
|
switch (color)
|
|
|
|
{
|
|
|
|
case WINE_BLACK: return COLOR_BLACK;
|
|
|
|
case WINE_WHITE: return COLOR_WHITE;
|
|
|
|
case WINE_RED: return COLOR_RED;
|
|
|
|
case WINE_GREEN: return COLOR_GREEN;
|
|
|
|
case WINE_YELLOW: return COLOR_YELLOW;
|
|
|
|
case WINE_BLUE: return COLOR_BLUE;
|
|
|
|
case WINE_MAGENTA: return COLOR_MAGENTA;
|
|
|
|
case WINE_CYAN: return COLOR_CYAN;
|
|
|
|
}
|
|
|
|
|
1999-05-14 10:17:14 +02:00
|
|
|
FIXME("Unable to allocate color %d (%s)\n", color,
|
1999-02-20 17:43:40 +01:00
|
|
|
color_names[color]);
|
1999-01-30 13:51:09 +01:00
|
|
|
|
|
|
|
/* Don't allocate a color... yet */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NCURSES_SetBackgroundColor(int fg, int bg)
|
|
|
|
{
|
|
|
|
int pair;
|
|
|
|
|
|
|
|
pair = get_color_pair(fg, bg);
|
|
|
|
|
1999-02-24 12:08:29 +01:00
|
|
|
wbkgd(stdscr, COLOR_PAIR(pair));
|
|
|
|
}
|
|
|
|
|
1999-02-25 18:11:05 +01:00
|
|
|
#ifdef HAVE_GETBKGD
|
1999-02-24 12:08:29 +01:00
|
|
|
void NCURSES_GetBackgroundColor(int *fg, int *bg)
|
|
|
|
{
|
|
|
|
chtype background;
|
|
|
|
short pair, sfg, sbg;
|
|
|
|
|
|
|
|
background = getbkgd(stdscr);
|
|
|
|
|
|
|
|
pair = (!A_CHARTEXT & background);
|
|
|
|
|
|
|
|
pair_content(pair, &sfg, &sbg);
|
|
|
|
|
|
|
|
*fg = sfg;
|
|
|
|
*bg = sbg;
|
1999-01-30 13:51:09 +01:00
|
|
|
}
|
1999-02-25 18:11:05 +01:00
|
|
|
#endif /* HAVE_GETBKGD */
|
1999-01-30 13:51:09 +01:00
|
|
|
|
1999-01-17 17:32:32 +01:00
|
|
|
#ifdef HAVE_RESIZETERM
|
|
|
|
|
1999-01-03 17:14:34 +01:00
|
|
|
void NCURSES_NotifyResizeScreen(int x, int y)
|
|
|
|
{
|
|
|
|
/* Note: This function gets called *after* another driver in the chain
|
|
|
|
calls ResizeScreen(). It is meant to resize the ncurses internal
|
|
|
|
data structures to know about the new window dimensions. */
|
|
|
|
|
1999-05-14 10:17:14 +02:00
|
|
|
TRACE("Terminal resized to y: %d, x: %d\n", y, x);
|
1999-02-20 17:43:40 +01:00
|
|
|
|
1999-01-03 17:14:34 +01:00
|
|
|
resizeterm(y, x);
|
|
|
|
}
|
|
|
|
|
1999-01-30 13:51:09 +01:00
|
|
|
#endif /* HAVE_RESIZETERM */
|
|
|
|
|
|
|
|
static int get_color_pair(int fg_color, int bg_color)
|
|
|
|
{
|
|
|
|
/* ncurses internally uses "color pairs" in addition to the "pallet" */
|
|
|
|
/* This isn't the best way to do this. Or even close */
|
|
|
|
|
|
|
|
static int current = 0;
|
|
|
|
static int fg[255]; /* 16 x 16 is enough */
|
|
|
|
static int bg[255];
|
|
|
|
int x;
|
|
|
|
|
|
|
|
/* The first pair is hardwired into ncurses */
|
|
|
|
fg[0] = COLOR_WHITE;
|
|
|
|
bg[0] = COLOR_BLACK;
|
|
|
|
|
|
|
|
for (x = 0; x <= current; x++)
|
|
|
|
{
|
|
|
|
if ((fg_color == fg[x]) && (bg_color == bg[x]))
|
|
|
|
{
|
1999-05-14 10:17:14 +02:00
|
|
|
TRACE("Color pair: already allocated\n");
|
1999-01-30 13:51:09 +01:00
|
|
|
return x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Need to allocate new color */
|
|
|
|
current++;
|
|
|
|
fg[current] = fg_color;
|
|
|
|
bg[current] = bg_color;
|
1999-05-14 10:17:14 +02:00
|
|
|
TRACE("Color pair: allocated.\n");
|
1999-01-30 13:51:09 +01:00
|
|
|
return init_pair(current, fg_color, bg_color);
|
|
|
|
}
|
1999-01-17 17:32:32 +01:00
|
|
|
|
1998-12-02 20:58:08 +01:00
|
|
|
#endif /* WINE_NCURSES */
|