diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index d539f268be..01f34d4bde 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -2031,7 +2031,8 @@ ch_sendraw({handle}, {string} [, {options}]) any send {string} over raw {handle} ch_setoptions({handle}, {options}) none set options for {handle} -ch_status({handle}) String status of channel {handle} +ch_status({handle} [, {options}]) + String status of channel {handle} changenr() Number current change number char2nr({expr}[, {utf8}]) Number ASCII/UTF8 value of first char in {expr} cindent({lnum}) Number C indent for line {lnum} @@ -3042,7 +3043,8 @@ ch_info({handle}) *ch_info()* Returns a Dictionary with information about {handle}. The items are: "id" number of the channel - "status" "open" (any part is open) or "closed" + "status" "open", "buffered" or "closed", like + ch_status() When opened with ch_open(): "hostname" the hostname of the address "port" the port of the address @@ -3051,11 +3053,11 @@ ch_info({handle}) *ch_info()* "sock_io" "socket" "sock_timeout" timeout in msec When opened with job_start(): - "out_status" "open" or "closed" + "out_status" "open", "buffered" or "closed" "out_mode" "NL", "RAW", "JSON" or "JS" "out_io" "null", "pipe", "file" or "buffer" "out_timeout" timeout in msec - "err_status" "open" or "closed" + "err_status" "open", "buffered" or "closed" "err_mode" "NL", "RAW", "JSON" or "JS" "err_io" "out", "null", "pipe", "file" or "buffer" "err_timeout" timeout in msec @@ -3140,7 +3142,7 @@ ch_setoptions({handle}, {options}) *ch_setoptions()* These options cannot be changed: "waittime" only applies to |ch_open()| -ch_status({handle}) *ch_status()* +ch_status({handle} [, {options}]) *ch_status()* Return the status of {handle}: "fail" failed to open the channel "open" channel can be used @@ -3150,6 +3152,11 @@ ch_status({handle}) *ch_status()* "buffered" is used when the channel was closed but there is still data that can be obtained with |ch_read()|. + If {options} is given it can contain a "part" entry to specify + the part of the channel to return the status for: "out" or + "err". For example, to get the error status: > + ch_status(job, {"part": "err"}) +< *copy()* copy({expr}) Make a copy of {expr}. For Numbers and Strings this isn't different from using {expr} directly. diff --git a/src/Makefile b/src/Makefile index 45b9071375..b30c9650a5 100644 --- a/src/Makefile +++ b/src/Makefile @@ -2065,7 +2065,7 @@ test1 \ test40 test41 test42 test43 test44 test45 test48 test49 \ test50 test51 test52 test53 test54 test55 test56 test57 test58 test59 \ test60 test64 test65 test66 test67 test68 test69 \ - test70 test71 test72 test73 test74 test75 test76 test77 test78 test79 \ + test70 test72 test73 test74 test75 test76 test77 test78 test79 \ test80 test82 test83 test84 test85 test86 test87 test88 test89 \ test90 test91 test92 test93 test94 test95 test97 test98 test99 \ test100 test101 test103 test104 test107 test108: diff --git a/src/channel.c b/src/channel.c index c09a17dbaf..70af912111 100644 --- a/src/channel.c +++ b/src/channel.c @@ -2611,23 +2611,41 @@ channel_has_readahead(channel_T *channel, int part) /* * Return a string indicating the status of the channel. + * If "req_part" is not negative check that part. */ char * -channel_status(channel_T *channel) +channel_status(channel_T *channel, int req_part) { int part; int has_readahead = FALSE; if (channel == NULL) return "fail"; - if (channel_is_open(channel)) - return "open"; - for (part = PART_SOCK; part <= PART_ERR; ++part) - if (channel_has_readahead(channel, part)) - { + if (req_part == PART_OUT) + { + if (channel->CH_OUT_FD != INVALID_FD) + return "open"; + if (channel_has_readahead(channel, PART_OUT)) has_readahead = TRUE; - break; - } + } + else if (req_part == PART_ERR) + { + if (channel->CH_ERR_FD != INVALID_FD) + return "open"; + if (channel_has_readahead(channel, PART_ERR)) + has_readahead = TRUE; + } + else + { + if (channel_is_open(channel)) + return "open"; + for (part = PART_SOCK; part <= PART_ERR; ++part) + if (channel_has_readahead(channel, part)) + { + has_readahead = TRUE; + break; + } + } if (has_readahead) return "buffered"; @@ -2640,6 +2658,7 @@ channel_part_info(channel_T *channel, dict_T *dict, char *name, int part) chanpart_T *chanpart = &channel->ch_part[part]; char namebuf[20]; /* longest is "sock_timeout" */ size_t tail; + char *status; char *s = ""; vim_strncpy((char_u *)namebuf, (char_u *)name, 4); @@ -2647,8 +2666,13 @@ channel_part_info(channel_T *channel, dict_T *dict, char *name, int part) tail = STRLEN(namebuf); STRCPY(namebuf + tail, "status"); - dict_add_nr_str(dict, namebuf, 0, - (char_u *)(chanpart->ch_fd == INVALID_FD ? "closed" : "open")); + if (chanpart->ch_fd != INVALID_FD) + status = "open"; + else if (channel_has_readahead(channel, part)) + status = "buffered"; + else + status = "closed"; + dict_add_nr_str(dict, namebuf, 0, (char_u *)status); STRCPY(namebuf + tail, "mode"); switch (chanpart->ch_mode) @@ -2681,7 +2705,7 @@ channel_part_info(channel_T *channel, dict_T *dict, char *name, int part) channel_info(channel_T *channel, dict_T *dict) { dict_add_nr_str(dict, "id", channel->ch_id, NULL); - dict_add_nr_str(dict, "status", 0, (char_u *)channel_status(channel)); + dict_add_nr_str(dict, "status", 0, (char_u *)channel_status(channel, -1)); if (channel->ch_hostname != NULL) { @@ -4269,6 +4293,8 @@ get_job_options(typval_T *tv, jobopt_T *opt, int supported) val = get_tv_string(item); if (STRCMP(val, "err") == 0) opt->jo_part = PART_ERR; + else if (STRCMP(val, "out") == 0) + opt->jo_part = PART_OUT; else { EMSG2(_(e_invarg2), val); diff --git a/src/eval.c b/src/eval.c index 6873b978af..3b5abe9c39 100644 --- a/src/eval.c +++ b/src/eval.c @@ -7305,7 +7305,7 @@ get_tv_string_buf_chk(typval_T *varp, char_u *buf) #ifdef FEAT_JOB_CHANNEL { channel_T *channel = varp->vval.v_channel; - char *status = channel_status(channel); + char *status = channel_status(channel, -1); if (channel == NULL) vim_snprintf((char *)buf, NUMBUFLEN, "channel %s", status); diff --git a/src/evalfunc.c b/src/evalfunc.c index 11a0368edd..60f8a7c77b 100644 --- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -514,7 +514,7 @@ static struct fst {"ch_sendexpr", 2, 3, f_ch_sendexpr}, {"ch_sendraw", 2, 3, f_ch_sendraw}, {"ch_setoptions", 2, 2, f_ch_setoptions}, - {"ch_status", 1, 1, f_ch_status}, + {"ch_status", 1, 2, f_ch_status}, #endif {"changenr", 0, 0, f_changenr}, {"char2nr", 1, 2, f_char2nr}, @@ -1985,13 +1985,24 @@ f_ch_setoptions(typval_T *argvars, typval_T *rettv UNUSED) f_ch_status(typval_T *argvars, typval_T *rettv) { channel_T *channel; + jobopt_T opt; + int part = -1; /* return an empty string by default */ rettv->v_type = VAR_STRING; rettv->vval.v_string = NULL; channel = get_channel_arg(&argvars[0], FALSE, FALSE, 0); - rettv->vval.v_string = vim_strsave((char_u *)channel_status(channel)); + + if (argvars[1].v_type != VAR_UNKNOWN) + { + clear_job_options(&opt); + if (get_job_options(&argvars[1], &opt, JO_PART) == OK + && (opt.jo_set & JO_PART)) + part = opt.jo_part; + } + + rettv->vval.v_string = vim_strsave((char_u *)channel_status(channel, part)); } #endif diff --git a/src/proto/channel.pro b/src/proto/channel.pro index 02153a6500..2b63291a2a 100644 --- a/src/proto/channel.pro +++ b/src/proto/channel.pro @@ -24,7 +24,7 @@ void channel_consume(channel_T *channel, int part, int len); int channel_collapse(channel_T *channel, int part, int want_nl); int channel_can_write_to(channel_T *channel); int channel_is_open(channel_T *channel); -char *channel_status(channel_T *channel); +char *channel_status(channel_T *channel, int req_part); void channel_info(channel_T *channel, dict_T *dict); void channel_close(channel_T *channel, int invoke_close_cb); void channel_close_in(channel_T *channel); diff --git a/src/testdir/Make_all.mak b/src/testdir/Make_all.mak index 999f519abf..0909f4f7cc 100644 --- a/src/testdir/Make_all.mak +++ b/src/testdir/Make_all.mak @@ -53,7 +53,6 @@ SCRIPTS_ALL = \ test68.out \ test69.out \ test70.out \ - test71.out \ test73.out \ test75.out \ test76.out \ diff --git a/src/testdir/test71.in b/src/testdir/test71.in deleted file mode 100644 index 944b69dc52..0000000000 --- a/src/testdir/test71.in +++ /dev/null @@ -1,94 +0,0 @@ -Test for encryption. -The test data is in another file to avoid problems with 'encoding', especially -cp932. - -STARTTEST -:so small.vim -:set enc=latin1 -:bwipe! -:r test71a.in -:/^start of text/+1 -:let text_lines = getline('.', line('.') + 2) -:/^start of cm=zip bytes/+1 -:let cm0_bytes = getline('.', '.') -:/^start of cm=blowfish bytes/+1 -:let cm1_bytes = getline('.', '.') -:/^start of cm=blowfish2 bytes/+1 -:let cm2_bytes = getline('.', '.') -:bwipe! -:call append(0, text_lines) -:$d -:X -foobar -foobar -:w! Xtestfile -:bwipe! -:e Xtestfile -foobar -:let cm0_read_back = getline('.', '$') -:set key= -:set cryptmethod=blowfish -:" If the blowfish test fails 'cryptmethod' will be 'zip' now. -:%s/^/\=&cryptmethod == 'blowfish' ? "OK " : "blowfish test failed "/ -:X -barfoo -barfoo -:w! Xtestfile -:bwipe! -:e Xtestfile -barfoo -:let cm1_read_back = getline('.', '$') -:set key= -:set cryptmethod=blowfish2 -:" If the blowfish test fails 'cryptmethod' will be 'zip' now. -:%s/^/\=&cryptmethod == 'blowfish2' ? "OK " : "blowfish test failed "/ -:X -bar2foo -bar2foo -:w! Xtestfile -:bwipe! -:e Xtestfile -bar2foo -:let cm2_read_back = getline('.', '$') -:bwipe! -:set bin noeol key= -:call append(0, cm0_bytes) -:$d -:set fenc=latin1 -:w! Xtestfile -:bwipe! -:set nobin -:e Xtestfile -foofoo -:let cm0_read_bin = getline('.', '$') -:bwipe! -:set bin noeol key= -:call append(0, cm1_bytes) -:$d -:set fenc=latin1 -:w! Xtestfile -:bwipe! -:set nobin -:e Xtestfile -barbar -:let cm1_read_bin = getline('.', '$') -:bwipe! -:set bin noeol key= -:call append(0, cm2_bytes) -:$d -:set fenc=latin1 -:w! Xtestfile -:bwipe! -:set nobin -:e Xtestfile -barburp -:call append(0, cm1_read_bin) -:call append(0, cm0_read_bin) -:call append(0, cm2_read_back) -:call append(0, cm1_read_back) -:call append(0, cm0_read_back) -:set key= fenc=latin1 -:w! test.out -:qa! -ENDTEST - diff --git a/src/testdir/test71.ok b/src/testdir/test71.ok deleted file mode 100644 index de1b0ab837..0000000000 --- a/src/testdir/test71.ok +++ /dev/null @@ -1,15 +0,0 @@ -01234567890123456789012345678901234567 -line 2 foo bar blah -line 3 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -OK 01234567890123456789012345678901234567 -OK line 2 foo bar blah -OK line 3 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -OK OK 01234567890123456789012345678901234567 -OK OK line 2 foo bar blah -OK OK line 3 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -1234567890 -abbccddeff -asdfasdfasdf -0001112223333 -abcdefghijklmnopqrstuvwxyz -!@#$%^&*()_+=-`~ diff --git a/src/testdir/test71a.in b/src/testdir/test71a.in deleted file mode 100644 index e79a39895a..0000000000 --- a/src/testdir/test71a.in +++ /dev/null @@ -1,18 +0,0 @@ - -start of text -01234567890123456789012345678901234567 -line 2 foo bar blah -line 3 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -end of text - -start of cm=zip bytes -VimCrypt~01!lV'}MgVE#32U -end of cm=zip bytes - -start of cm=blowfish bytes -VimCrypt~02!k)#S=#MJAͥM! -end of cm=blowfish bytes - -start of cm=blowfish2 bytes -VimCrypt~03!N;^C).FS6[T˧ؾ9 2 Q@ߚIv.`$% -end of cm=blowfish2 bytes diff --git a/src/testdir/test_channel.vim b/src/testdir/test_channel.vim index f8252f1a3c..eb75a0b1d2 100644 --- a/src/testdir/test_channel.vim +++ b/src/testdir/test_channel.vim @@ -434,6 +434,23 @@ func Test_raw_pipe() let job = job_start(s:python . " test_channel_pipe.py", {'mode': 'raw'}) call assert_equal(v:t_job, type(job)) call assert_equal("run", job_status(job)) + + call assert_equal("open", ch_status(job)) + call assert_equal("open", ch_status(job), {"part": "out"}) + call assert_equal("open", ch_status(job), {"part": "err"}) + call assert_fails('call ch_status(job, {"in_mode": "raw"})', 'E475:') + call assert_fails('call ch_status(job, {"part": "in"})', 'E475:') + + let dict = ch_info(job) + call assert_true(dict.id != 0) + call assert_equal('open', dict.status) + call assert_equal('open', dict.out_status) + call assert_equal('RAW', dict.out_mode) + call assert_equal('pipe', dict.out_io) + call assert_equal('open', dict.err_status) + call assert_equal('RAW', dict.err_mode) + call assert_equal('pipe', dict.err_io) + try " For a change use the job where a channel is expected. call ch_sendraw(job, "echo something\n") diff --git a/src/testdir/test_crypt.vim b/src/testdir/test_crypt.vim index 96b8b1bfab..4e9cc2e512 100644 --- a/src/testdir/test_crypt.vim +++ b/src/testdir/test_crypt.vim @@ -1,5 +1,8 @@ " Tests for encryption. -" TODO: include tests from test71. + +if !has('cryptv') + finish +endif func Common_head_only(text) " This was crashing Vim diff --git a/src/version.c b/src/version.c index 096b354dfc..b25b93ad1c 100644 --- a/src/version.c +++ b/src/version.c @@ -779,6 +779,12 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 16, +/**/ + 15, +/**/ + 14, /**/ 13, /**/