Skip to content

Commit 4c86830

Browse files
committed
patch 8.2.2638: cannot write a message to the terminal from the GUI
Problem: Cannot write a message to the terminal from the GUI. Solution: Add :echoconsole and use it in the test runner. (issue #7975)
1 parent 09f8b3a commit 4c86830

9 files changed

Lines changed: 54 additions & 32 deletions

File tree

runtime/doc/eval.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13141,7 +13141,12 @@ text...
1314113141
< If you just want a highlighted message use |:echohl|.
1314213142
And to get a beep: >
1314313143
:exe "normal \<Esc>"
13144-
<
13144+
13145+
:echoc[onsole] {expr1} .. *:echoc* *:echoconsole*
13146+
Intended for testing: works like `:echomsg` but when
13147+
running in the GUI and started from a terminal write
13148+
the text to stdout.
13149+
1314513150
*:eval*
1314613151
:eval {expr} Evaluate {expr} and discard the result. Example: >
1314713152
:eval Getlist()->Filter()->append('$')

src/eval.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6117,6 +6117,7 @@ get_echo_attr(void)
61176117
* ":execute expr1 ..." execute the result of an expression.
61186118
* ":echomsg expr1 ..." Print a message
61196119
* ":echoerr expr1 ..." Print an error
6120+
* ":echoconsole expr1 ..." Print a message on stdout
61206121
* Each gets spaces around each argument and a newline at the end for
61216122
* echo commands
61226123
*/
@@ -6194,6 +6195,11 @@ ex_execute(exarg_T *eap)
61946195
msg_attr(ga.ga_data, echo_attr);
61956196
out_flush();
61966197
}
6198+
else if (eap->cmdidx == CMD_echoconsole)
6199+
{
6200+
ui_write(ga.ga_data, (int)STRLEN(ga.ga_data), TRUE);
6201+
ui_write((char_u *)"\r\n", 2, TRUE);
6202+
}
61976203
else if (eap->cmdidx == CMD_echoerr)
61986204
{
61996205
int save_did_emsg = did_emsg;

src/ex_cmdidxs.h

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,27 @@ static const unsigned short cmdidxs1[26] =
1010
/* c */ 43,
1111
/* d */ 109,
1212
/* e */ 134,
13-
/* f */ 157,
14-
/* g */ 174,
15-
/* h */ 180,
16-
/* i */ 189,
17-
/* j */ 208,
18-
/* k */ 210,
19-
/* l */ 215,
20-
/* m */ 277,
21-
/* n */ 295,
22-
/* o */ 315,
23-
/* p */ 327,
24-
/* q */ 366,
25-
/* r */ 369,
26-
/* s */ 389,
27-
/* t */ 458,
28-
/* u */ 503,
29-
/* v */ 514,
30-
/* w */ 535,
31-
/* x */ 549,
32-
/* y */ 559,
33-
/* z */ 560
13+
/* f */ 158,
14+
/* g */ 175,
15+
/* h */ 181,
16+
/* i */ 190,
17+
/* j */ 209,
18+
/* k */ 211,
19+
/* l */ 216,
20+
/* m */ 278,
21+
/* n */ 296,
22+
/* o */ 316,
23+
/* p */ 328,
24+
/* q */ 367,
25+
/* r */ 370,
26+
/* s */ 390,
27+
/* t */ 459,
28+
/* u */ 504,
29+
/* v */ 515,
30+
/* w */ 536,
31+
/* x */ 550,
32+
/* y */ 560,
33+
/* z */ 561
3434
};
3535

3636
/*
@@ -45,7 +45,7 @@ static const unsigned char cmdidxs2[26][26] =
4545
/* b */ { 2, 0, 0, 5, 6, 8, 0, 0, 0, 0, 0, 9, 10, 11, 12, 13, 0, 14, 0, 0, 0, 0, 23, 0, 0, 0 },
4646
/* c */ { 3, 12, 16, 18, 20, 22, 25, 0, 0, 0, 0, 33, 37, 40, 46, 56, 58, 59, 60, 0, 62, 0, 65, 0, 0, 0 },
4747
/* d */ { 0, 0, 0, 0, 0, 0, 0, 0, 8, 18, 0, 19, 0, 0, 20, 0, 0, 22, 23, 0, 0, 0, 0, 0, 0, 0 },
48-
/* e */ { 1, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 10, 0, 0, 0, 0, 0, 0, 0, 17, 0, 18, 0, 0 },
48+
/* e */ { 1, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 8, 10, 11, 0, 0, 0, 0, 0, 0, 0, 18, 0, 19, 0, 0 },
4949
/* f */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0 },
5050
/* g */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 2, 0, 0, 4, 5, 0, 0, 0, 0 },
5151
/* h */ { 5, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
@@ -69,4 +69,4 @@ static const unsigned char cmdidxs2[26][26] =
6969
/* z */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
7070
};
7171

