Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Active screen buffer size is out of sync #16231

Open
o-sdn-o opened this issue Oct 26, 2023 · 3 comments
Open

Active screen buffer size is out of sync #16231

o-sdn-o opened this issue Oct 26, 2023 · 3 comments
Labels
Area-Server Down in the muck of API call servicing, interprocess communication, eventing, etc. Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-2 A description (P2) Product-Conpty For console issues specifically related to conpty
Milestone

Comments

@o-sdn-o
Copy link

o-sdn-o commented 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

@o-sdn-o o-sdn-o added Issue-Bug It either shouldn't be doing this or needs an investigation. Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting labels Oct 26, 2023
@o-sdn-o o-sdn-o changed the title Resizing active additional screen buffer is broken Active additional screen buffer resize is out of sync Oct 26, 2023
@o-sdn-o o-sdn-o changed the title Active additional screen buffer resize is out of sync Active screen buffer size is out of sync Oct 26, 2023
@237dmitry
Copy link

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

@o-sdn-o
Copy link
Author

o-sdn-o commented Oct 26, 2023

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

@carlos-zamora carlos-zamora added Product-Conpty For console issues specifically related to conpty Area-Server Down in the muck of API call servicing, interprocess communication, eventing, etc. Priority-2 A description (P2) labels Nov 1, 2023
@carlos-zamora carlos-zamora added this to the Backlog milestone Nov 1, 2023
@carlos-zamora carlos-zamora removed the Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting label Nov 1, 2023
@zadjii-msft
Copy link
Member

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 up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Server Down in the muck of API call servicing, interprocess communication, eventing, etc. Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-2 A description (P2) Product-Conpty For console issues specifically related to conpty
Projects
None yet
Development

No branches or pull requests

4 participants