Skip to content

Commit 0cc7809

Browse files
illwieckzslipher
andcommitted
Make possible to use PDCursesMod on every system
- PDCursesMod is forced on Windows as USE_CURSES is always enabled since there is no other console code. - PDCursesMod is used on macOS if USE_CURSES is enabled, it couldn't be enabled before as system ncurses isn't supported. - PDCursesMod is used on Linux if USE_CURSES is enabled, but USE_CURSES_NCURSES is disabled. - ncurses is used on Linux if both USE_CURSES and USE_CURSES_NCURSES are enabled. Co-authored-by: slipher <slipher@protonmail.com>
1 parent 79598bf commit 0cc7809

File tree

3 files changed

+55
-25
lines changed

3 files changed

+55
-25
lines changed

CMakeLists.txt

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,15 @@ if(NOT DAEMON_EXTERNAL_APP)
141141

142142
set(NACL_RUNTIME_PATH "" CACHE STRING "Directory containing the NaCl binaries")
143143

144-
# Not supported on mac because the included version is too old
145-
if(APPLE)
146-
set(USE_CURSES OFF)
147-
elseif(WIN32)
144+
if (WIN32)
145+
# The alternative code is based on non-curses unix terminal functions.
148146
set(USE_CURSES ON)
149147
else()
148+
if (NOT APPLE)
149+
# Not supported on macOS because the included version is too old.
150+
option(USE_CURSES_NCURSES "Use ncurses instead of PDCursesMod" ON)
151+
endif()
152+
150153
option(USE_CURSES "Enable fancy colors in terminal's output" ON)
151154
endif()
152155

@@ -657,20 +660,24 @@ endif()
657660
# Curses, pdcurses on Windows and ncursesw on Unix
658661
if (BUILD_CLIENT OR BUILD_TTY_CLIENT OR BUILD_SERVER OR BUILD_DUMMY_APP)
659662
if (USE_CURSES)
660-
if (WIN32)
661-
set(LIBS_ENGINE_BASE ${LIBS_ENGINE_BASE} gdi32 comdlg32)
663+
if (USE_CURSES_NCURSES)
664+
# Tells FindCurses that ncurses is required.
665+
set(CURSES_NEED_NCURSES 1)
666+
667+
add_definitions(-DUSE_CURSES -DUSE_CURSES_NCURSES)
668+
find_package(CursesW REQUIRED)
669+
set(LIBS_ENGINE_BASE ${LIBS_ENGINE_BASE} ${CURSESW_LIBRARIES})
670+
include_directories(${CURSESW_INCLUDE_DIR})
671+
else ()
672+
if (WIN32)
673+
set(LIBS_ENGINE_BASE ${LIBS_ENGINE_BASE} gdi32 comdlg32)
674+
endif()
662675

663676
add_definitions(-DPDC_WIDE -DPDC_FORCE_UTF8 -DPDC_RGB -DUSE_CURSES)
664677
add_library(srclibs-pdcurses EXCLUDE_FROM_ALL ${PDCURSESLIST})
665678
set_target_properties(srclibs-pdcurses PROPERTIES POSITION_INDEPENDENT_CODE 1 FOLDER "libs")
666679
set(LIBS_ENGINE_BASE ${LIBS_ENGINE_BASE} srclibs-pdcurses)
667680
include_directories(${LIB_DIR}/pdcursesmod)
668-
else ()
669-
add_definitions(-DUSE_CURSES)
670-
set(CURSES_NEED_NCURSES 1) # Tells FindCurses that ncurses is required
671-
find_package(CursesW REQUIRED)
672-
set(LIBS_ENGINE_BASE ${LIBS_ENGINE_BASE} ${CURSESW_LIBRARIES})
673-
include_directories(${CURSESW_INCLUDE_DIR})
674681
endif()
675682
endif()
676683
endif()

