Skip to content

Commit a683bab

Browse files
committed
Merge remote-tracking branch 'vim/master'
2 parents 677d665 + 0e77b76 commit a683bab

13 files changed

Lines changed: 92 additions & 150 deletions

File tree

runtime/doc/eval.txt

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2031,7 +2031,8 @@ ch_sendraw({handle}, {string} [, {options}])
20312031
any send {string} over raw {handle}
20322032
ch_setoptions({handle}, {options})
20332033
none set options for {handle}
2034-
ch_status({handle}) String status of channel {handle}
2034+
ch_status({handle} [, {options}])
2035+
String status of channel {handle}
20352036
changenr() Number current change number
20362037
char2nr({expr}[, {utf8}]) Number ASCII/UTF8 value of first char in {expr}
20372038
cindent({lnum}) Number C indent for line {lnum}
@@ -3042,7 +3043,8 @@ ch_info({handle}) *ch_info()*
30423043
Returns a Dictionary with information about {handle}. The
30433044
items are:
30443045
"id" number of the channel
3045-
"status" "open" (any part is open) or "closed"
3046+
"status" "open", "buffered" or "closed", like
3047+
ch_status()
30463048
When opened with ch_open():
30473049
"hostname" the hostname of the address
30483050
"port" the port of the address
@@ -3051,11 +3053,11 @@ ch_info({handle}) *ch_info()*
30513053
"sock_io" "socket"
30523054
"sock_timeout" timeout in msec
30533055
When opened with job_start():
3054-
"out_status" "open" or "closed"
3056+
"out_status" "open", "buffered" or "closed"
30553057
"out_mode" "NL", "RAW", "JSON" or "JS"
30563058
"out_io" "null", "pipe", "file" or "buffer"
30573059
"out_timeout" timeout in msec
3058-
"err_status" "open" or "closed"
3060+
"err_status" "open", "buffered" or "closed"
30593061
"err_mode" "NL", "RAW", "JSON" or "JS"
30603062
"err_io" "out", "null", "pipe", "file" or "buffer"
30613063
"err_timeout" timeout in msec
@@ -3140,7 +3142,7 @@ ch_setoptions({handle}, {options}) *ch_setoptions()*
31403142
These options cannot be changed:
31413143
"waittime" only applies to |ch_open()|
31423144

3143-
ch_status({handle}) *ch_status()*
3145+
ch_status({handle} [, {options}]) *ch_status()*
31443146
Return the status of {handle}:
31453147
"fail" failed to open the channel
31463148
"open" channel can be used
@@ -3150,6 +3152,11 @@ ch_status({handle}) *ch_status()*
31503152
"buffered" is used when the channel was closed but there is
31513153
still data that can be obtained with |ch_read()|.
31523154

3155+
If {options} is given it can contain a "part" entry to specify
3156+
the part of the channel to return the status for: "out" or
3157+
"err". For example, to get the error status: >
3158+
ch_status(job, {"part": "err"})
3159+
<
31533160
*copy()*
31543161
copy({expr}) Make a copy of {expr}. For Numbers and Strings this isn't
31553162
different from using {expr} directly.

src/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2065,7 +2065,7 @@ test1 \
20652065
test40 test41 test42 test43 test44 test45 test48 test49 \
20662066
test50 test51 test52 test53 test54 test55 test56 test57 test58 test59 \
20672067
test60 test64 test65 test66 test67 test68 test69 \
2068-
test70 test71 test72 test73 test74 test75 test76 test77 test78 test79 \
2068+
test70 test72 test73 test74 test75 test76 test77 test78 test79 \
20692069
test80 test82 test83 test84 test85 test86 test87 test88 test89 \
20702070
test90 test91 test92 test93 test94 test95 test97 test98 test99 \
20712071
test100 test101 test103 test104 test107 test108:

src/channel.c

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2611,23 +2611,41 @@ channel_has_readahead(channel_T *channel, int part)
26112611

