# HG changeset patch # User Bram Moolenaar # Date 1616427004 -3600 # Node ID 9f64c420f2803503c3f2ba97279c68135cf85046 # Parent a926732fe169d953f186474c846066a8611ac0fa patch 8.2.2638: cannot write a message to the terminal from the GUI Commit: https://github.com/vim/vim/commit/4c86830fc578bcb47a51cf0983da5388cdbfe6cc Author: Bram Moolenaar Date: Mon Mar 22 16:19:45 2021 +0100 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 https://github.com/vim/vim/issues/7975) diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -13141,7 +13141,12 @@ text... < If you just want a highlighted message use |:echohl|. And to get a beep: > :exe "normal \" -< + +:echoc[onsole] {expr1} .. *:echoc* *:echoconsole* + Intended for testing: works like `:echomsg` but when + running in the GUI and started from a terminal write + the text to stdout. + *:eval* :eval {expr} Evaluate {expr} and discard the result. Example: > :eval Getlist()->Filter()->append('$') diff --git a/src/eval.c b/src/eval.c --- a/src/eval.c +++ b/src/eval.c @@ -6117,6 +6117,7 @@ get_echo_attr(void) * ":execute expr1 ..." execute the result of an expression. * ":echomsg expr1 ..." Print a message * ":echoerr expr1 ..." Print an error + * ":echoconsole expr1 ..." Print a message on stdout * Each gets spaces around each argument and a newline at the end for * echo commands */ @@ -6194,6 +6195,11 @@ ex_execute(exarg_T *eap) msg_attr(ga.ga_data, echo_attr); out_flush(); } + else if (eap->cmdidx == CMD_echoconsole) + { + ui_write(ga.ga_data, (int)STRLEN(ga.ga_data), TRUE); + ui_write((char_u *)"\r\n", 2, TRUE); + } else if (eap->cmdidx == CMD_echoerr) { int save_did_emsg = did_emsg; diff --git a/src/ex_cmdidxs.h b/src/ex_cmdidxs.h --- a/src/ex_cmdidxs.h +++ b/src/ex_cmdidxs.h @@ -10,27 +10,27 @@ static const unsigned short cmdidxs1[26] /* c */ 43, /* d */ 109, /* e */ 134, - /* f */ 157, - /* g */ 174, - /* h */ 180, - /* i */ 189, - /* j */ 208, - /* k */ 210, - /* l */ 215, - /* m */ 277, - /* n */ 295, - /* o */ 315, - /* p */ 327, - /* q */ 366, - /* r */ 369, - /* s */ 389, - /* t */ 458, - /* u */ 503, - /* v */ 514, - /* w */ 535, - /* x */ 549, - /* y */ 559, - /* z */ 560 + /* f */ 158, + /* g */ 175, + /* h */ 181, + /* i */ 190, + /* j */ 209, + /* k */ 211, + /* l */ 216, + /* m */ 278, + /* n */ 296, + /* o */ 316, + /* p */ 328, + /* q */ 367, + /* r */ 370, + /* s */ 390, + /* t */ 459, + /* u */ 504, + /* v */ 515, + /* w */ 536, + /* x */ 550, + /* y */ 560, + /* z */ 561 }; /* @@ -45,7 +45,7 @@ static const unsigned char cmdidxs2[26][ /* 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 }, /* 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 }, /* 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 }, - /* 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 }, + /* 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 }, /* 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 }, /* 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 }, /* 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][ /* 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 } }; -static const int command_count = 575; +static const int command_count = 576; diff --git a/src/ex_cmds.h b/src/ex_cmds.h --- a/src/ex_cmds.h +++ b/src/ex_cmds.h @@ -530,6 +530,9 @@ EXCMD(CMD_echohl, "echohl", ex_echohl, EXCMD(CMD_echomsg, "echomsg", ex_execute, EX_EXTRA|EX_NOTRLCOM|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK, ADDR_NONE), +EXCMD(CMD_echoconsole, "echoconsole", ex_execute, + EX_EXTRA|EX_NOTRLCOM|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK, + ADDR_NONE), EXCMD(CMD_echon, "echon", ex_echo, EX_EXTRA|EX_NOTRLCOM|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK, ADDR_NONE), diff --git a/src/proto/ui.pro b/src/proto/ui.pro --- a/src/proto/ui.pro +++ b/src/proto/ui.pro @@ -1,11 +1,11 @@ /* ui.c */ -void ui_write(char_u *s, int len); +void ui_write(char_u *s, int len, int console); void ui_inchar_undo(char_u *s, int len); int ui_inchar(char_u *buf, int maxlen, long wtime, int tb_change_cnt); 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)); int ui_wait_for_chars_or_timer(long wtime, int (*wait_func)(long wtime, int *interrupted, int ignore_input), int *interrupted, int ignore_input); int ui_char_avail(void); -void ui_delay(long msec, int ignoreinput); +void ui_delay(long msec_arg, int ignoreinput); void ui_suspend(void); void suspend_shell(void); int ui_get_shellsize(void); diff --git a/src/term.c b/src/term.c --- a/src/term.c +++ b/src/term.c @@ -2545,7 +2545,7 @@ out_flush(void) // set out_pos to 0 before ui_write, to avoid recursiveness len = out_pos; out_pos = 0; - ui_write(out_buf, len); + ui_write(out_buf, len, FALSE); #ifdef FEAT_JOB_CHANNEL if (ch_log_output) { diff --git a/src/testdir/runtest.vim b/src/testdir/runtest.vim --- a/src/testdir/runtest.vim +++ b/src/testdir/runtest.vim @@ -162,7 +162,7 @@ function GetAllocId(name) endfunc func RunTheTest(test) - echo 'Executing ' . a:test + echoconsole 'Executing ' . a:test if has('reltime') let func_start = reltime() endif diff --git a/src/ui.c b/src/ui.c --- a/src/ui.c +++ b/src/ui.c @@ -18,10 +18,14 @@ #include "vim.h" void -ui_write(char_u *s, int len) +ui_write(char_u *s, int len, int console UNUSED) { #ifdef FEAT_GUI - if (gui.in_use && !gui.dying && !gui.starting) + if (gui.in_use && !gui.dying && !gui.starting +# ifndef NO_CONSOLE + && !console +# endif + ) { gui_write(s, len); if (p_wd) @@ -33,7 +37,7 @@ ui_write(char_u *s, int len) // Don't output anything in silent mode ("ex -s") unless 'verbose' set if (!(silent_mode && p_verbose == 0)) { -#if !defined(MSWIN) +# if !defined(MSWIN) char_u *tofree = NULL; if (output_conv.vc_type != CONV_NONE) @@ -43,9 +47,11 @@ ui_write(char_u *s, int len) if (tofree != NULL) s = tofree; } -#endif +# endif mch_write(s, len); + if (console && s[len - 1] == '\n') + fsync(1); # if !defined(MSWIN) if (output_conv.vc_type != CONV_NONE) diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -751,6 +751,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 2638, +/**/ 2637, /**/ 2636,