mirror of
https://github.com/neovim/neovim.git
synced 2024-12-20 03:05:11 -07:00
feat(f_chansend): support Blob data argument
This commit is contained in:
parent
e88961943b
commit
7e9ea08321
@ -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", ""])
|
||||
|
@ -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;
|
||||
|
@ -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.
|
||||
|
@ -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())
|
||||
|
Loading…
Reference in New Issue
Block a user