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
Console.getCursorPosition() synchronously writes ANSI 6h and reads the position. The underlying assumption is that there is no other interfering character while you perform Console.getCursorPosition().
But the exception above is caused because there is 's' character in the buffer when the callback is invoked for 'a' key. It is a race condition because the exception won't happen if you type 's' slightly slower than 'a'.
The cause is clear, but I am not sure how to fix this. If you just skip 's' in the buffer and perform Console.getCursorPosition(), the exception will disappear but 's' will be lost too. Once you read 's', there is no way to put it back at the front of the buffer.
I think the fundamental problem lies in that the API of console package mixes both synchronous and asynchronous API in a non-compatible way. It seems we can't reliably use synchronous APIs like Console.getCursorPosition() under the asynchronous key callback because "mixing synchronous and asynchronous reads is undefined".
Any suggestion?
The text was updated successfully, but these errors were encountered:
The following program throws a FormatException when you press 'a' with another key simultaneously (e.g., press and 'a' and 's' at the same time).
Console.getCursorPosition()
synchronously writes ANSI6h
and reads the position. The underlying assumption is that there is no other interfering character while you performConsole.getCursorPosition()
.But the exception above is caused because there is 's' character in the buffer when the callback is invoked for 'a' key. It is a race condition because the exception won't happen if you type 's' slightly slower than 'a'.
The cause is clear, but I am not sure how to fix this. If you just skip 's' in the buffer and perform
Console.getCursorPosition()
, the exception will disappear but 's' will be lost too. Once you read 's', there is no way to put it back at the front of the buffer.I think the fundamental problem lies in that the API of
console
package mixes both synchronous and asynchronous API in a non-compatible way. It seems we can't reliably use synchronous APIs likeConsole.getCursorPosition()
under the asynchronous key callback because "mixing synchronous and asynchronous reads is undefined".Any suggestion?
The text was updated successfully, but these errors were encountered: