1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
|
#include <setjmp.h>
#include <signal.h>
#include <stdio.h>
#include "config.h"
#ifdef CURSES_DRIVER
#ifdef USE_NCURSES
#ifdef RENAMED_NCURSES
#include <curses.h>
#else
#include <ncurses.h>
#endif
#else
#include <curses.h>
#endif
#ifdef GPM_MOUSEDRIVER
#include <gpm.h>
#endif
#include "aalib.h"
#include "aaint.h"
__AA_CONST struct aa_driver curses_d;
int __curses_is_up;
int __resized_curses;
static int uninitcurses;
static int curses_init(__AA_CONST struct aa_hardware_params *p, __AA_CONST void *none, struct aa_hardware_params *dest, void **param)
{
int a;
if (!__curses_is_up) {
fflush(stdout);
if ((initscr()) == NULL)
return 0;
__curses_is_up = 1;
uninitcurses = 1;
}
dest->font=NULL;
dest->supported=AA_NORMAL_MASK;
#ifdef HAVE_TERMATTRS
a = termattrs();
if (has_colors()) {
start_color();
init_pair(1, COLOR_BLACK, COLOR_BLACK);
dest->supported |= AA_DIM_MASK;
} else {
if (a & A_DIM)
dest->supported |= AA_DIM_MASK;
}
if (a & A_BOLD)
dest->supported |= AA_BOLD_MASK;
if (a & A_BOLD)
dest->supported |= AA_BOLDFONT_MASK;
if (a & A_REVERSE)
dest->supported |= AA_REVERSE_MASK;
#else
dest->supported |= AA_REVERSE_MASK | AA_DIM_MASK | AA_BOLD_MASK | AA_BOLDFONT_MASK;
#endif
intrflush(stdscr, FALSE);
aa_recommendlowkbd("curses");
return 1;
}
static void curses_uninit(aa_context * c)
{
wclear(stdscr);
intrflush(stdscr, TRUE);
#if 0
nocbreak();
echo();
nl();
#endif
refresh();
if (uninitcurses) {
uninitcurses = 0;
__curses_is_up = 0;
endwin();
}
}
static void curses_getsize(aa_context * c, int *width, int *height)
{
if (__resized_curses)
curses_uninit(c), curses_init(&c->params, NULL,&c->driverparams, NULL), __resized_curses = 0;
*width = stdscr->_maxx + 1;
*height = stdscr->_maxy + 1;
#ifdef GPM_MOUSEDRIVER
gpm_mx = *width;
gpm_my = *height;
#endif
}
static void curses_setattr(aa_context * c, int attr)
{
switch (attr) {
case AA_NORMAL:
attrset(A_NORMAL);
break;
case AA_DIM:
if (has_colors()) {
attrset(A_BOLD);
attron(COLOR_PAIR(1));
} else {
attrset(A_DIM);
}
break;
case AA_BOLD:
attrset(A_BOLD);
break;
case AA_BOLDFONT:
attrset(A_BOLD);
break;
case AA_REVERSE:
attrset(A_REVERSE);
break;
case AA_SPECIAL:
attrset(A_REVERSE);
break;
}
}
static void curses_print(aa_context * c, __AA_CONST char *text)
{
addstr(text);
}
static void curses_flush(aa_context * c)
{
refresh();
}
static void curses_gotoxy(aa_context * c, int x, int y)
{
move(y, x);
}
static void curses_cursor(aa_context * c, int mode)
{
#ifdef HAVE_CURS_SET
curs_set(mode);
#endif
}
__AA_CONST struct aa_driver curses_d =
{
"curses", "Curses driver 1.0",
curses_init,
curses_uninit,
curses_getsize,
curses_setattr,
curses_print,
curses_gotoxy,
/*curses_getchar,
NULL, */
curses_flush,
curses_cursor,
};
#endif
|