Skip to content

Commit

Permalink
patch 8.2.2662: there is no way to avoid some escape sequences
Browse files Browse the repository at this point in the history
Problem:    There is no way to avoid some escape sequences.
Solution:   Suppress escape sequences when the --not-a-term argument is used.
            (Gary Johnson)
  • Loading branch information
brammool committed Mar 27, 2021
1 parent bb5d87c commit 7007e31
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 10 deletions.
21 changes: 15 additions & 6 deletions src/main.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
11 changes: 7 additions & 4 deletions src/os_unix.c
Expand Up @@ -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
Expand All @@ -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
Expand Down
26 changes: 26 additions & 0 deletions src/testdir/test_startup.vim
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Expand Up @@ -750,6 +750,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
2662,
/**/
2661,
/**/
Expand Down

0 comments on commit 7007e31

Please sign in to comment.