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

GetConsoleScreenBufferInfo() returns very different terminal height in CMD vs Windows new Terminal app #357

Closed
tartley opened this issue Oct 19, 2022 · 1 comment

Comments

@tartley
Copy link
Owner

tartley commented Oct 19, 2022

Reported by the industrious LqdBcnAtWork at #352 (comment):

Another quirk with colorama.win32.GetConsoleScreenBufferInfo().

In Windows default CMD prompt, running str(colorama.win32.GetConsoleScreenBufferInfo()) yields something like:

'(9001,120,56,0,7,27,0,56,119,63,120)'

Those first two numbers are the terminal height (including all scrollback) and width. However calling the same function in the fancy new Terminal app for win10, gives a very different result:

'(52,209,51,0,7,0,0,51,208,52,209)'.

The terminal height is much smaller. It is just actual visible space for text, no matter how much you can scroll back by.

Now this is an issue because the CMD reports the cursor position from it's zero, while the Terminal reports the cursor position within the screen, but both translate the ANSI calls to be relative to the screen.

Example scenario

So, for example, in my scenario, I have a function that'll print n lines, move back up, n lines, then save the cursor position for printing/reprinting a line. This is so I can specify the amount of lines I may or may not print (but not track) before scrolling would happen. That way I can return to a line and update it's contents without worrying about having to know exactly how many lines have been printed. But I need to handle this in both CMD and the Terminal.

A workaround

Fortunately colorama.win32.GetConsoleScreenBufferInfo().srWindow.Top reports correctly for both, so I just get the Y value for the cursor, and subtract that Top value from it, and add 1. That way I always get an accurate value for the cursor's line.

Windows console, always causing issues because it's different.

@tartley
Copy link
Owner Author

tartley commented Oct 19, 2022

Including this reported quirk as an issue here, so that at least users can search for it and find the workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant