tartley / colorama

Simple cross-platform colored terminal text in Python
BSD 3-Clause "New" or "Revised" License
3.51k stars 249 forks source link

GetConsoleScreenBufferInfo().dwCursorPosition problem with cursor movement #356

Closed tartley closed 1 year ago

tartley commented 1 year ago

Reported by the fabulous @LqdBcnAtWork in https://github.com/tartley/colorama/pull/352:

colorama.win32.GetConsoleScreenBufferInfo().dwCursorPosition is unreliable when used immediately after Cursor movement codes:

The following code has shown the issue and is repeatable for me:

from time import sleep
from colorama import Cursor
import colorama

colorama.just_fix_windows_console()

space = 10

print(1)
print("\n"*space,Cursor.UP(space),end="\r",sep="") # run with end="" and end="\r"
sleep(1) # take note of where the cursor is while 'sleeping'
pos = colorama.win32.GetConsoleScreenBufferInfo().dwCursorPosition
print(2)
print("pos:",pos.Y)

By having end="" the Y position is calculated while not respecting the movement done by Cursor.UP, however having something print after the reposition fixes the issue.

tartley commented 1 year ago

njsmith replied in that thread: Huh, weird. Sounds like this is a quirk on Microsoft's end, so not much we can do about it, but useful to know.

So I'm filing this as a (closed) issue, then at least people can find it in searches in case it comes up.