diff --git a/configure.in b/configure.in index 2db06035..b1df913d 100644 --- a/configure.in +++ b/configure.in @@ -13,6 +13,7 @@ AC_ARG_ENABLE(clock, AS_HELP_STRING([--enable-clock], [Enable clock screen]), [c AC_ARG_ENABLE(unicode, AS_HELP_STRING([--enable-unicode], [Enable utf8 support]), [unicode=$enableval], [unicode=yes]) AC_ARG_WITH(taglib, AS_HELP_STRING([--with-taglib], [Enable tag editor]), [taglib=$withval], [taglib=no]) AC_ARG_WITH(curl, AS_HELP_STRING([--with-curl], [Enable fetching lyrics from the Internet]), [curl=$withval], [curl=no]) +AC_ARG_WITH(pdcurses, AS_HELP_STRING([--with-pdcurses], [Link against pdcurses instead of ncurses]), [pdcurses=$withval], [pdcurses=no]) if test "$clock" = "yes"; then AC_DEFINE([ENABLE_CLOCK], [1], [enables clock screen]) @@ -32,23 +33,29 @@ AC_CHECK_HEADERS([iconv.h], , AC_MSG_NOTICE(cannot find iconv.h header, iconv su dnl ======================== dnl = checking for ncurses = dnl ======================== -if test "$unicode" = "yes" ; then - ncurses_config_bin=ncursesw5-config - ncurses_lib=ncursesw - CPPFLAGS="$CPPFLAGS -D_UTF8" +if test "$pdcurses" = "no" ; then + if test "$unicode" = "yes" ; then + curses_config_bin=ncursesw5-config + curses_lib=ncursesw + AC_DEFINE([_UTF8], [1], [enables unicode support]) + else + curses_config_bin=ncurses5-config + curses_lib=ncurses + fi else - ncurses_config_bin=ncurses5-config - ncurses_lib=ncurses + curses_config_bin=xcurses-config + curses_lib=XCurses + AC_DEFINE([USE_PDCURSES], [1], [enables pdcurses support]) fi -AC_PATH_PROG(NCURSES_CONFIG, $ncurses_config_bin) -if test "$NCURSES_CONFIG" != "" ; then - CPPFLAGS="$CPPFLAGS `$NCURSES_CONFIG --cflags`" - LDFLAGS="$LDFLAGS `$NCURSES_CONFIG --libs`" - AC_CHECK_LIB($ncurses_lib, initscr, , AC_MSG_ERROR([$ncurses_lib library is required])) +AC_PATH_PROG(CURSES_CONFIG, $curses_config_bin) +if test "$CURSES_CONFIG" != "" ; then + CPPFLAGS="$CPPFLAGS `$CURSES_CONFIG --cflags`" + LDFLAGS="$LDFLAGS `$CURSES_CONFIG --libs`" + AC_CHECK_LIB($curses_lib, initscr, , AC_MSG_ERROR([$curses_lib library is required])) else - AC_CHECK_LIB($ncurses_lib, initscr, LDFLAGS="$LDFLAGS -l$ncurses_lib", AC_MSG_ERROR([$ncurses_lib library is required])) + AC_CHECK_LIB($curses_lib, initscr, LDFLAGS="$LDFLAGS -l$curses_lib", AC_MSG_ERROR([$ncurses_lib library is required])) fi -AC_CHECK_HEADERS([ncurses.h], , AC_MSG_ERROR([missing ncurses.h header])) +AC_CHECK_HEADERS([curses.h], , AC_MSG_ERROR([missing ncurses.h header])) dnl ================================= dnl = checking for curl and pthread = diff --git a/src/ncmpcpp.cpp b/src/ncmpcpp.cpp index 2f93c8db..8e1b9259 100644 --- a/src/ncmpcpp.cpp +++ b/src/ncmpcpp.cpp @@ -117,7 +117,7 @@ int main(int argc, char *argv[]) std::streambuf *cerr_buffer = std::cerr.rdbuf(); std::cerr.rdbuf(errorlog.rdbuf()); - InitScreen(Config.colors_enabled); + InitScreen("ncmpc++ ver. "VERSION, Config.colors_enabled); init_current_locale(); MainStartY = 2; @@ -325,6 +325,10 @@ int main(int argc, char *argv[]) } else if (input == KEY_RESIZE) { +# ifdef USE_PDCURSES + resize_term(0, 0); +# endif // USE_PDCURSES + RedrawHeader = 1; if (COLS < 20 || LINES < 5) diff --git a/src/status.cpp b/src/status.cpp index 62cde76f..58c41710 100644 --- a/src/status.cpp +++ b/src/status.cpp @@ -51,10 +51,14 @@ namespace void WindowTitle(const string &status) { +# ifndef USE_PDCURSES static const string term_type = getenv("TERM") ? getenv("TERM") : ""; if (term_type != "linux" && Config.set_window_title) std::cout << "\033]0;" << status << "\7"; +# else + (void)status; +# endif // USE_PDCURSES } } diff --git a/src/window.cpp b/src/window.cpp index 9b691493..a3278fb6 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -28,18 +28,33 @@ using namespace NCurses; using std::string; using std::wstring; -void NCurses::InitScreen(bool enable_colors) +void NCurses::InitScreen(const char *window_title, bool enable_colors) { + const int ColorsTable[] = + { + COLOR_BLACK, COLOR_RED, COLOR_GREEN, COLOR_YELLOW, + COLOR_BLUE, COLOR_MAGENTA, COLOR_CYAN, COLOR_WHITE + }; setlocale(LC_ALL, ""); +# if defined(USE_PDCURSES) && defined(XCURSES) + Xinitscr(1, const_cast(&window_title)); +# else + window_title = 0; // silence compiler initscr(); +# endif // USE_PDCURSES && XCURSES if (has_colors() && enable_colors) { start_color(); use_default_colors(); int num = 1; - for (int i = -1; i < 8; i++) +# ifdef USE_PDCURSES + int i = 0; +# else + int i = -1; +# endif // USE_PDCURSES + for (; i < 8; i++) for (int j = 0; j < 8; j++) - init_pair(num++, j, i); + init_pair(num++, ColorsTable[j], i < 0 ? i : ColorsTable[i]); } noecho(); cbreak(); @@ -424,7 +439,12 @@ string Window::GetString(const string &base, size_t length, size_t width, bool e input = wgetch(itsWindow); // these key codes are special and should be ignored - if (input < 10 || (input > 10 && input < 32)) + if ((input < 10 || (input > 10 && input < 32)) +# ifdef USE_PDCURSES + && input != 8) // backspace key in pdcurses +# else + ) +# endif // USE_PDCURSES continue; switch (input) @@ -445,6 +465,9 @@ string Window::GetString(const string &base, size_t length, size_t width, bool e break; } case KEY_BACKSPACE: case 127: +# ifdef USE_PDCURSES + case 8: // backspace key in pdcurses +# endif // USE_PDCURSES { if (x <= minx && !beginning) break; @@ -458,7 +481,11 @@ string Window::GetString(const string &base, size_t length, size_t width, bool e } else if (beginning > 0) beginning--; - if (input != KEY_BACKSPACE && input != 127) + if (input != KEY_BACKSPACE && input != 127 +# ifdef USE_PDCURSES + && input != 8 // backspace key in pdcurses +# endif // USE_PDCURSES + ) break; // backspace = left & delete. } case KEY_DC: diff --git a/src/window.h b/src/window.h index 990dbdc0..1cf0c9d2 100644 --- a/src/window.h +++ b/src/window.h @@ -25,7 +25,11 @@ #include #endif -#include "ncurses.h" +#ifdef USE_PDCURSES +# define XCURSES +#endif + +#include "curses.h" #include #include @@ -55,7 +59,7 @@ namespace NCurses typedef void (*GetStringHelper)(const std::wstring &); - void InitScreen(bool); + void InitScreen(const char *, bool); void DestroyScreen(); struct Colors