Repository: neovim
Issue: `screenstring()` doesn't work for Command line in child Neovim process
Labels: bug-regression,startup,messages

### Describe the bug

The `screenstring()` executed inside child Neovim process through RPC returns incorrect results for Command line area (omits its content while working correctly for `showcmd` area).

Judging by my GitHub Actions, it worked on commit 6134c1e8a but stopped working on f6929ea51.

From my work on #19020 I remember that this Command line area is treated somewhat differently from the rest of the window. This is based on [these lines](https://github.com/neovim/neovim/blob/8a4285d5637c146a0ae606918a8e77063c6a5f0d/src/nvim/eval.c#L5354-L5357) but I am not sure how it could have gotten affected in the previous couple of days.

@bfredl, sorry to mention you here to get your attention, but it seems you might have an idea of what is going on here. This breaks screenshot tests so it would be bad for this issue to get lost among others.

### Steps to reproduce

- Create 'init-child-screenstring.lua' with the following content:

    <details>
    <summary>init-child-screenstring.lua</summary>

    ```lua
    _G.new_child = function(nvim_executable)
      -- Create new child process
      local stdin = vim.loop.new_pipe()
      local stdout = vim.loop.new_pipe()
      local stderr = vim.loop.new_pipe()

      local address = vim.fn.tempname()

      vim.loop.spawn(nvim_executable or 'nvim', {
        stdio = { stdin, stdout, stderr },
        args = { '--clean', '--listen', address },
      }, function() end)

      -- Wait for Neovim to open
      vim.loop.sleep(200)

      -- Connect
      local channel = vim.fn.sockconnect('pipe', address, { rpc = true })

      -- Follow advice from https://github.com/neovim/neovim/issues/21630
      stdin:close()
      stdout:close()
      stderr:close()

      -- Create helper methods for easier demonstration
      local child = { channel = channel }

      -- Type keys (for initializing Visual mode)
      child.type_keys = function(keys) vim.rpcrequest(channel, 'nvim_input', keys) end

      -- Echo message in Command line area
      child.echo = function(msg) vim.rpcrequest(channel, 'nvim_echo', { { msg } }, false, {}) end

      -- Call `screenstring()` inside child process
      child.screenstring = function(row, col)
        return vim.rpcrequest(channel, 'nvim_exec_lua', 'return vim.fn.screenstring(...)', { row, col })
      end

      -- Main demo: print child process's last line (Command line with defaults)
      child.print_last_line = function()
        local n_lines = vim.rpcrequest(channel, 'nvim_get_option', 'lines')
        local n_cols = vim.rpcrequest(channel, 'nvim_get_option', 'columns')
        local last_line = {}
        for i = 1, n_cols do
          table.insert(last_line, child.screenstring(n_lines, i))
        end

        print(vim.inspect(table.concat(last_line)))
      end

      return child
    end
    ```

    </details>

    It is basically a creation-connection to full child process (following advice from #21630) and then a couple helper wrappers to get information from child process through RPC requests.

- Assuming `nvim_nightly_g737` is the executable for latest nightly, run `nvim_nightly_g737 -u init-child-screenstring.lua`.
- `:lua child = new_child('nvim_nightly_g737')`. This should create and connect to child process running latest nightly.
- Execute one of the following:
    - `:lua child.type_keys('V')` - this should initialize Visual linewise mode. When executed in non-child process it is followed by showing `-- VISUAL LINE --` in Command line.
    - `:lua child.echo('Hello world!')` - this should show the message in Command line.
- Execute `:lua child.print_last_line()`. For both of versions of previous step it prints content of Command line but **without messages at the start**.

### Expected behavior

Prints actual content of Command line:

- The one starting with `-- VISUAL LINE --` if `child.type_keys('V')` was executed.
- The one starting with `Hello world!` if `child.echo('Hello world!')` was executed.

To check the expected content, initiate child process with `:lua child = new_child('nvim')` (assuming `nvim` is an executable for commit earlier than 6134c1e8a (like 0.8.2).

### Neovim version (nvim -v)

NVIM v0.9.0-dev-737+g0aae7f386

### Vim (not Nvim) behaves the same?

No (doesn't have this functionality)

### Operating system/version

EndeavourOS Linux x86_64 (6.1.6-arch1-1)

### Terminal name/version

st-0.9

### $TERM environment variable

st-256color

### Installation

appimage