Skip to content
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

Reporting cursors current location #65

Open
jhrf opened this issue Jul 16, 2014 · 4 comments
Open

Reporting cursors current location #65

jhrf opened this issue Jul 16, 2014 · 4 comments

Comments

@jhrf
Copy link

jhrf commented Jul 16, 2014

Hello,

I love blessings. It's super convenient. Many many thanks. I just have a small suggestion.

It would be great if you could report the current cursor position so that one could create "position dependant" outputting.

I see this as being possible within the current paradigm if I could just access where my cursor was relative to the width and height. This stems from the fact that sometimes (height-1) isn't what I need. Sometimes (curpos + 1) is where I need to print (particularly if the user invokes my program without filling up a whole terminal screen yet.

Would this be possible? Pardon me if there is already a way of doing this.

Kind Regards,

Henry

EDIT: Looking at the source code, might this have something to do with accurate reporting of the Terminal.restore or Terminal.save variables?

@jquast
Copy link
Collaborator

jquast commented Aug 20, 2014

you can always use relative, term.down, term.up etc. For example, term.move_x(0).

but yes, it is possible to query the terminal emulator to report its current position -- however this would require blessings to capture and parse "keyboard input", which it does not currently do. I'll consider such feature for my fork, and I've discussed the ability previously in issue #4 which this may be a duplicate of.

In summary, for vt100-derived terminals, write '\x1b[6n' and expect return pattern r"[(\d+);(\d+)R" from stdin. For sun, '\x1b[18t' and r"[8;(\d+);(\d+)t". see: xresize.c from X11.org -- xresize works by moving the cursor to position 999,999, then query the current cursor position -- its return value is the bounds of the window (height, width).

Problem is that it is slow, blocking, and could time out, and won't work for win32's cmd.exe.

But it works.

@thomasballinger
Copy link

Work could proceed on this, just assume Blessed has cursor query by using https://github.com/thomasballinger/blessings/tree/cursor-query

@jquast
Copy link
Collaborator

jquast commented Apr 8, 2015

@thomasballinger and I hope to contribute this upstream once 'blessed-integration' is merged (we require polling for "keyboard input")

@jquast jquast mentioned this issue Jan 17, 2020
@jquast
Copy link
Collaborator

jquast commented Feb 2, 2020

get_location() is released in blessed, which is API-compatible with blessings, https://blessed.readthedocs.io/en/latest/location.html#finding-the-cursor

sbraz pushed a commit to sbraz/blessed that referenced this issue Apr 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants