summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2021-03-27 12:11:33 +0100
committerBram Moolenaar <Bram@vim.org>2021-03-27 12:11:33 +0100
commit7007e31bde75b6360a1b54c7572e4f855458f37d (patch)
tree0119498d79dd4ea241d54d85c1d35ad434ff8fa3
parentbb5d87c8504588be9c9d2fecc5b6455a2b2f6201 (diff)
patch 8.2.2662: there is no way to avoid some escape sequencesv8.2.2662
Problem: There is no way to avoid some escape sequences. Solution: Suppress escape sequences when the --not-a-term argument is used. (Gary Johnson)
-rw-r--r--src/main.c21
-rw-r--r--src/os_unix.c11
-rw-r--r--src/testdir/test_startup.vim26
-rw-r--r--src/version.c2
4 files changed, 50 insertions, 10 deletions
diff --git a/src/main.c b/src/main.c
index 369741abad..30014d4be2 100644
--- a/src/main.c
+++ b/src/main.c
@@ -995,6 +995,19 @@ is_not_a_term()
return params.not_a_term;
}
+/*
+ * Return TRUE when the --not-a-term argument was found or the GUI is in use.
+ */
+ static int
+is_not_a_term_or_gui()
+{
+ return params.not_a_term
+#ifdef FEAT_GUI
+ || gui.in_use
+#endif
+ ;
+}
+
// When TRUE in a safe state when starting to wait for a character.
static int was_safe = FALSE;
@@ -1528,9 +1541,7 @@ getout(int exitval)
#endif
// Position the cursor on the last screen line, below all the text
-#ifdef FEAT_GUI
- if (!gui.in_use)
-#endif
+ if (!is_not_a_term_or_gui())
windgoto((int)Rows - 1, 0);
#if defined(FEAT_EVAL) || defined(FEAT_SYN_HL)
@@ -1640,9 +1651,7 @@ getout(int exitval)
}
// Position the cursor again, the autocommands may have moved it
-#ifdef FEAT_GUI
- if (!gui.in_use)
-#endif
+ if (!is_not_a_term_or_gui())
windgoto((int)Rows - 1, 0);
#ifdef FEAT_JOB_CHANNEL
diff --git a/src/os_unix.c b/src/os_unix.c
index 1c80799174..20c61106f9 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
@@ -3370,9 +3370,12 @@ 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())
+ {
+ // restore xterm title and icon name
+ 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
diff --git a/src/testdir/test_startup.vim b/src/testdir/test_startup.vim
index 323b019c1c..2d5fdcb246 100644
--- a/src/testdir/test_startup.vim
+++ b/src/testdir/test_startup.vim
@@ -1043,6 +1043,32 @@ func Test_io_not_a_terminal()
\ 'Vim: Warning: Input is not from a terminal'], l)
endfunc
+" Test for --not-a-term avoiding escape codes.
+func Test_not_a_term()
+ CheckUnix
+ CheckNotGui
+
+ if &shellredir =~ '%s'
+ let redir = printf(&shellredir, 'Xvimout')
+ else
+ let redir = &shellredir .. ' Xvimout'
+ endif
+
+ " Without --not-a-term there are a few escape sequences.
+ " This will take 2 seconds because of the missing --not-a-term
+ let cmd = GetVimProg() .. ' --cmd quit ' .. redir
+ exe "silent !" . cmd
+ call assert_match("\<Esc>", readfile('Xvimout')->join())
+ call delete('Xvimout')
+
+ " With --not-a-term there are no escape sequences.
+ let cmd = GetVimProg() .. ' --not-a-term --cmd quit ' .. redir
+ exe "silent !" . cmd
+ call assert_notmatch("\<Esc>", readfile('Xvimout')->join())
+ call delete('Xvimout')
+endfunc
+
+
" Test for the "-w scriptout" argument
func Test_w_arg()
" Can't catch the output of gvim.
diff --git a/src/version.c b/src/version.c
index 5596bbb27c..60fe36f0f6 100644
--- 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 */
/**/
+ 2662,
+/**/
2661,
/**/
2660,