Console.SetCursorPosition does not work properly on windows terminal.
On windows terminal, SetCursorPosition sets the cursor relevant to where the console is scrolled to.
On console host this behaviour does not happen.
I want to disable this behaviour or find a workaround for windows terminal that lets me use SetCursorPosition to change the console position freely.
I have also tried using an ANSI escape sequence, this does not seem to work either.
11 Replies
\x1b[2J
thats the ansi escape sequence for clearing the terminal
can you tell me how i use that?
does that fix the relative thing
it's not really clear from your description what works, what doesn't, and what you expect
in conhost, there is a hard limit of 9000 lines and each line you print goes 0 1 2 3 4 5 whatever and so on
windows terminal is different, line 0 is always the top line that is visible
but that means that if i call setcursorposition(0, 15) for example on conhost it will go to the 15th line that was printed which might scroll up hundreds of lines but on windows terminal it will go to the 15th line relative from the first visible line on the screen
i want to revert the behaviour back to the original one, or find a way to go to an exact position instead of a relative one
Normally SetCursorPosition(x, y) should work
works on conhost, doesnt work on windows terminal / has the unwanted behaviour of moving relative instead of absolute
could try sending CHA+VPA sequence
they are documented at https://github.com/MicrosoftDocs/Console-Docs/blob/main/docs/console-virtual-terminal-sequences.md
GitHub
Console-Docs/docs/console-virtual-terminal-sequences.md at main · M...
Windows Console Docs Repo. Contribute to MicrosoftDocs/Console-Docs development by creating an account on GitHub.
Doesn't work, but I think I'm doing it wrong because it also fails on conhost.
This is the original code
And this is what I tried changing it to
yeah, no idea if you can make terminal scroll to behave like conhost
Console.SetBufferSize
fixes it but it breaks again if the window is resized
but it also has the side affect of malforming data when the setcursorposition is called
so not a good solution