Update: this problem exists for the Cygwin terminal mintty
See the latest comment
I am trying to read the terminal response on escape code queries on Windows.
The code always queries successfully on Linux but sometimes messes the terminal up (I have to type stty echo then). On Windows however the terminal answer is not caught by the program and gets written as text.
How do I read such a terminal response? What am I doing wrong here?

Update: this problem exists for the Cygwin terminal mintty
See the latest comment
I am trying to read the terminal response on escape code queries on Windows.
The code always queries successfully on Linux but sometimes messes the terminal up (I have to type
stty echothen). On Windows however the terminal answer is not caught by the program and gets written as text.How do I read such a terminal response? What am I doing wrong here?
demo code