mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Merge PR #1613 'Fix shell command output'
This commit is contained in:
commit
33530ac9a4
@ -141,7 +141,7 @@ int os_call_shell(char_u *cmd, ShellOpts opts, char_u *extra_arg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (output) {
|
if (output) {
|
||||||
write_output(output, nread);
|
(void)write_output(output, nread, true, true);
|
||||||
free(output);
|
free(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,6 +197,9 @@ static int shell(const char *cmd,
|
|||||||
// the output buffer
|
// the output buffer
|
||||||
DynamicBuffer buf = DYNAMIC_BUFFER_INIT;
|
DynamicBuffer buf = DYNAMIC_BUFFER_INIT;
|
||||||
rstream_cb data_cb = system_data_cb;
|
rstream_cb data_cb = system_data_cb;
|
||||||
|
if (nread) {
|
||||||
|
*nread = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (forward_output) {
|
if (forward_output) {
|
||||||
data_cb = out_data_cb;
|
data_cb = out_data_cb;
|
||||||
@ -296,9 +299,9 @@ static void system_data_cb(RStream *rstream, void *data, bool eof)
|
|||||||
static void out_data_cb(RStream *rstream, void *data, bool eof)
|
static void out_data_cb(RStream *rstream, void *data, bool eof)
|
||||||
{
|
{
|
||||||
RBuffer *rbuffer = rstream_buffer(rstream);
|
RBuffer *rbuffer = rstream_buffer(rstream);
|
||||||
size_t len = rbuffer_pending(rbuffer);
|
size_t written = write_output(rbuffer_read_ptr(rbuffer),
|
||||||
ui_write((char_u *)rbuffer_read_ptr(rbuffer), (int)len);
|
rbuffer_pending(rbuffer), false, eof);
|
||||||
rbuffer_consumed(rbuffer, len);
|
rbuffer_consumed(rbuffer, written);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parses a command string into a sequence of words, taking quotes into
|
/// Parses a command string into a sequence of words, taking quotes into
|
||||||
@ -407,18 +410,27 @@ static void read_input(DynamicBuffer *buf)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void write_output(char *output, size_t remaining)
|
static size_t write_output(char *output, size_t remaining, bool to_buffer,
|
||||||
|
bool eof)
|
||||||
{
|
{
|
||||||
if (!output) {
|
if (!output) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *start = output;
|
||||||
size_t off = 0;
|
size_t off = 0;
|
||||||
while (off < remaining) {
|
while (off < remaining) {
|
||||||
if (output[off] == NL) {
|
if (output[off] == NL) {
|
||||||
// Insert the line
|
// Insert the line
|
||||||
output[off] = NUL;
|
output[off] = NUL;
|
||||||
ml_append(curwin->w_cursor.lnum++, (char_u *)output, 0, false);
|
if (to_buffer) {
|
||||||
|
ml_append(curwin->w_cursor.lnum++, (char_u *)output, 0, false);
|
||||||
|
} else {
|
||||||
|
// pending data from the output buffer has been flushed to the screen,
|
||||||
|
// safe to call ui_write directly
|
||||||
|
ui_write((char_u *)output, (int)off);
|
||||||
|
ui_write((char_u *)"\r\n", 2);
|
||||||
|
}
|
||||||
size_t skip = off + 1;
|
size_t skip = off + 1;
|
||||||
output += skip;
|
output += skip;
|
||||||
remaining -= skip;
|
remaining -= skip;
|
||||||
@ -433,14 +445,26 @@ static void write_output(char *output, size_t remaining)
|
|||||||
off++;
|
off++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (remaining) {
|
if (eof) {
|
||||||
// append unfinished line
|
if (remaining) {
|
||||||
ml_append(curwin->w_cursor.lnum++, (char_u *)output, 0, false);
|
if (to_buffer) {
|
||||||
// remember that the NL was missing
|
// append unfinished line
|
||||||
curbuf->b_no_eol_lnum = curwin->w_cursor.lnum;
|
ml_append(curwin->w_cursor.lnum++, (char_u *)output, 0, false);
|
||||||
} else {
|
// remember that the NL was missing
|
||||||
curbuf->b_no_eol_lnum = 0;
|
curbuf->b_no_eol_lnum = curwin->w_cursor.lnum;
|
||||||
|
} else {
|
||||||
|
ui_write((char_u *)output, (int)remaining);
|
||||||
|
ui_write((char_u *)"\r\n", 2);
|
||||||
|
}
|
||||||
|
output += remaining;
|
||||||
|
} else if (to_buffer) {
|
||||||
|
curbuf->b_no_eol_lnum = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
out_flush();
|
||||||
|
|
||||||
|
return (size_t)(output - start);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void shell_write_cb(WStream *wstream, void *data, int status)
|
static void shell_write_cb(WStream *wstream, void *data, int status)
|
||||||
|
15
third-party/CMakeLists.txt
vendored
15
third-party/CMakeLists.txt
vendored
@ -97,9 +97,10 @@ if(USE_BUNDLED_LIBUNIBILIUM)
|
|||||||
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/DownloadAndExtractFile.cmake
|
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/DownloadAndExtractFile.cmake
|
||||||
CONFIGURE_COMMAND ""
|
CONFIGURE_COMMAND ""
|
||||||
BUILD_IN_SOURCE 1
|
BUILD_IN_SOURCE 1
|
||||||
BUILD_COMMAND ${MAKE_PRG} CC=${DEPS_C_COMPILER}
|
BUILD_COMMAND ${MAKE_PRG} CC=${CMAKE_C_COMPILER}
|
||||||
PREFIX=${DEPS_INSTALL_DIR}
|
PREFIX=${DEPS_INSTALL_DIR}
|
||||||
CFLAGS=-fPIC
|
CFLAGS+=${CMAKE_C_COMPILER_ARG1}
|
||||||
|
CFLAGS+=-fPIC
|
||||||
INSTALL_COMMAND ${MAKE_PRG} PREFIX=${DEPS_INSTALL_DIR} install)
|
INSTALL_COMMAND ${MAKE_PRG} PREFIX=${DEPS_INSTALL_DIR} install)
|
||||||
list(APPEND THIRD_PARTY_DEPS libunibilium)
|
list(APPEND THIRD_PARTY_DEPS libunibilium)
|
||||||
endif()
|
endif()
|
||||||
@ -120,10 +121,11 @@ if(USE_BUNDLED_LIBTERMKEY)
|
|||||||
CONFIGURE_COMMAND ""
|
CONFIGURE_COMMAND ""
|
||||||
BUILD_IN_SOURCE 1
|
BUILD_IN_SOURCE 1
|
||||||
BUILD_COMMAND ""
|
BUILD_COMMAND ""
|
||||||
INSTALL_COMMAND ${MAKE_PRG} CC=${DEPS_C_COMPILER}
|
INSTALL_COMMAND ${MAKE_PRG} CC=${CMAKE_C_COMPILER}
|
||||||
PREFIX=${DEPS_INSTALL_DIR}
|
PREFIX=${DEPS_INSTALL_DIR}
|
||||||
PKG_CONFIG_PATH=${DEPS_LIB_DIR}/pkgconfig
|
PKG_CONFIG_PATH=${DEPS_LIB_DIR}/pkgconfig
|
||||||
CFLAGS=-fPIC
|
CFLAGS+=${CMAKE_C_COMPILER_ARG1}
|
||||||
|
CFLAGS+=-fPIC
|
||||||
install)
|
install)
|
||||||
list(APPEND THIRD_PARTY_DEPS libtermkey)
|
list(APPEND THIRD_PARTY_DEPS libtermkey)
|
||||||
add_dependencies(libtermkey libunibilium)
|
add_dependencies(libtermkey libunibilium)
|
||||||
@ -145,10 +147,11 @@ if(USE_BUNDLED_LIBTICKIT)
|
|||||||
CONFIGURE_COMMAND ""
|
CONFIGURE_COMMAND ""
|
||||||
BUILD_IN_SOURCE 1
|
BUILD_IN_SOURCE 1
|
||||||
BUILD_COMMAND ""
|
BUILD_COMMAND ""
|
||||||
INSTALL_COMMAND ${MAKE_PRG} CC=${DEPS_C_COMPILER}
|
INSTALL_COMMAND ${MAKE_PRG} CC=${CMAKE_C_COMPILER}
|
||||||
PREFIX=${DEPS_INSTALL_DIR}
|
PREFIX=${DEPS_INSTALL_DIR}
|
||||||
PKG_CONFIG_PATH=${DEPS_LIB_DIR}/pkgconfig
|
PKG_CONFIG_PATH=${DEPS_LIB_DIR}/pkgconfig
|
||||||
CFLAGS=-fPIC
|
CFLAGS+=${CMAKE_C_COMPILER_ARG1}
|
||||||
|
CFLAGS+=-fPIC
|
||||||
install)
|
install)
|
||||||
list(APPEND THIRD_PARTY_DEPS libtickit)
|
list(APPEND THIRD_PARTY_DEPS libtickit)
|
||||||
add_dependencies(libtickit libtermkey)
|
add_dependencies(libtickit libtermkey)
|
||||||
|
Loading…
Reference in New Issue
Block a user