Skip to content

Commit

Permalink
ref #19 : add windows support MSYS2 + PDCurses
Browse files Browse the repository at this point in the history
  • Loading branch information
ggerganov committed Jan 4, 2021
1 parent af31323 commit 39f34ea
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 7 deletions.
18 changes: 11 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,20 @@ endif()
# dependencies

if (IMTUI_SUPPORT_NCURSES)
find_package(Curses REQUIRED)
CHECK_LIBRARY_EXISTS("${CURSES_NCURSES_LIBRARY}"
nodelay "" CURSES_NCURSES_HAS_NODELAY)
if(NOT CURSES_NCURSES_HAS_NODELAY)
if (MINGW)
set(CURSES_LIBRARIES pdcurses)
else()
find_package(Curses REQUIRED)
CHECK_LIBRARY_EXISTS("${CURSES_NCURSES_LIBRARY}"
nodelay "" CURSES_NCURSES_HAS_NODELAY)
if(NOT CURSES_NCURSES_HAS_NODELAY)
find_library(CURSES_EXTRA_LIBRARY tinfo)
CHECK_LIBRARY_EXISTS("${CURSES_EXTRA_LIBRARY}"
nodelay "" CURSES_TINFO_HAS_NODELAY)
endif()
if(CURSES_EXTRA_LIBRARY)
nodelay "" CURSES_TINFO_HAS_NODELAY)
endif()
if(CURSES_EXTRA_LIBRARY)
set(CURSES_LIBRARIES ${CURSES_LIBRARIES} ${CURSES_EXTRA_LIBRARY})
endif()
endif()
endif()

Expand Down
3 changes: 3 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ if (IMTUI_SUPPORT_NCURSES)
if (IMTUI_SUPPORT_CURL)
if (IMTUI_SUPPORT_CURL)
find_package(CURL REQUIRED)
if (MINGW)
set(CURL_LIBRARIES curl)
endif()
endif()

add_subdirectory(hnterm)
Expand Down
2 changes: 2 additions & 0 deletions examples/hnterm/impl-ncurses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ static void addTransfer(CURLM *cm, int idx, std::string && uri) {
}

bool hnInit() {
#ifndef _WIN32
struct sigaction sh;
struct sigaction osh;

Expand All @@ -119,6 +120,7 @@ bool hnInit() {
if (sigaction(SIGPIPE, &sh, &osh) < 0) {
return false;
}
#endif

curl_global_init(CURL_GLOBAL_ALL);
g_cm = curl_multi_init();
Expand Down
4 changes: 4 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ target_link_libraries(imtui PRIVATE

set_target_properties(imtui PROPERTIES PUBLIC_HEADER "include/imtui/imtui.h;include/imtui/imtui-impl-text.h")

if (MINGW)
target_link_libraries(imtui PUBLIC stdc++)
endif()

# ncurses

if (IMTUI_SUPPORT_NCURSES)
Expand Down
29 changes: 29 additions & 0 deletions src/imtui-impl-ncurses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,26 @@
#include "imtui/imtui-impl-ncurses.h"
#include "imtui/imtui-impl-text.h"

#ifdef _WIN32
#define NCURSES_MOUSE_VERSION
#include <pdcurses.h>
#define set_escdelay(X)

#define KEY_OFFSET 0xec00

#define KEY_CODE_YES (KEY_OFFSET + 0x00) /* If get_wch() gives a key code */

#define KEY_BREAK (KEY_OFFSET + 0x01) /* Not on PC KBD */
#define KEY_DOWN (KEY_OFFSET + 0x02) /* Down arrow key */
#define KEY_UP (KEY_OFFSET + 0x03) /* Up arrow key */
#define KEY_LEFT (KEY_OFFSET + 0x04) /* Left arrow key */
#define KEY_RIGHT (KEY_OFFSET + 0x05) /* Right arrow key */
#define KEY_HOME (KEY_OFFSET + 0x06) /* home key */
#define KEY_BACKSPACE (8) /* not on pc */
#define KEY_F0 (KEY_OFFSET + 0x08) /* function keys; 64 reserved */
#else
#include <ncurses.h>
#endif

#include <array>
#include <chrono>
Expand Down Expand Up @@ -223,6 +242,16 @@ bool ImTui_ImplNcurses_NewFrame() {
} else if (c == 336) {
ImGui::GetIO().KeysDown[ImGui::GetIO().KeyMap[ImGuiKey_DownArrow]] = true;
ImGui::GetIO().KeyShift = true;
} else if (c == KEY_BACKSPACE) {
ImGui::GetIO().KeysDown[ImGui::GetIO().KeyMap[ImGuiKey_Backspace]] = true;
} else if (c == KEY_LEFT) {
ImGui::GetIO().KeysDown[ImGui::GetIO().KeyMap[ImGuiKey_LeftArrow]] = true;
} else if (c == KEY_RIGHT) {
ImGui::GetIO().KeysDown[ImGui::GetIO().KeyMap[ImGuiKey_RightArrow]] = true;
} else if (c == KEY_UP) {
ImGui::GetIO().KeysDown[ImGui::GetIO().KeyMap[ImGuiKey_UpArrow]] = true;
} else if (c == KEY_DOWN) {
ImGui::GetIO().KeysDown[ImGui::GetIO().KeyMap[ImGuiKey_DownArrow]] = true;
} else {
keysDown[c] = true;
}
Expand Down
4 changes: 4 additions & 0 deletions third-party/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@ target_link_libraries(imgui-for-imtui PRIVATE
)

set_property(TARGET imgui-for-imtui PROPERTY POSITION_INDEPENDENT_CODE ON)

if (MINGW)
set_target_properties(imgui-for-imtui PROPERTIES COMPILE_FLAGS -fno-threadsafe-statics)
endif()

0 comments on commit 39f34ea

Please # to comment.