On 2021-03-25, Gary Johnson wrote:
> On 2021-03-25, Christian Brabandt wrote:
> > On Mi, 24 Mär 2021, Ron Aaron wrote:
> > 
> > > I want to get the vim version for a bash script. The way I'm trying to 
> > > use is:
> > > 
> > > vim --not-a-term --cmd 'echo v:versionlong|quit'
> > > 
> > > However, that spews a bunch of ANSI terminal control stuff as well, which 
> > > I don't want. Is there an option to suppress that output?
> > 
> > Have you tried TERM=dumb vim --cmd 'echo v:versionlong|quit'?
> 
> I did.  It eliminated all but t_cm and added a ^M.

I think this is partly a bug in Vim.  There are a few places in the
code where Vim assumes that it is running in a terminal as it
normally does and should output terminal control sequences without
regard to the presence of --not-a-term.

I have attached a patch that seems to fix that problem.  If someone
would rather I submitted a PR, I can do that, too.  Since this is
just a proposal at this point, the patch was just easier for me.

Even with the patch, though, I think using :echo to send something
to stdout is incorrect.  The :echo command is intended to write to
the screen and does so under the control of Vim's screen management.
I think it would be a mistake to modify that code to have :echo
write to the screen or directly to stdout.  I think a better
approach is to use echoraw() when you want to write directly to
stdout.

That would change your command to this:

    vim --not-a-term --cmd 'call echoraw(v:versionlong)|quit'

If you want to put a newline on the end of that, use this:

    vim --not-a-term --cmd 'call echoraw(v:versionlong."\n")|quit'

Of course, neither of those will do what you want without my patch
applied.  We'll have to see if Bram et al. think that's a good idea.

Regards,
Gary

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20210326225648.GC22800%40phoenix.
diff --git a/src/main.c b/src/main.c
index 369741aba..4b992d141 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1531,7 +1531,8 @@ getout(int exitval)
 #ifdef FEAT_GUI
     if (!gui.in_use)
 #endif
-       windgoto((int)Rows - 1, 0);
+       if (!is_not_a_term())
+           windgoto((int)Rows - 1, 0);
 
 #if defined(FEAT_EVAL) || defined(FEAT_SYN_HL)
     // Optionally print hashtable efficiency.
@@ -1643,7 +1644,8 @@ getout(int exitval)
 #ifdef FEAT_GUI
     if (!gui.in_use)
 #endif
-       windgoto((int)Rows - 1, 0);
+       if (!is_not_a_term())
+           windgoto((int)Rows - 1, 0);
 
 #ifdef FEAT_JOB_CHANNEL
     job_stop_on_exit();
diff --git a/src/os_unix.c b/src/os_unix.c
index 1c8079917..62eb364a3 100644
--- a/src/os_unix.c
+++ b/src/os_unix.c
@@ -3343,7 +3343,7 @@ exit_scroll(void)
        else
            out_char('\n');
     }
-    else
+    else if (!is_not_a_term())
     {
        restore_cterm_colors();         // get original colors back
        msg_clr_eos_force();            // clear the rest of the display
@@ -3371,8 +3371,11 @@ mch_exit(int r)
        settmode(TMODE_COOK);
 #ifdef FEAT_TITLE
        // restore xterm title and icon name
-       mch_restore_title(SAVE_RESTORE_BOTH);
-       term_pop_title(SAVE_RESTORE_BOTH);
+       if (!is_not_a_term())
+       {
+           mch_restore_title(SAVE_RESTORE_BOTH);
+           term_pop_title(SAVE_RESTORE_BOTH);
+       }
 #endif
        /*
         * When t_ti is not empty but it doesn't cause swapping terminal

Raspunde prin e-mail lui