]> granicus.if.org Git - vim/commitdiff
patch 8.2.2638: cannot write a message to the terminal from the GUI v8.2.2638
authorBram Moolenaar <Bram@vim.org>
Mon, 22 Mar 2021 15:19:45 +0000 (16:19 +0100)
committerBram Moolenaar <Bram@vim.org>
Mon, 22 Mar 2021 15:19:45 +0000 (16:19 +0100)
Problem:    Cannot write a message to the terminal from the GUI.
Solution:   Add :echoconsole and use it in the test runner. (issue #7975)

runtime/doc/eval.txt
src/eval.c
src/ex_cmdidxs.h
src/ex_cmds.h
src/proto/ui.pro
src/term.c
src/testdir/runtest.vim
src/ui.c
src/version.c

index 723a7329b3fba4e4179faa21f46d13dfd06883ac..86df7b5704c2701a1ca7ec99e50f39da750935d1 100644 (file)
@@ -13141,7 +13141,12 @@ text...
 <                      If you just want a highlighted message use |:echohl|.
                        And to get a beep: >
                :exe "normal \<Esc>"
-<
+
+: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('$')
index 6cdc10f68bfd69d0ca5b22dc7096b904f68f8377..95dd5e2e6ce99f880f1842b2d2eabcba3c8380b2 100644 (file)
@@ -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;
index 8afc445357d2770c77ab4dc60f71a7d3bdfb5e9f..70fb71a79423dfdab1a29994dd117a752e45d499 100644 (file)
@@ -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][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][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;
index 90fd015384c211e72a95bc5882ef1435e09d9d54..aa41ab3a28f1549a8bcab124cb7a47ce3cf34912 100644 (file)
@@ -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),
index 5aad9d8a094548c1ac32e7297f32de29f8a02e71..e75be32b97c6e91c10003c9eb1818ba502677a58 100644 (file)
@@ -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);
index d2ada6c2b056e28b12e3223adab09784b1a9e963..8ce577ec130272075088f0e0682bf4d9e9922643 100644 (file)
@@ -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)
        {
index 4602051a734c61dd2232b551215c7eda212e68ae..e43dd8d94471b869270442a32af37602bb05cacb 100644 (file)
@@ -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
index 3f4304f6921189076a729abd6b4c0cdd49ed3cf3..6c1c1de0289a52f6dea887ba12a91e48bee0b1f4 100644 (file)
--- a/src/ui.c
+++ b/src/ui.c
 #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)
index 399539d8c749e490b2afb8cbd75121fa5cd386e0..40411d8be392435eae030736fddd94b39e7ab1c2 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2638,
 /**/
     2637,
 /**/