72-
static const int command_count = 575;
72+
static const int command_count = 576;

src/ex_cmds.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,9 @@ EXCMD(CMD_echohl, "echohl", ex_echohl,
530530
EXCMD(CMD_echomsg, "echomsg", ex_execute,
531531
EX_EXTRA|EX_NOTRLCOM|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK,
532532
ADDR_NONE),
533+
EXCMD(CMD_echoconsole, "echoconsole", ex_execute,
534+
EX_EXTRA|EX_NOTRLCOM|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK,
535+
ADDR_NONE),
533536
EXCMD(CMD_echon, "echon", ex_echo,
534537
EX_EXTRA|EX_NOTRLCOM|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK,
535538
ADDR_NONE),

src/proto/ui.pro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/* ui.c */
2-
void ui_write(char_u *s, int len);
2+
void ui_write(char_u *s, int len, int console);
33
void ui_inchar_undo(char_u *s, int len);
44
int ui_inchar(char_u *buf, int maxlen, long wtime, int tb_change_cnt);
55
int inchar_loop(char_u *buf, int maxlen, long wtime, int tb_change_cnt, int (*wait_func)(long wtime, int *interrupted, int ignore_input), int (*resize_func)(int check_only));
66
int ui_wait_for_chars_or_timer(long wtime, int (*wait_func)(long wtime, int *interrupted, int ignore_input), int *interrupted, int ignore_input);
77
int ui_char_avail(void);
8-
void ui_delay(long msec, int ignoreinput);
8+
void ui_delay(long msec_arg, int ignoreinput);
99
void ui_suspend(void);
1010
void suspend_shell(void);
1111
int ui_get_shellsize(void);

src/term.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2545,7 +2545,7 @@ out_flush(void)
25452545
// set out_pos to 0 before ui_write, to avoid recursiveness
25462546
len = out_pos;
25472547
out_pos = 0;
2548-
ui_write(out_buf, len);
2548+
ui_write(out_buf, len, FALSE);
25492549
#ifdef FEAT_JOB_CHANNEL
25502550
if (ch_log_output)
25512551
{

src/testdir/runtest.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ function GetAllocId(name)
162162
endfunc
163163

164164
func RunTheTest(test)
165-
echo 'Executing ' . a:test
165+
echoconsole 'Executing ' . a:test
166166
if has('reltime')
167167
let func_start = reltime()
168168
endif

src/ui.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,14 @@
1818
#include "vim.h"
1919

2020
void
21-
ui_write(char_u *s, int len)
21+
ui_write(char_u *s, int len, int console UNUSED)
2222
{
2323
#ifdef FEAT_GUI
24-
if (gui.in_use && !gui.dying && !gui.starting)
24+
if (gui.in_use && !gui.dying && !gui.starting
25+
# ifndef NO_CONSOLE
26+
&& !console
27+
# endif
28+
)
2529
{
2630
gui_write(s, len);
2731
if (p_wd)
@@ -33,7 +37,7 @@ ui_write(char_u *s, int len)
3337
// Don't output anything in silent mode ("ex -s") unless 'verbose' set
3438
if (!(silent_mode && p_verbose == 0))
3539
{
36-
#if !defined(MSWIN)
40+
# if !defined(MSWIN)
3741
char_u *tofree = NULL;
3842

3943
if (output_conv.vc_type != CONV_NONE)
@@ -43,9 +47,11 @@ ui_write(char_u *s, int len)
4347
if (tofree != NULL)
4448
s = tofree;
4549
}
46-
#endif
50+
# endif
4751

4852
mch_write(s, len);
53+
if (console && s[len - 1] == '\n')
54+
fsync(1);
4955

5056
# if !defined(MSWIN)
5157
if (output_conv.vc_type != CONV_NONE)

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,8 @@ static char *(features[]) =
750750

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
2638,
753755
/**/
754756
2637,
755757
/**/

0 commit comments

Comments
 (0)