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
This commit is contained in:
Rui Abreu Ferreira 2017-03-18 00:06:47 +00:00 committed by Justin M. Keyes
parent 31e5053253
commit 685ca180f7
7 changed files with 60 additions and 18 deletions

View File

@ -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)

View File

@ -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

View File

@ -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);
}

View File

@ -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;

View File

@ -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)

View File

@ -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)

View File

@ -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
-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
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()