Repository: neovim/neovim
File: test/functional/terminal/tui_spec.lua (Lua)

Code before:
      {MATCH:%d+ +}|
      {5:-- TERMINAL --}                                              |
    ]])
    restart_pid_check()
    gui_running_check()
  end)

  it('filters stdin marker from v:argv on restart #34417', function()
    if t.skip(is_os('win'), 'unstable on Windows') then
      return
    end
    clear()
    finally(function()
      n.check_close()
    end)
    local screen = tt.setup_child_nvim({
      '-u',
      'NONE',
      '-i',
      'NONE',
      '--cmd',
      'set notermguicolors',
      '-', -- stdin marker
    })
    tt.feed_data(':echo index(v:argv, "-") >= 0 ? v:true : v:false\013')
    screen:expect({ any = 'v:true' })
    tt.feed_data('\013')
    tt.feed_data(':restart\013')
    screen:expect([[
      ^                                                  |
      ~                                                 |*3
      {2:[No Name]                       0,0-1          All}|
                                                        |
      {5:-- TERMINAL --}                                    |
    ]])
    tt.feed_data(':echo index(v:argv, "-") >= 0 ? v:true : v:false\013')
    screen:expect({ any = 'v:false' })
  end)
end)

describe('TUI :connect', function()
  if t.skip(is_os('win'), "relies on :detach which currently doesn't work on windows") then
    return
  end

  local screen_empty = [[
    ^                                                  |
    {100:~                                                 }|*5
                                                      |
  ]]


Review comment (suggestion):
instead of this hack, can we connect to the child Nvim by returning the child address from `tt.setup_child_nvim` . E.g. 

1. get the job-id [here](https://github.com/neovim/neovim/blob/e8ace820934a9eb7f23b7a3f61ccea2c7de02043/test/functional/testterm.lua#L151) 
2. then get its address 
3. then use `n.connect()`
4. then use `n.set_session()`
5. then we can use `n.*` functions
6. then restore the main session again via `n.set_session()`

Code after:
      if server_session then
        server_session:close()
      end
      n.check_close()
    end)
    local server_pipe = new_pipename()
    local screen = tt.setup_child_nvim({
      '-u',
      'NONE',
      '-i',
      'NONE',
      '--listen',
      server_pipe,
      '--cmd',
      'set notermguicolors',
      '-',
    })
    screen:expect([[
      ^                                                  |
      ~                                                 |*3
      {2:[No Name] [RO]                  1,0-1          All}|
                                                        |
      {5:-- TERMINAL --}                                    |
    ]])
    server_session = n.connect(server_pipe)
    local expr = 'index(v:argv, "-") >= 0 ? v:true : v:false'
    local _, has_stdin = server_session:request('nvim_eval', expr)
    eq(true, has_stdin)

    tt.feed_data(':restart\013')
    screen:expect([[
      ^                                                  |
      ~                                                 |*3
      {2:[No Name]                       0,0-1          All}|
                                                        |
      {5:-- TERMINAL --}                                    |
    ]])
    server_session:close()
    server_session = n.connect(server_pipe)
    local _, has_stdin_after = server_session:request('nvim_eval', expr)
    eq(false, has_stdin_after)
  end)
end)

describe('TUI :connect', function()
  if t.skip(is_os('win'), "relies on :detach which currently doesn't work on windows") then
    return
  end

  local screen_empty = [[
    ^                                                  |