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

Code before:
    feed_csi('2;5H') -- Cursor to 2,5 (after any scrollback)
    screen:expect([[
      cool line 5                                       |
      cool^ line 6                                       |
      cool line 7                                       |
      cool line 8                                       |
      cool line 9                                       |
      cool line 10                                      |
      {5:-- TERMINAL --}                  7,5           Bot |
    ]])
    -- Check topline correct after leaving terminal mode.
    -- The new cursor position is one column left of the terminal's actual cursor position.
    command('stopinsert | call nvim_win_set_cursor(0, [1, 0])')
    screen:expect([[
      cool line 5                                       |
      coo^l line 6                                       |
      cool line 7                                       |
      cool line 8                                       |
      cool line 9                                       |
      cool line 10                                      |
                                      7,4           Bot |
    ]])
  end)

  it('in new tabpage has correct terminal size', function()
    screen:set_default_attr_ids({
      [1] = { reverse = true },
      [3] = { bold = true },
      [17] = { background = 2, foreground = Screen.colors.Grey0 },
      [18] = { background = 2, foreground = 8 },
      [19] = { underline = true, foreground = Screen.colors.Grey0, background = 7 },
      [20] = { underline = true, foreground = 5, background = 7 },
    })

    command('file foo | vsplit')
    screen:expect([[
      tty ready                │tty ready               |
      rows: 5, cols: 25        │rows: 5, cols: 25       |
      ^                         │                        |
                               │                        |*2
      {17:foo [-]                   }{18:foo [-]                 }|
      {3:-- TERMINAL --}                                    |
    ]])
    command('tab split')
    screen:expect([[
      {19: }{20:2}{19: foo }{3: foo }{1:                                     }{19:X}|
      tty ready                                         |
      rows: 5, cols: 25                                 |
      rows: 5, cols: 50                                 |
      ^                                                  |
                                                        |

Review comment (bug):
Dunno why this consistently happens only on Windows: https://github.com/neovim/neovim/actions/runs/21770029074/job/62816978757#step:7:10661

```
FAILED   test/functional/terminal/window_spec.lua @ 426: :terminal window updates terminal size
test/functional\terminal\window_spec.lua:469: Row 1 did not match.
Expected:
  |*rows: 5, cols: 25        │tty ready               |
  |*rows: 5, cols: 50        │rows: 5, cols: 25       |
  |*rows: 2, cols: 50        │rows: 5, cols: 50       |
  |*rows: 5, cols: 25        │rows: 2, cols: 50       |
  |*^                         │rows: 5, cols: 25       |
  |{17:foo [-]                   }{18:foo [-]                 }|
  |{3:-- TERMINAL --}                                    |
Actual:
  |*rows: 2, cols: 50        │rows: 2, cols: 50       |
  |*rows: 5, cols: 25        │rows: 5, cols: 25       |
  |*^                         │                        |
  |*                         │                        |
  |*                         │                        |
  |{17:foo [-]                   }{18:foo [-]                 }|
  |{3:-- TERMINAL --}                                    |
```

---

Also, the test from #37159 seems to be flaking occasionally on Windows: https://github.com/neovim/neovim/actions/runs/21785075626/job/62855122707#step:7:10662 😔

```
FAILED   test/functional/terminal/window_spec.lua @ 38: :terminal window resets horizontal scroll on resize #35331
test/functional\terminal\window_spec.lua:69: Row 1 did not match.
Expected:
  |*interact $ AAAAAAAAAAAAAAAAAA│$ AAAAAAAAAAAAAAAAA^A|
  |*AAAAAAAAAAAA                 │AAA                 |
  |                             │                    |
  |                             │                    |
  |                             │                    |
  |{119:1000                          }{120:1002                }|
  |                                                  |
Actual:
  |*AAAAAAAA                     │AAAA      ^          |
  |*                             │                    |
  |                             │                    |
  |                             │                    |
  |                             │                    |
  |{119:1000                          }{120:1002                }|
  |                                                  |
```

Code after:
    feed_csi('2;5H') -- Cursor to 2,5 (after any scrollback)
    screen:expect([[
      cool line 5                                       |
      cool^ line 6                                       |
      cool line 7                                       |
      cool line 8                                       |
      cool line 9                                       |
      cool line 10                                      |
      {5:-- TERMINAL --}                  7,5           Bot |
    ]])
    -- Check topline correct after leaving terminal mode.
    -- The new cursor position is one column left of the terminal's actual cursor position.
    command('stopinsert | call nvim_win_set_cursor(0, [1, 0])')
    screen:expect([[
      cool line 5                                       |
      coo^l line 6                                       |
      cool line 7                                       |
      cool line 8                                       |
      cool line 9                                       |
      cool line 10                                      |
                                      7,4           Bot |
    ]])
  end)

  it('updates terminal size', function()
    skip(is_os('win'), "Windows doesn't show all lines?")
    screen:set_default_attr_ids({
      [1] = { reverse = true },
      [2] = { background = 225, foreground = Screen.colors.Gray0 },
      [3] = { bold = true },
      [4] = { foreground = 12 },
      [5] = { reverse = true, bold = true },
      [17] = { background = 2, foreground = Screen.colors.Grey0 },
      [18] = { background = 2, foreground = 8 },
      [19] = { underline = true, foreground = Screen.colors.Grey0, background = 7 },
      [20] = { underline = true, foreground = 5, background = 7 },
    })

    command('file foo | vsplit')
    screen:expect([[
      tty ready                │tty ready               |
      rows: 5, cols: 25        │rows: 5, cols: 25       |
      ^                         │                        |
                               │                        |*2
      {17:foo [-]                   }{18:foo [-]                 }|
      {3:-- TERMINAL --}                                    |
    ]])
    command('tab split')
    screen:expect([[
      {19: }{20:2}{19: foo }{3: foo }{1:                                     }{19:X}|
      tty ready                                         |