microsoft / microsoft/terminal

Active screen buffer size is out of sync

Open
#16,231 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Area-Server Issue-Bug Priority-2 Product-Conpty
Dominant language
C++
Stars
105k
Forks
9.6k
Avg merge
3d 17h
Merged PRs (30d)
29

Description

### Windows Terminal version

current main branch

### Windows build number

10.0.19045.3448

### Other Software

_No response_

### Steps to reproduce

- Run WT with any profile
- Run the following c++20 code (creates additional screen buffer and make it active)
- Resize the current pane (e.g., split pane)
- Press any key to exit
- Check the current size report - it is not valid
- Run any TUI app just to be sure (e.g. wsl mc )

```cpp
#include
#include

int main()
{
auto len = DWORD{};
auto rec = INPUT_RECORD{};
auto inf = CONSOLE_SCREEN_BUFFER_INFO{};
auto inp = ::GetStdHandle(STD_INPUT_HANDLE);
auto out = ::GetStdHandle(STD_OUTPUT_HANDLE);
auto alt = ::CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, 0, 0, CONSOLE_TEXTMODE_BUFFER, 0);
::SetConsoleActiveScreenBuffer(alt);
::GetConsoleScreenBufferInfo(alt, &inf);
auto msg = "current size: " + std::to_string(inf.dwSize.X) + "x" + std::to_string(inf.dwSize.Y)
+ "\nchange pane size and press any key\n";
::WriteFile(alt, msg.data(), msg.size(), &len, 0);
while (true)
{
::ReadConsoleInputW(inp, &rec, 1, &len);
if (rec.EventType == KEY_EVENT && rec.Event.KeyEvent.bKeyDown) break;
else if (rec.EventType == WINDOW_BUFFER_SIZE_EVENT)
{
::GetConsoleScreenBufferInfo(out /*not alt*/, &inf);
msg = "current size: " + std::to_string(inf.dwSize.X) + "x" + std::to_string(inf.dwSize.Y) + "\n";
::WriteFile(alt, msg.data(), msg.size(), &len, 0);
}
}
::SetConsoleActiveScreenBuffer(out);
::GetConsoleScreenBufferInfo(out, &inf);
msg = "current size: " + std::to_string(inf.dwSize.X) + "x" + std::to_string(inf.dwSize.Y) + "\n";
::WriteFile(out, msg.data(), msg.size(), &len, 0);
}
```

### Expected Behavior

After run
```
current size: 106x20
change pane size and press any key
current size: 51x20
```
After exit
```
PS D:\sources\test\size_test\x64\Debug> .\cpp20app.exe
current size: 51x20
PS D:\sources\test\size_test\x64\Debug>
```

### Actual Behavior

After run
```
current size: 106x22
change pane size and press any key
current size: 106x22
```
After exit (the size has not changed despite the pane split!)
```
PS D:\sources\test\size_test\x64\Debug> .\cpp20app.exe
current size: 106x21
PS D:\sources\test\size_test\x64\Debug>
```
wsl mc:
![image](https://github.com/microsoft/terminal/assets/11535558/fda13e1b-d209-4913-854f-181aef6035d6)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the provided C++20 reproducer on Windows Terminal with a split-pane resize, then compare the reported screen-buffer dimensions before and after the resize. Check the behavior with a TUI app such as `wsl mc`; done means the active buffer and returned console size reflect the resized pane after the alternate buffer is restored.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
cli, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.