Skip to content

Console.CursorTop always zero when stdin redirected on linux #57347

Answered by stephentoub
lejsekt asked this question in Q&A
Discussion options

You must be logged in to vote

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.

// Getting the cursor position involves both writing out a request string and
// parsing a response string from the terminal. So if anything is redirected, bail.
if (Console.IsInputRedirected || Console.IsOutputRedirected)
{
return false;
}

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@lejsekt
Comment options

@stephentoub
Comment options

Answer selected by lejsekt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants