You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[System.Console]::SetWindowPosition() fails to set cursor position #9018
.NET console class method "SetWindowPosition" fails to execute. In regular Powershell console, following command was used to scroll to top of the window (As an alternative to cls/Clear-Host, so buffer was not cleared only scrolled up). Confirmed it is still working there but in Terminal it fails with following error:
MethodInvocationException: Exception calling "SetWindowPosition" with "2" argument(s): "The window position must be set such that the current window size fits within the console's buffer, and the numbers must not be negative. (Parameter 'top')
Actual value was 2."
Using any other value than (0,0) causes this to fail. [System.Console]::SetWindowPosition(0,0) does succeed but does not scroll to top of the window as it does in regular powershell console.
P.S: This might not be a Terminal issue but would love to get it resolved.
and Thank you team for all the love you pour into Terminal, its easily my most used and most loved software on Windows along with PowerShell itself. Cheers
Activity
ghost added
Needs-TriageIt's a new issue that the core contributor team needs to triage at the next triage meeting
So this one is weird. You can't set the Terminal's buffer viewport with SetWindowPosition, because technically there's another buffer that's sitting between powershell and the Terminal. We call this buffer "conpty". The conpty buffer is exactly the size of the viewport, which is more like how other terminal applications (on other platforms behave). So when you try to set the viewport's top to 2, conpty rejects that API call, because the viewport can only even be at the top of the buffer. It's always at top=0.
Like 237dmitry mentioned, you can use \x1b[2J to clear the "scrollback", the text above the viewport, and \x1b[H to move the cursor to 0,0. These are escape sequences, and we've got a big ol' list of the ones we support here. There's also a lot more details on using escape sequences instead of API calls in this doc.
Activity
237dmitry commentedon Feb 8, 2021
"Ctrl+L"
237dmitry commentedon Feb 8, 2021
You can use esc-sequences as well.
nebula-it commentedon Feb 9, 2021
This is perfect, thanks 237dmitry. Just out of curiosity, is this documented somewhere?
237dmitry commentedon Feb 9, 2021
You can see here. Not of all working in Windows Terminal but this is problem of all terminals
zadjii-msft commentedon Feb 23, 2021
So this one is weird. You can't set the Terminal's buffer viewport with
SetWindowPosition, because technically there's another buffer that's sitting between powershell and the Terminal. We call this buffer "conpty". The conpty buffer is exactly the size of the viewport, which is more like how other terminal applications (on other platforms behave). So when you try to set the viewport's top to2, conpty rejects that API call, because the viewport can only even be at the top of the buffer. It's always at top=0.Like 237dmitry mentioned, you can use
\x1b[2Jto clear the "scrollback", the text above the viewport, and\x1b[Hto move the cursor to 0,0. These are escape sequences, and we've got a big ol' list of the ones we support here. There's also a lot more details on using escape sequences instead of API calls in this doc.