]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1281: extra newline output when editing stdin v9.1.1281
authorAbhijit Barik <Abhijit.Barik@ivanti.com>
Sun, 6 Apr 2025 14:12:06 +0000 (16:12 +0200)
committerChristian Brabandt <cb@256bit.org>
Sun, 6 Apr 2025 14:12:06 +0000 (16:12 +0200)
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>
src/main.c
src/testdir/test_startup.vim
src/version.c

index f603a52a52e09d24c55d3bb1b7ccc612782dcbfe..77669462889915022eda72ead2c19e1f6ce21f7c 100644 (file)
@@ -660,7 +660,7 @@ vim_main2(void)
 #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
 
index 8052aa883df3a5201970a062599d13a0351665da..03876749f45052d260b291397a07691a1a6c8ed3 100644 (file)
@@ -781,6 +781,68 @@ func Test_progpath()
   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
index 50743e051963fea5b9498ac0922fca6cafc83d15..a900afc7b1c6156e129e76fdf445265a5a5b0a0c 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1281,
 /**/
     1280,
 /**/