Active screen buffer size is out of sync #20734

Open
opened 2026-01-31 07:22:32 +00:00 by claunia · 3 comments
Owner

Originally created by @o-sdn-o on GitHub (Oct 26, 2023).

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 )
#include <string>
#include <windows.h>

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

Originally created by @o-sdn-o on GitHub (Oct 26, 2023). ### 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 <string> #include <windows.h> 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)
claunia added the Issue-BugArea-ServerProduct-ConptyPriority-2 labels 2026-01-31 07:22:33 +00:00
Author
Owner

@237dmitry commented on GitHub (Oct 26, 2023):

How does it reproduce without your app? I tried with `e[?1049h and `e[?1049l but could not. [console]::BufferWidth was always correct.

@237dmitry commented on GitHub (Oct 26, 2023): How does it reproduce without your app? I tried with ``` `e[?1049h ``` and ``` `e[?1049l ``` but could not. `[console]::BufferWidth` was always correct.
Author
Owner

@o-sdn-o commented on GitHub (Oct 26, 2023):

I don't know how to reproduce this without Win32 Console API.

@o-sdn-o commented on GitHub (Oct 26, 2023): I don't know how to reproduce this without Win32 Console API.
Author
Owner

@zadjii-msft commented on GitHub (Nov 1, 2023):

Alrighty so very brief overview of the problem: When we switch back to the old screen buffer, conpty doesn't know what to do with that. Should conpty force the old buffer to the second buffer's size? (probably). Should it send a "hey I was resized message" to whatever the terminal is? (another good option, though that'll run afoul of #5094 quickly).

I'd reckon it should probably do the same thing the alt buffer does - resize the buffer to the current size as we do the swap.

@zadjii-msft commented on GitHub (Nov 1, 2023): Alrighty so very brief overview of the problem: When we switch back to the old screen buffer, conpty doesn't know what to do with that. Should conpty force the old buffer to the second buffer's size? (probably). Should it send a "hey I was resized message" to whatever the terminal is? (another good option, though that'll run afoul of #5094 quickly). I'd reckon it should probably do the same thing the alt buffer does - resize the buffer to the current size as we do the swap.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#20734