26122612
/*
26132613
* Return a string indicating the status of the channel.
2614+
* If "req_part" is not negative check that part.
26142615
*/
26152616
char *
2616-
channel_status(channel_T *channel)
2617+
channel_status(channel_T *channel, int req_part)
26172618
{
26182619
int part;
26192620
int has_readahead = FALSE;
26202621

26212622
if (channel == NULL)
26222623
return "fail";
2623-
if (channel_is_open(channel))
2624-
return "open";
2625-
for (part = PART_SOCK; part <= PART_ERR; ++part)
2626-
if (channel_has_readahead(channel, part))
2627-
{
2624+
if (req_part == PART_OUT)
2625+
{
2626+
if (channel->CH_OUT_FD != INVALID_FD)
2627+
return "open";
2628+
if (channel_has_readahead(channel, PART_OUT))
26282629
has_readahead = TRUE;
2629-
break;
2630-
}
2630+
}
2631+
else if (req_part == PART_ERR)
2632+
{
2633+
if (channel->CH_ERR_FD != INVALID_FD)
2634+
return "open";
2635+
if (channel_has_readahead(channel, PART_ERR))
2636+
has_readahead = TRUE;
2637+
}
2638+
else
2639+
{
2640+
if (channel_is_open(channel))
2641+
return "open";
2642+
for (part = PART_SOCK; part <= PART_ERR; ++part)
2643+
if (channel_has_readahead(channel, part))
2644+
{
2645+
has_readahead = TRUE;
2646+
break;
2647+
}
2648+
}
26312649

26322650
if (has_readahead)
26332651
return "buffered";
@@ -2640,15 +2658,21 @@ channel_part_info(channel_T *channel, dict_T *dict, char *name, int part)
26402658
chanpart_T *chanpart = &channel->ch_part[part];
26412659
char namebuf[20]; /* longest is "sock_timeout" */
26422660
size_t tail;
2661+
char *status;
26432662
char *s = "";
26442663

26452664
vim_strncpy((char_u *)namebuf, (char_u *)name, 4);
26462665
STRCAT(namebuf, "_");
26472666
tail = STRLEN(namebuf);
26482667

26492668
STRCPY(namebuf + tail, "status");
2650-
dict_add_nr_str(dict, namebuf, 0,
2651-
(char_u *)(chanpart->ch_fd == INVALID_FD ? "closed" : "open"));
2669+
if (chanpart->ch_fd != INVALID_FD)
2670+
status = "open";
2671+
else if (channel_has_readahead(channel, part))
2672+
status = "buffered";
2673+
else
2674+
status = "closed";
2675+
dict_add_nr_str(dict, namebuf, 0, (char_u *)status);
26522676

26532677
STRCPY(namebuf + tail, "mode");
26542678
switch (chanpart->ch_mode)
@@ -2681,7 +2705,7 @@ channel_part_info(channel_T *channel, dict_T *dict, char *name, int part)
26812705
channel_info(channel_T *channel, dict_T *dict)
26822706
{
26832707
dict_add_nr_str(dict, "id", channel->ch_id, NULL);
2684-
dict_add_nr_str(dict, "status", 0, (char_u *)channel_status(channel));
2708+
dict_add_nr_str(dict, "status", 0, (char_u *)channel_status(channel, -1));
26852709

26862710
if (channel->ch_hostname != NULL)
26872711
{
@@ -4269,6 +4293,8 @@ get_job_options(typval_T *tv, jobopt_T *opt, int supported)
42694293
val = get_tv_string(item);
42704294
if (STRCMP(val, "err") == 0)
42714295
opt->jo_part = PART_ERR;
4296+
else if (STRCMP(val, "out") == 0)
4297+
opt->jo_part = PART_OUT;
42724298
else
42734299
{
42744300
EMSG2(_(e_invarg2), val);

src/eval.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7305,7 +7305,7 @@ get_tv_string_buf_chk(typval_T *varp, char_u *buf)
73057305
#ifdef FEAT_JOB_CHANNEL
73067306
{
73077307
channel_T *channel = varp->vval.v_channel;
7308-
char *status = channel_status(channel);
7308+
char *status = channel_status(channel, -1);
73097309

73107310
if (channel == NULL)
73117311
vim_snprintf((char *)buf, NUMBUFLEN, "channel %s", status);

src/evalfunc.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ static struct fst
514514
{"ch_sendexpr", 2, 3, f_ch_sendexpr},
515515
{"ch_sendraw", 2, 3, f_ch_sendraw},
516516
{"ch_setoptions", 2, 2, f_ch_setoptions},
517-
{"ch_status", 1, 1, f_ch_status},
517+
{"ch_status", 1, 2, f_ch_status},
518518
#endif
519519
{"changenr", 0, 0, f_changenr},
520520
{"char2nr", 1, 2, f_char2nr},
@@ -1985,13 +1985,24 @@ f_ch_setoptions(typval_T *argvars, typval_T *rettv UNUSED)
19851985
f_ch_status(typval_T *argvars, typval_T *rettv)
19861986
{
19871987
channel_T *channel;
1988+
jobopt_T opt;
1989+
int part = -1;
19881990

19891991
/* return an empty string by default */
19901992
rettv->v_type = VAR_STRING;
19911993
rettv->vval.v_string = NULL;
19921994

19931995
channel = get_channel_arg(&argvars[0], FALSE, FALSE, 0);
1994-
rettv->vval.v_string = vim_strsave((char_u *)channel_status(channel));
1996+
1997+
if (argvars[1].v_type != VAR_UNKNOWN)
1998+
{
1999+
clear_job_options(&opt);
2000+
if (get_job_options(&argvars[1], &opt, JO_PART) == OK
2001+
&& (opt.jo_set & JO_PART))
2002+
part = opt.jo_part;
2003+
}
2004+
2005+
rettv->vval.v_string = vim_strsave((char_u *)channel_status(channel, part));
19952006
}
19962007
#endif
19972008

src/proto/channel.pro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ void channel_consume(channel_T *channel, int part, int len);
2424
int channel_collapse(channel_T *channel, int part, int want_nl);
2525
int channel_can_write_to(channel_T *channel);
2626
int channel_is_open(channel_T *channel);
27-
char *channel_status(channel_T *channel);
27+
char *channel_status(channel_T *channel, int req_part);
2828
void channel_info(channel_T *channel, dict_T *dict);
2929
void channel_close(channel_T *channel, int invoke_close_cb);
3030
void channel_close_in(channel_T *channel);

src/testdir/Make_all.mak

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ SCRIPTS_ALL = \
5353
test68.out \
5454
test69.out \
5555
test70.out \
56-
test71.out \
5756
test73.out \
5857
test75.out \
5958
test76.out \

src/testdir/test71.in

Lines changed: 0 additions & 94 deletions
This file was deleted.

src/testdir/test71.ok

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/testdir/test71a.in

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)