diff options
author | Rui Abreu Ferreira <raf-ep@gmx.com> | 2017-03-18 00:06:47 +0000 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2017-05-03 12:48:24 +0200 |
commit | 685ca180f7c96f77a79c78d3b26bd003f8cd834c (patch) | |
tree | c8f74f7e9ca99ee323c7b25d3f4fc144962a7ac2 | |
parent | 31e5053253e1b341b341e772fa7f2e24d75488d3 (diff) | |
download | rneovim-685ca180f7c96f77a79c78d3b26bd003f8cd834c.tar.gz rneovim-685ca180f7c96f77a79c78d3b26bd003f8cd834c.tar.bz2 rneovim-685ca180f7c96f77a79c78d3b26bd003f8cd834c.zip |
win: Terminal UI #6315
For CI builds unibilium is provided through msys2 packages, and
libtermkey is built from source in third-party from equalsraf/libtermkey.
In Windows we cannot read terminal input from the stdin file descriptor,
instead use libuv's uv_tty API. It should handle key input and encoding.
The UI suspend is not implemented for Windows, because the
SIGSTP/SIGCONT do not exist in windows. Currently this is a NOOP.
Closes #3902
Closes #6640
-rw-r--r-- | CMakeLists.txt | 6 | ||||
-rw-r--r-- | ci/build.bat | 2 | ||||
-rw-r--r-- | src/nvim/tui/input.c | 6 | ||||
-rw-r--r-- | src/nvim/tui/input.h | 3 | ||||
-rw-r--r-- | src/nvim/tui/tui.c | 8 | ||||
-rw-r--r-- | third-party/CMakeLists.txt | 5 | ||||
-rw-r--r-- | third-party/cmake/BuildLibtermkey.cmake | 48 |
7 files changed, 60 insertions, 18 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 1b49d79499..03b13404a5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -324,11 +324,7 @@ if(MSGPACK_HAS_FLOAT32) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DNVIM_MSGPACK_HAS_FLOAT32") endif() -if(UNIX) - option(FEAT_TUI "Enable the Terminal UI" ON) -else() - option(FEAT_TUI "Enable the Terminal UI" OFF) -endif() +option(FEAT_TUI "Enable the Terminal UI" ON) if(FEAT_TUI) find_package(Unibilium REQUIRED) diff --git a/ci/build.bat b/ci/build.bat index 9071c0864e..bc110396ef 100644 --- a/ci/build.bat +++ b/ci/build.bat @@ -17,7 +17,7 @@ set PATH=C:\Program Files (x86)\CMake\bin\cpack.exe;%PATH% :: Build third-party dependencies C:\msys64\usr\bin\bash -lc "pacman --verbose --noconfirm -Su" || goto :error -C:\msys64\usr\bin\bash -lc "pacman --verbose --noconfirm --needed -S mingw-w64-%ARCH%-cmake mingw-w64-%ARCH%-perl mingw-w64-%ARCH%-diffutils gperf" || goto :error +C:\msys64\usr\bin\bash -lc "pacman --verbose --noconfirm --needed -S mingw-w64-%ARCH%-cmake mingw-w64-%ARCH%-perl mingw-w64-%ARCH%-diffutils mingw-w64-%ARCH%-unibilium gperf" || goto :error :: Setup python (use AppVeyor system python) C:\Python27\python.exe -m pip install neovim || goto :error diff --git a/src/nvim/tui/input.c b/src/nvim/tui/input.c index 3d37fabeee..03587d68f0 100644 --- a/src/nvim/tui/input.c +++ b/src/nvim/tui/input.c @@ -47,7 +47,13 @@ void term_input_init(TermInput *input, Loop *loop) int curflags = termkey_get_canonflags(input->tk); termkey_set_canonflags(input->tk, curflags | TERMKEY_CANON_DELBS); // setup input handle +#ifdef WIN32 + uv_tty_init(loop, &input->tty_in, 0, 1); + uv_tty_set_mode(&input->tty_in, UV_TTY_MODE_RAW); + rstream_init_stream(&input->read_stream, &input->tty_in, 0xfff); +#else rstream_init_fd(loop, &input->read_stream, input->in_fd, 0xfff); +#endif // initialize a timer handle for handling ESC with libtermkey time_watcher_init(loop, &input->timer_handle, input); } diff --git a/src/nvim/tui/input.h b/src/nvim/tui/input.h index 7d59cf5c6a..573cc9d683 100644 --- a/src/nvim/tui/input.h +++ b/src/nvim/tui/input.h @@ -17,6 +17,9 @@ typedef struct term_input { #endif TimeWatcher timer_handle; Loop *loop; +#ifdef WIN32 + uv_tty_t tty_in; +#endif Stream read_stream; RBuffer *key_buffer; uv_mutex_t key_buffer_mutex; diff --git a/src/nvim/tui/tui.c b/src/nvim/tui/tui.c index 522f7d59f2..e45c620176 100644 --- a/src/nvim/tui/tui.c +++ b/src/nvim/tui/tui.c @@ -251,7 +251,9 @@ static void tui_main(UIBridgeData *bridge, UI *ui) kv_init(data->invalid_regions); signal_watcher_init(data->loop, &data->winch_handle, ui); signal_watcher_init(data->loop, &data->cont_handle, data); +#ifdef UNIX signal_watcher_start(&data->cont_handle, sigcont_cb, SIGCONT); +#endif tui_terminal_start(ui); data->stop = false; // allow the main thread to continue, we are ready to start handling UI @@ -280,10 +282,12 @@ static void tui_scheduler(Event event, void *d) loop_schedule(data->loop, event); } +#ifdef UNIX static void sigcont_cb(SignalWatcher *watcher, int signum, void *data) { ((TUIData *)data)->cont_received = true; } +#endif static void sigwinch_cb(SignalWatcher *watcher, int signum, void *data) { @@ -744,6 +748,7 @@ static void tui_flush(UI *ui) flush_buf(ui, true); } +#ifdef UNIX static void suspend_event(void **argv) { UI *ui = argv[0]; @@ -765,15 +770,18 @@ static void suspend_event(void **argv) // resume the main thread CONTINUE(data->bridge); } +#endif static void tui_suspend(UI *ui) { +#ifdef UNIX TUIData *data = ui->data; // kill(0, SIGTSTP) won't stop the UI thread, so we must poll for SIGCONT // before continuing. This is done in another callback to avoid // loop_poll_events recursion multiqueue_put_event(data->loop->fast_events, event_create(suspend_event, 1, ui)); +#endif } static void tui_set_title(UI *ui, char *title) diff --git a/third-party/CMakeLists.txt b/third-party/CMakeLists.txt index d58ad1755a..b8dad75b24 100644 --- a/third-party/CMakeLists.txt +++ b/third-party/CMakeLists.txt @@ -105,8 +105,13 @@ set(LUAROCKS_SHA256 cae709111c5701235770047dfd7169f66b82ae1c7b9b79207f9df0afb722 set(UNIBILIUM_URL https://github.com/mauke/unibilium/archive/v1.2.0.tar.gz) set(UNIBILIUM_SHA256 623af1099515e673abfd3cae5f2fa808a09ca55dda1c65a7b5c9424eb304ead8) +if(WIN32) +set(LIBTERMKEY_URL https://github.com/equalsraf/libtermkey/archive/tb-windows.zip) +set(LIBTERMKEY_SHA256 c81e33e38662b151a49847ff4feef4f8c4b2a66f3e159a28b575cbc9bcd8ffea) +else() set(LIBTERMKEY_URL http://www.leonerd.org.uk/code/libtermkey/libtermkey-0.19.tar.gz) set(LIBTERMKEY_SHA256 c505aa4cb48c8fa59c526265576b97a19e6ebe7b7da20f4ecaae898b727b48b7) +endif() set(LIBVTERM_URL https://github.com/neovim/libvterm/archive/a9c7c6fd20fa35e0ad3e0e98901ca12dfca9c25c.tar.gz) set(LIBVTERM_SHA256 1a4272be91d9614dc183a503786df83b6584e4afaab7feaaa5409f841afbd796) diff --git a/third-party/cmake/BuildLibtermkey.cmake b/third-party/cmake/BuildLibtermkey.cmake index 57e14d36d3..4b581c2a01 100644 --- a/third-party/cmake/BuildLibtermkey.cmake +++ b/third-party/cmake/BuildLibtermkey.cmake @@ -1,21 +1,41 @@ -if(WIN32) - message(STATUS "Building libtermkey in Windows is not supported (skipping)") - return() -endif() find_package(PkgConfig REQUIRED) +if(WIN32) +ExternalProject_Add(libtermkey + PREFIX ${DEPS_BUILD_DIR} + URL ${LIBTERMKEY_URL} + DOWNLOAD_DIR ${DEPS_DOWNLOAD_DIR}/libtermkey + DOWNLOAD_COMMAND ${CMAKE_COMMAND} + -DPREFIX=${DEPS_BUILD_DIR} + -DDOWNLOAD_DIR=${DEPS_DOWNLOAD_DIR}/libtermkey + -DURL=${LIBTERMKEY_URL} + -DEXPECTED_SHA256=${LIBTERMKEY_SHA256} + -DTARGET=libtermkey + -DUSE_EXISTING_SRC_DIR=${USE_EXISTING_SRC_DIR} + -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/DownloadAndExtractFile.cmake + CONFIGURE_COMMAND ${CMAKE_COMMAND} ${DEPS_BUILD_DIR}/src/libtermkey + -DCMAKE_INSTALL_PREFIX=${DEPS_INSTALL_DIR} + # Pass toolchain + -DCMAKE_TOOLCHAIN_FILE=${TOOLCHAIN} + -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} + # Hack to avoid -rdynamic in Mingw + -DCMAKE_SHARED_LIBRARY_LINK_C_FLAGS="" + -DCMAKE_GENERATOR=${CMAKE_GENERATOR} + BUILD_COMMAND ${CMAKE_COMMAND} --build . --config ${CMAKE_BUILD_TYPE} + INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install --config ${CMAKE_BUILD_TYPE}) +else() ExternalProject_Add(libtermkey PREFIX ${DEPS_BUILD_DIR} URL ${LIBTERMKEY_URL} DOWNLOAD_DIR ${DEPS_DOWNLOAD_DIR}/libtermkey DOWNLOAD_COMMAND ${CMAKE_COMMAND} - -DPREFIX=${DEPS_BUILD_DIR} - -DDOWNLOAD_DIR=${DEPS_DOWNLOAD_DIR}/libtermkey - -DURL=${LIBTERMKEY_URL} - -DEXPECTED_SHA256=${LIBTERMKEY_SHA256} - -DTARGET=libtermkey - -DUSE_EXISTING_SRC_DIR=${USE_EXISTING_SRC_DIR} - -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/DownloadAndExtractFile.cmake + -DPREFIX=${DEPS_BUILD_DIR} + -DDOWNLOAD_DIR=${DEPS_DOWNLOAD_DIR}/libtermkey + -DURL=${LIBTERMKEY_URL} + -DEXPECTED_SHA256=${LIBTERMKEY_SHA256} + -DTARGET=libtermkey + -DUSE_EXISTING_SRC_DIR=${USE_EXISTING_SRC_DIR} + -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/DownloadAndExtractFile.cmake CONFIGURE_COMMAND "" BUILD_IN_SOURCE 1 BUILD_COMMAND "" @@ -24,6 +44,10 @@ ExternalProject_Add(libtermkey PKG_CONFIG_PATH=${DEPS_LIB_DIR}/pkgconfig CFLAGS=-fPIC install) +endif() list(APPEND THIRD_PARTY_DEPS libtermkey) -add_dependencies(libtermkey unibilium) +if(NOT WIN32) + # There is no unibilium build recipe for Windows yet + add_dependencies(libtermkey unibilium) +endif() |