diff options
author | Sean Dewar <seandewar@users.noreply.github.com> | 2021-07-29 12:26:13 +0100 |
---|---|---|
committer | Sean Dewar <seandewar@users.noreply.github.com> | 2021-09-16 00:14:47 +0100 |
commit | 7e9ea083213c3eb195fbf206f12a3aac1fa29033 (patch) | |
tree | 7bf1d6dfaa12f6ce922e9fef37d2b2c92845b0d9 | |
parent | e88961943b85434ceebff6a31089c635ac39cd66 (diff) | |
download | rneovim-7e9ea083213c3eb195fbf206f12a3aac1fa29033.tar.gz rneovim-7e9ea083213c3eb195fbf206f12a3aac1fa29033.tar.bz2 rneovim-7e9ea083213c3eb195fbf206f12a3aac1fa29033.zip |
feat(f_chansend): support Blob data argument
-rw-r--r-- | runtime/doc/eval.txt | 4 | ||||
-rw-r--r-- | src/nvim/channel.c | 1 | ||||
-rw-r--r-- | src/nvim/eval/funcs.c | 12 | ||||
-rw-r--r-- | test/functional/core/channels_spec.lua | 5 |
4 files changed, 19 insertions, 3 deletions
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index a628b9d030..94be7b595e 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -3217,8 +3217,8 @@ chansend({id}, {data}) *chansend()* written if the write succeeded, 0 otherwise. See |channel-bytes| for more information. - {data} may be a string, string convertible, or a list. If - {data} is a list, the items will be joined by newlines; any + {data} may be a string, string convertible, |Blob|, or a list. + If {data} is a list, the items will be joined by newlines; any newlines in an item will be sent as NUL. To send a final newline, include a final empty string. Example: > :call chansend(id, ["abc", "123\n456", ""]) diff --git a/src/nvim/channel.c b/src/nvim/channel.c index 94db7fb3b9..54a59f6cc1 100644 --- a/src/nvim/channel.c +++ b/src/nvim/channel.c @@ -516,6 +516,7 @@ uint64_t channel_from_stdio(bool rpc, CallbackReader on_output, /// @param data will be consumed size_t channel_send(uint64_t id, char *data, size_t len, bool data_owned, const char **error) + FUNC_ATTR_NONNULL_ALL { Channel *chan = find_channel(id); size_t written = 0; diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index ec13aa7fbd..e83e0ac0cc 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -972,7 +972,17 @@ static void f_chansend(typval_T *argvars, typval_T *rettv, FunPtr fptr) } ptrdiff_t input_len = 0; - char *input = save_tv_as_string(&argvars[1], &input_len, false); + char *input = NULL; + if (argvars[1].v_type == VAR_BLOB) { + const blob_T *const b = argvars[1].vval.v_blob; + input_len = tv_blob_len(b); + if (input_len > 0) { + input = xmemdup(b->bv_ga.ga_data, input_len); + } + } else { + input = save_tv_as_string(&argvars[1], &input_len, false); + } + if (!input) { // Either the error has been handled by save_tv_as_string(), // or there is no input to send. diff --git a/test/functional/core/channels_spec.lua b/test/functional/core/channels_spec.lua index 1ef34c7318..6efa4f9b80 100644 --- a/test/functional/core/channels_spec.lua +++ b/test/functional/core/channels_spec.lua @@ -89,6 +89,9 @@ describe('channels', function() command("call chansend(id, 'howdy')") eq({"notification", "stdout", {id, {"[1, ['howdy'], 'stdin']"}}}, next_msg()) + command("call chansend(id, 0z686f6c61)") + eq({"notification", "stdout", {id, {"[1, ['hola'], 'stdin']"}}}, next_msg()) + command("call chanclose(id, 'stdin')") expect_twostreams({{"notification", "stdout", {id, {"[1, [''], 'stdin']"}}}, {'notification', 'stdout', {id, {''}}}}, @@ -131,6 +134,8 @@ describe('channels', function() command("call chansend(id, 'TEXT\n')") expect_twoline(id, "stdout", "TEXT\r", "[1, ['TEXT', ''], 'stdin']") + command("call chansend(id, 0z426c6f6273210a)") + expect_twoline(id, "stdout", "Blobs!\r", "[1, ['Blobs!', ''], 'stdin']") command("call chansend(id, 'neovan')") eq({"notification", "stdout", {id, {"neovan"}}}, next_msg()) |