Console.CursorTop always zero when stdin redirected on linux #57347
-
Hi, Program.cs of a .NET 5 console app.
I'm using Windows Terminal on Windows and run it like the following in pwsh:
For linux test env I'm using ubuntu instance in WSL2 and I publish the program as a self contained single file executable. I run it like:
The last always shows cursor top as zero. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
There's no formal API on Unix for reading the current cursor position. Instead, it works by writing a known ANSI escape sequence to stdout, to which a conforming terminal responds by providing the cursor position for reading on stdin. As such, if either stdout or stdin is redirected, we can't get the cursor position on Unix. runtime/src/libraries/System.Console/src/System/ConsolePal.Unix.cs Lines 439 to 444 in 134c25d |
Beta Was this translation helpful? Give feedback.
There's no formal API on Unix for reading the current cursor position. Instead, it works by writing a known ANSI escape sequence to stdout, to which a conforming terminal responds by providing the cursor position for reading on stdin. As such, if either stdout or stdin is redirected, we can't get the cursor position on Unix.
runtime/src/libraries/System.Console/src/System/ConsolePal.Unix.cs
Lines 439 to 444 in 134c25d