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

SetConsoleScreenBufferInfoEx isn't working well on Window Terminal. #14568

Closed
BDisp opened this issue Dec 15, 2022 · 4 comments
Closed

SetConsoleScreenBufferInfoEx isn't working well on Window Terminal. #14568

BDisp opened this issue Dec 15, 2022 · 4 comments
Labels
Issue-Bug It either shouldn't be doing this or needs an investigation. Resolution-Duplicate There's another issue on the tracker that's pretty much the same thing.

Comments

@BDisp
Copy link

BDisp commented Dec 15, 2022

Windows Terminal version

1.15.3466.0

Windows build number

10.0.22621.963

Other Software

No response

Steps to reproduce

Please try to run this code:

#include <windows.h>
#include <stdio.h>

int main(void)
{
	HANDLE hStdout;
	CONSOLE_SCREEN_BUFFER_INFOEX csbiInfoEx{ 0 };
	csbiInfoEx.cbSize = sizeof(csbiInfoEx);
	SMALL_RECT winRect, srctScrollRect, srctClipRect;
	CHAR_INFO chiFill;
	COORD coordDest;
	COORD size = COORD{ 80, 25 };
	int i;

	printf("\nPrinting 20 lines for reference. ");
	printf("Notice that line 6 is discarded during scrolling.\n");
	for (i = 0; i <= 20; i++)
		printf("%d\n", i);

	hStdout = GetStdHandle(STD_OUTPUT_HANDLE);

	if (hStdout == INVALID_HANDLE_VALUE)
	{
		printf("GetStdHandle failed with %d\n", GetLastError());
		return 1;
	}

	// Get the screen buffer size. 

	if (!GetConsoleScreenBufferInfoEx(hStdout, &csbiInfoEx))
	{
		printf("GetConsoleScreenBufferInfoEx failed %d\n", GetLastError());
		return 1;
	}

	// Set the screen buffer size. 

	csbiInfoEx.dwSize = size;
	csbiInfoEx.srWindow = SMALL_RECT{ 0,0,size.X,size.Y };
	csbiInfoEx.dwMaximumWindowSize = size;

	if (!SetConsoleScreenBufferInfoEx(hStdout, &csbiInfoEx))
	{
		printf("SetConsoleScreenBufferInfoEx failed %d\n", GetLastError());
		return 1;
	}

	// Set the screen size. 

	winRect = { 0,0,(short)(size.X - 1),(short)(size.Y - 1) };

	if (!SetConsoleWindowInfo(hStdout, true, &winRect))
	{
		printf("SetConsoleWindowInfo failed %d\n", GetLastError());
		return 1;
	}

	// The scrolling rectangle is the bottom 15 rows of the 
	// screen buffer. 

	srctScrollRect.Top = csbiInfoEx.dwSize.Y - 16;
	srctScrollRect.Bottom = csbiInfoEx.dwSize.Y - 1;
	srctScrollRect.Left = 0;
	srctScrollRect.Right = csbiInfoEx.dwSize.X - 1;

	// The destination for the scroll rectangle is one row up. 

	coordDest.X = 0;
	coordDest.Y = csbiInfoEx.dwSize.Y - 17;

	// The clipping rectangle is the same as the scrolling rectangle. 
	// The destination row is left unchanged. 

	srctClipRect = srctScrollRect;

	// Fill the bottom row with green blanks. 

	chiFill.Attributes = BACKGROUND_GREEN | FOREGROUND_RED;
	chiFill.Char.UnicodeChar = ' ';

	// Scroll up one line. 

	if (!ScrollConsoleScreenBuffer(
		hStdout,         // screen buffer handle 
		&srctScrollRect, // scrolling rectangle 
		&srctClipRect,   // clipping rectangle 
		coordDest,       // top left destination cell 
		&chiFill))       // fill character and color
	{
		printf("ScrollConsoleScreenBuffer failed %d\n", GetLastError());
		return 1;
	}

	(void)getchar(); //Explicitly ignore return value.

	return 0;
}

Expected Behavior

With Windows Console Host I get the right size:

imagem

Actual Behavior

With Windows Terminal I don't get the right size screen as expected. See the point missing after the word scrolling.
Look at the green blanks filled at the bottom which occupies all the incorrect console size.
If I'm doing something wrong, please let me know. Thanks.

imagem

@BDisp BDisp 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 Dec 15, 2022
@j4james
Copy link
Collaborator

j4james commented Dec 15, 2022

I think the only issue here is that we don't support screen size changes in Windows Terminal. If I remember correctly, the SetConsoleScreenBufferInfoEx call will change the size on the conhost side of the conpty connection, but that change isn't passed on to the conpty client. As a result, the two get out of sync and things can get weird. This problem is tracked in issue #5094.

@BDisp
Copy link
Author

BDisp commented Dec 15, 2022

Thanks for your response @j4james. Do you prefer I close this issue and use the tracked one?

@zadjii-msft
Copy link
Member

Yea, that's probably easiest, thanks!

/dup #5094

@zadjii-msft zadjii-msft closed this as not planned Won't fix, can't repro, duplicate, stale Dec 15, 2022
@ghost
Copy link

ghost commented Dec 15, 2022

Hi! We've identified this issue as a duplicate of another one that already exists on this Issue Tracker. This specific instance is being closed in favor of tracking the concern over on the referenced thread. Thanks for your report!

@ghost ghost closed this as completed Dec 15, 2022
@ghost ghost added Resolution-Duplicate There's another issue on the tracker that's pretty much the same thing. and removed Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting labels Dec 15, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Bug It either shouldn't be doing this or needs an investigation. Resolution-Duplicate There's another issue on the tracker that's pretty much the same thing.
Projects
None yet
Development

No branches or pull requests

3 participants