Support older ncurses.

This commit is contained in:
Jari Vetoniemi 2014-04-15 20:34:21 +03:00
parent 8e415197d2
commit 953c61f4ad

View File

@ -42,9 +42,16 @@ static const char *TTY = "/dev/tty";
};
#endif
/* these are implemented as macros in older curses */
#ifndef NCURSES_OPAQUE
static int wrap_getmaxx(WINDOW *win) { return getmaxx(win); }
static int wrap_getmaxy(WINDOW *win) { return getmaxy(win); }
#endif
/* ncurses.h likes to define stuff for us.
* This unforunately mangles with our struct. */
#undef erase
#undef getch
#undef get_wch
#undef refresh
#undef mvprintw
@ -68,6 +75,7 @@ static struct curses {
int (*endwin)(void);
int (*refresh)(void);
int (*erase)(void);
int (*getch)(void);
int (*get_wch)(wint_t *wch);
int (*mvprintw)(int x, int y, const char *fmt, ...);
int (*move)(int x, int y);
@ -278,7 +286,11 @@ static bmKey _bmDrawCursesGetKey(unsigned int *unicode)
if (!curses.stdscr)
return BM_KEY_NONE;
curses.get_wch((wint_t*)unicode);
if (curses.get_wch)
curses.get_wch((wint_t*)unicode);
else if (curses.getch)
*unicode = curses.getch();
switch (*unicode) {
#if KEY_RESIZE
case KEY_RESIZE:
@ -419,7 +431,7 @@ int _bmDrawCursesInit(struct _bmRenderApi *api)
goto function_pointer_exception;
if (!bmLoadFunction(refresh))
goto function_pointer_exception;
if (!bmLoadFunction(get_wch))
if (!bmLoadFunction(get_wch) && !bmLoadFunction(getch))
goto function_pointer_exception;
if (!bmLoadFunction(erase))
goto function_pointer_exception;
@ -437,10 +449,6 @@ int _bmDrawCursesInit(struct _bmRenderApi *api)
goto function_pointer_exception;
if (!bmLoadFunction(use_default_colors))
goto function_pointer_exception;
if (!bmLoadFunction(getmaxx))
goto function_pointer_exception;
if (!bmLoadFunction(getmaxy))
goto function_pointer_exception;
if (!bmLoadFunction(keypad))
goto function_pointer_exception;
if (!bmLoadFunction(curs_set))
@ -454,6 +462,16 @@ int _bmDrawCursesInit(struct _bmRenderApi *api)
if (!bmLoadFunction(ESCDELAY))
goto function_pointer_exception;
#ifndef NCURSES_OPAQUE
curses.getmaxx = wrap_getmaxx;
curses.getmaxy = wrap_getmaxy;
#else
if (!bmLoadFunction(getmaxx))
goto function_pointer_exception;
if (!bmLoadFunction(getmaxy))
goto function_pointer_exception;
#endif
#undef bmLoadFunction
api->displayedCount = _bmDrawCursesDisplayedCount;