-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add getCursorPos() to std/terminal #22749
Conversation
550812d
to
132a47e
Compare
var oldMode: Termios | ||
discard fd.tcGetAttr(addr oldMode) | ||
fd.setRaw() | ||
stdout.write(getPos) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Documentation comment should mention that internally it writes to stdout IMHO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oof, I just realized that it doesn't behave very well if there's not a terminal in the loop (writes the request to stdout and blocks while waiting for something from stdin). It might do to warn users about that. Added a comment.
From the failing CI:
Super sophisticated test program: # test.nim
import terminal
echo getCursorPos() Placing it in the same dir as terminal.nim and running
Fixed it like so: proc getCursorPos*(): tuple [x, y: int] {.raises: [ValueError, IOError, OSError].} =
return getCursorPos(getStdHandle(STD_OUTPUT_HANDLE)) Tested on windows, works ok. |
Thanks for your hard work on this PR! Hint: mm: orc; opt: speed; options: -d:release |
This would be handy for making terminal apps which display content below the prompt (e.g.
fzf
does this).Need to test it on windows before I remove "draft" status.