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>
diff --git a/src/main.c b/src/main.c
index f603a52..7766946 100644
--- a/src/main.c
+++ b/src/main.c
@@ -660,7 +660,7 @@
#if defined(UNIX) || defined(VMS)
// When switching screens and something caused a message from a vimrc
// 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;
#endif
diff --git a/src/testdir/test_startup.vim b/src/testdir/test_startup.vim
index 8052aa8..0387674 100644
--- a/src/testdir/test_startup.vim
+++ b/src/testdir/test_startup.vim
@@ -781,6 +781,68 @@
call assert_match('vim\c', v:progname)
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()
" must be able to get the output of Vim.
CheckUnix
diff --git a/src/version.c b/src/version.c
index 50743e0..a900afc 100644
--- a/src/version.c
+++ b/src/version.c
@@ -705,6 +705,8 @@
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1281,
+/**/
1280,
/**/
1279,