blessings icon indicating copy to clipboard operation
blessings copied to clipboard

Reporting cursors current location

Open jhrf opened this issue 10 years ago • 4 comments

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?

jhrf avatar Jul 16 '14 13:07 jhrf

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.

jquast avatar Aug 20 '14 17:08 jquast

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

thomasballinger avatar Dec 03 '14 02:12 thomasballinger

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

jquast avatar Apr 08 '15 00:04 jquast

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

jquast avatar Feb 02 '20 04:02 jquast