src/engine/sys/con_curses.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,12 @@ static void CON_SetColor( WINDOW *win, const Color::Color& color )
103103
static void CON_UpdateCursor()
104104
{
105105
// pdcurses uses a different mechanism to move the cursor than ncurses
106-
#ifdef _WIN32
107-
move( LINES - 1, Color::StrlenNocolor( PROMPT ) + 8 + input_field.GetViewCursorPos() );
108-
wnoutrefresh( stdscr );
109-
#else
106+
#ifdef USE_CURSES_NCURSES
110107
wmove( inputwin, 0, input_field.GetViewCursorPos() );
111108
wnoutrefresh( inputwin );
109+
#else
110+
move( LINES - 1, Color::StrlenNocolor( PROMPT ) + 8 + input_field.GetViewCursorPos() );
111+
wnoutrefresh( stdscr );
112112
#endif
113113
}
114114

@@ -228,7 +228,12 @@ static void CON_Redraw()
228228
{
229229
return;
230230
}
231-
resizeterm( winsz.ws_row, winsz.ws_col );
231+
232+
#if defined(USE_CURSES_NCURSES)
233+
resizeterm( winsz.ws_row, winsz.ws_col );
234+
#else
235+
resize_term( winsz.ws_row, winsz.ws_col );
236+
#endif
232237
#endif
233238

234239
delwin( logwin );

srclibs.cmake

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,16 +99,34 @@ set(PDCURSESLIST
9999
${LIB_DIR}/pdcursesmod/pdcurses/touch.c
100100
${LIB_DIR}/pdcursesmod/pdcurses/util.c
101101
${LIB_DIR}/pdcursesmod/pdcurses/window.c
102-
${LIB_DIR}/pdcursesmod/wingui/pdcclip.c
103-
${LIB_DIR}/pdcursesmod/wingui/pdcdisp.c
104-
${LIB_DIR}/pdcursesmod/wingui/pdcgetsc.c
105-
${LIB_DIR}/pdcursesmod/wingui/pdckbd.c
106-
${LIB_DIR}/pdcursesmod/wingui/pdcscrn.c
107-
${LIB_DIR}/pdcursesmod/wingui/pdcsetsc.c
108-
${LIB_DIR}/pdcursesmod/wingui/pdcutil.c
109-
${LIB_DIR}/pdcursesmod/wingui/pdcwin.h
110102
)
111103

104+
if (WIN32)
105+
set(PDCURSESLIST
106+
${PDCURSESLIST}
107+
${LIB_DIR}/pdcursesmod/wingui/pdcclip.c
108+
${LIB_DIR}/pdcursesmod/wingui/pdcdisp.c
109+
${LIB_DIR}/pdcursesmod/wingui/pdcgetsc.c
110+
${LIB_DIR}/pdcursesmod/wingui/pdckbd.c
111+
${LIB_DIR}/pdcursesmod/wingui/pdcscrn.c
112+
${LIB_DIR}/pdcursesmod/wingui/pdcsetsc.c
113+
${LIB_DIR}/pdcursesmod/wingui/pdcutil.c
114+
${LIB_DIR}/pdcursesmod/wingui/pdcwin.h
115+
)
116+
else()
117+
set(PDCURSESLIST
118+
${PDCURSESLIST}
119+
${LIB_DIR}/pdcursesmod/vt/pdcclip.c
120+
${LIB_DIR}/pdcursesmod/vt/pdcdisp.c
121+
${LIB_DIR}/pdcursesmod/vt/pdcgetsc.c
122+
${LIB_DIR}/pdcursesmod/vt/pdckbd.c
123+
${LIB_DIR}/pdcursesmod/vt/pdcscrn.c
124+
${LIB_DIR}/pdcursesmod/vt/pdcsetsc.c
125+
${LIB_DIR}/pdcursesmod/vt/pdcutil.c
126+
${LIB_DIR}/pdcursesmod/vt/pdcvt.h
127+
)
128+
endif()
129+
112130
set(TINYFORMATLIST
113131
${LIB_DIR}/tinyformat/tinyformat.h
114132
)

0 commit comments

Comments
 (0)