# HG changeset patch # User Teemu Piippo # Date 1437606921 -10800 # Node ID 777b2a10b8356d99c1347b783077774d221be7c9 # Parent 08ccaf26cffdbec6ae7b1bba5a604d97ca273e78 Add support for standard pdcurses, thanks to Leonard for pointing out the solutions to a few mysteries. diff -r 08ccaf26cffd -r 777b2a10b835 CMakeLists.txt --- a/CMakeLists.txt Thu Jul 23 01:52:04 2015 +0300 +++ b/CMakeLists.txt Thu Jul 23 02:15:21 2015 +0300 @@ -57,16 +57,27 @@ add_definitions ("-D_CRT_SEURE_NO_WARNINGS") target_link_libraries (${TARGET_NAME} wsock32 ws2_32) - if (PDCURSES_WIN32A_PATH) - include_directories (${PDCURSES_WIN32A_PATH}/include) + if (PDCURSES_PATH OR PDCURSES_WIN32A_PATH) + if (NOT PDCURSES_PATH) + set (PDCURSES_PATH "${PDCURSES_WIN32A_PATH}") + add_definitions (-DHAVE_PDCURSES_WIN32A) + endif() + + include_directories (${PDCURSES_PATH}/include) if (MINGW) - target_link_libraries (${TARGET_NAME} ${PDCURSES_WIN32A_PATH}/lib/pdcurses.a) + target_link_libraries (${TARGET_NAME} ${PDCURSES_PATH}/lib/pdcurses.a) else() - target_link_libraries (${TARGET_NAME} ${PDCURSES_WIN32A_PATH}/lib/pdcurses.lib) + target_link_libraries (${TARGET_NAME} ${PDCURSES_PATH}/lib/pdcurses.lib) endif() else() - message (SEND_ERROR "Must give PDCURSES_WIN32A_PATH on Windows") + message (SEND_ERROR "Must provide PDCURSES_PATH or PDCURSES_WIN32A_PATH on Windows") + + if (MINGW) + message (SEND_ERROR "This path must contain pdcurses.a in lib/, and curses.h in include/.") + else() + message (SEND_ERROR "This path must contain pdcurses.lib in lib/, and curses.h in include/.") + endif() endif() else() include_directories (${CURSES_INCUDE_DIRS}) # sic diff -r 08ccaf26cffd -r 777b2a10b835 sources/basics.h --- a/sources/basics.h Thu Jul 23 01:52:04 2015 +0300 +++ b/sources/basics.h Thu Jul 23 02:15:21 2015 +0300 @@ -36,30 +36,11 @@ #define MACRO_TO_STRING_2(A) #A #define MACRO_TO_STRING(A) MACRO_TO_STRING_2(A) +// The Windows SDK appears to use identifiers that conflicts with the identifiers defined in ZFC, +// so they have to be put in a namespace. #define BEGIN_ZFC_NAMESPACE namespace zfc { #define END_ZFC_NAMESPACE } -BEGIN_ZFC_NAMESPACE - -class String; - -// ------------------------------------------------------------------------------------------------- -// -enum Color -{ - BLACK, - RED, - GREEN, - YELLOW, - BLUE, - MAGENTA, - CYAN, - WHITE, - DEFAULT, - - NUM_COLORS -}; - // Goddamnit, MSVC #ifdef _MSC_VER # define and && @@ -85,6 +66,8 @@ #define TEXTCOLOR_BrightCyan TEXTCOLOR_Escape "V" #define TEXTCOLOR_Reset TEXTCOLOR_Escape "-" +BEGIN_ZFC_NAMESPACE + template T min (T a, T b) { @@ -104,4 +87,5 @@ } struct Exitception {}; + END_ZFC_NAMESPACE diff -r 08ccaf26cffd -r 777b2a10b835 sources/coloredline.h --- a/sources/coloredline.h Thu Jul 23 01:52:04 2015 +0300 +++ b/sources/coloredline.h Thu Jul 23 02:15:21 2015 +0300 @@ -32,6 +32,23 @@ #include "main.h" BEGIN_ZFC_NAMESPACE +// The order of these colors appears to differ between curses distributions (PDCurses and its +// win32a for instance have blue and red swapped). So we need to explicitly define the values +// of the enumerators based on their curses values. +enum Color +{ + BLACK = COLOR_BLACK, + RED = COLOR_RED, + GREEN = COLOR_GREEN, + YELLOW = COLOR_YELLOW, + BLUE = COLOR_BLUE, + MAGENTA = COLOR_MAGENTA, + CYAN = COLOR_CYAN, + WHITE = COLOR_WHITE, + DEFAULT = 8, + NUM_COLORS +}; + // ------------------------------------------------------------------------------------------------- // enum diff -r 08ccaf26cffd -r 777b2a10b835 sources/cursesstuff.h diff -r 08ccaf26cffd -r 777b2a10b835 sources/interface.cpp --- a/sources/interface.cpp Thu Jul 23 01:52:04 2015 +0300 +++ b/sources/interface.cpp Thu Jul 23 02:15:21 2015 +0300 @@ -41,7 +41,7 @@ // ------------------------------------------------------------------------------------------------- // -int Interface::color_pair (Color fg, Color bg) +chtype Interface::color_pair (Color fg, Color bg) { return COLOR_PAIR (1 + (int (fg) * NUM_COLORS) + int (bg)); } @@ -209,7 +209,7 @@ { if (Title.length() <= COLS) { - int pair = color_pair (WHITE, BLUE); + chtype pair = color_pair (WHITE, BLUE); int startx = (COLS - Title.length()) / 2; int endx = startx + Title.length(); attron (pair); @@ -436,7 +436,7 @@ // void Interface::render_input() { - int promptColor = color_pair (WHITE, BLUE); + chtype promptColor = color_pair (WHITE, BLUE); // If we're asking the user if they want to disconnect, we don't render any input strings, // just the confirmation message. @@ -497,7 +497,7 @@ // void Interface::render_statusbar() { - int color = color_pair (WHITE, BLUE); + chtype color = color_pair (WHITE, BLUE); int y = LINES - 1; attron (color); mvhline (y, 0, ' ', COLS); @@ -814,6 +814,7 @@ break; case '\n': + case '\r': case KEY_ENTER: switch (CurrentInputState) { diff -r 08ccaf26cffd -r 777b2a10b835 sources/interface.h --- a/sources/interface.h Thu Jul 23 01:52:04 2015 +0300 +++ b/sources/interface.h Thu Jul 23 02:15:21 2015 +0300 @@ -33,6 +33,8 @@ #include "network/ipaddress.h" #include "coloredline.h" #include "network/rconsession.h" +#include "coloredline.h" + BEGIN_ZFC_NAMESPACE class Interface @@ -94,7 +96,7 @@ void render_input(); void render_statusbar(); void position_cursor(); - int color_pair (Color fg, Color bg); + chtype color_pair (Color fg, Color bg); const String& current_input(); void detach_input(); String& mutable_current_input(); diff -r 08ccaf26cffd -r 777b2a10b835 sources/main.cpp --- a/sources/main.cpp Thu Jul 23 01:52:04 2015 +0300 +++ b/sources/main.cpp Thu Jul 23 02:15:21 2015 +0300 @@ -46,7 +46,10 @@ int main (int argc, char* argv[]) { #ifdef _WIN32 +# ifdef HAVE_PDCURSES_WIN32A + // PDCurses-win32a uses a GUI window of its own so we need to destroy the console window. FreeConsole(); +# endif WSADATA wsaData; int result = WSAStartup (MAKEWORD (2, 2), &wsaData); diff -r 08ccaf26cffd -r 777b2a10b835 sources/main.h --- a/sources/main.h Thu Jul 23 01:52:04 2015 +0300 +++ b/sources/main.h Thu Jul 23 02:15:21 2015 +0300 @@ -36,6 +36,7 @@ #include #include #include +#include #include "basics.h" #include "mystring.h" #include "geometry.h"