mirror of
				https://github.com/vim/vim.git
				synced 2025-10-30 09:47:20 -04:00 
			
		
		
		
	patch 9.1.1281: extra newline output when editing stdin
Problem:  extra newline output when editing stdin
Solution: remove outputting when reading from stdin in non-terminal mode
          (Abhijit Barik)
fixes: #16856
closes: #17047
Co-authored-by: LemonBoy <LemonBoy@users.noreply.github.com>
Signed-off-by: Abhijit Barik <Abhijit.Barik@ivanti.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
			
			
This commit is contained in:
		
				
					committed by
					
						 Christian Brabandt
						Christian Brabandt
					
				
			
			
				
	
			
			
			
						parent
						
							ba73766788
						
					
				
				
					commit
					221927b2bf
				
			| @@ -660,7 +660,7 @@ vim_main2(void) | |||||||
| #if defined(UNIX) || defined(VMS) | #if defined(UNIX) || defined(VMS) | ||||||
|     // When switching screens and something caused a message from a vimrc |     // When switching screens and something caused a message from a vimrc | ||||||
|     // script, need to output an extra newline on exit. |     // script, need to output an extra newline on exit. | ||||||
|     if ((did_emsg || msg_didout) && *T_TI != NUL) |     if ((did_emsg || msg_didout) && *T_TI != NUL && params.edit_type != EDIT_STDIN) | ||||||
| 	newline_on_exit = TRUE; | 	newline_on_exit = TRUE; | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
|   | |||||||
| @@ -781,6 +781,68 @@ func Test_progpath() | |||||||
|   call assert_match('vim\c', v:progname) |   call assert_match('vim\c', v:progname) | ||||||
| endfunc | endfunc | ||||||
|  |  | ||||||
|  | func Test_stdin_no_newline() | ||||||
|  |   CheckScreendump | ||||||
|  |   CheckUnix | ||||||
|  |   CheckExecutable bash | ||||||
|  |  | ||||||
|  |   let $PS1 = 'TEST_PROMPT> ' | ||||||
|  |   let buf = RunVimInTerminal('', #{rows: 20, cmd: 'bash --noprofile --norc'}) | ||||||
|  |   call TermWait(buf, 100) | ||||||
|  |  | ||||||
|  |   " Write input to temp file | ||||||
|  |   call term_sendkeys(buf, "echo hello > temp.txt\<CR>") | ||||||
|  |   call TermWait(buf, 200) | ||||||
|  |  | ||||||
|  |   call term_sendkeys(buf, "bash -c '../vim --not-a-term -u NONE -c \":q!\" -' < temp.txt\<CR>") | ||||||
|  |   call TermWait(buf, 200) | ||||||
|  |  | ||||||
|  |   " Capture terminal output | ||||||
|  |   let lines = [] | ||||||
|  |   for i in range(1, term_getsize(buf)[0]) | ||||||
|  |     call add(lines, term_getline(buf, i)) | ||||||
|  |   endfor | ||||||
|  |  | ||||||
|  |   " Find the command line in output | ||||||
|  |   let cmd_line = -1 | ||||||
|  |   for i in range(len(lines)) | ||||||
|  |     if lines[i] =~ '.*vim.*--not-a-term.*' | ||||||
|  |       let cmd_line = i | ||||||
|  |       break | ||||||
|  |     endif | ||||||
|  |   endfor | ||||||
|  |  | ||||||
|  |   if cmd_line == -1 | ||||||
|  |     call assert_report('Command line not found in terminal output') | ||||||
|  |   else | ||||||
|  |     let next_line = -1 | ||||||
|  |     for i in range(cmd_line + 1, len(lines)) | ||||||
|  |       if lines[i] =~ '\S' | ||||||
|  |         let next_line = i | ||||||
|  |         break | ||||||
|  |       endif | ||||||
|  |     endfor | ||||||
|  |  | ||||||
|  |     if next_line == -1 | ||||||
|  |       call assert_report('No prompt found after command execution') | ||||||
|  |     else | ||||||
|  |       call assert_equal(cmd_line + 1, next_line, 'Prompt should be on the immediate next line') | ||||||
|  |       call assert_match('.*TEST_PROMPT>.*', lines[next_line], 'Line should contain the prompt PS1') | ||||||
|  |     endif | ||||||
|  |   endif | ||||||
|  |  | ||||||
|  |   " Clean up temp file and exit shell | ||||||
|  |   call term_sendkeys(buf, "rm -f temp.txt\<CR>") | ||||||
|  |   call term_sendkeys(buf, "exit\<CR>") | ||||||
|  |   call TermWait(buf, 200) | ||||||
|  |  | ||||||
|  |   if job_status(term_getjob(buf)) ==# 'run' | ||||||
|  |     call StopVimInTerminal(buf) | ||||||
|  |   endif | ||||||
|  |  | ||||||
|  |   unlet $PS1 | ||||||
|  | endfunc | ||||||
|  |  | ||||||
| func Test_silent_ex_mode() | func Test_silent_ex_mode() | ||||||
|   " must be able to get the output of Vim. |   " must be able to get the output of Vim. | ||||||
|   CheckUnix |   CheckUnix | ||||||
|   | |||||||
| @@ -704,6 +704,8 @@ static char *(features[]) = | |||||||
|  |  | ||||||
| static int included_patches[] = | static int included_patches[] = | ||||||
| {   /* Add new patch number below this line */ | {   /* Add new patch number below this line */ | ||||||
|  | /**/ | ||||||
|  |     1281, | ||||||
| /**/ | /**/ | ||||||
|     1280, |     1280, | ||||||
| /**/ | /**/ | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user