-
Notifications
You must be signed in to change notification settings - Fork 71
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
First take on cursor position #32
Conversation
@@ -280,6 +281,27 @@ def width(self): | |||
""" | |||
return self._height_and_width().ws_col | |||
|
|||
@property | |||
def cursor_position(self): |
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.
As much of a fan of @Property as I am, I want to use a function, get_cursor_position(), because we should indicate this is an expensive/blocking call, where-as a @property-backed attribute somewhat implies otherwise.
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.
Please provide argument timeout=5
and honor it.
Please return the (invalid) value of (0,0) if:
- self.keyboard_fd is None
- HAS_TTY is False
- or a response is not received within timeout
and document as such.
This is so that programs that use it (like the proposed bin/resize.py) may work even if stdin is not a tty.
For testing, lets port resize.c from x11.org's xterm in python in as bin/resize.py and bin/sunsize.py! I know it looks scary but ignore all the cruft, its simple:
This can then be manually tested, that it reports the same COLUMNS and LINES that your terminal emulator already has. Secondly, this will have to be "mocked", but not in the mock module sense, just in that the build agents are not terminal emulators and we will have to mock one. You see many tests around keyboard input that spawns a pty and reads its output and sends input, you'll do the same, look for the "report cursor position" sequence, send one manually into the child process, which then asserts the child's (height, width) returned is what was sent.
I don't think so, hardcoding
Don't worry about it, trust the values of term.u7 (request) and term.u6 (response)
Nope, we'll cross that moat when we get to it -- don't worry about it. |
first = 0 | ||
keystrokes = [] | ||
while True: | ||
keystrokes.append(self.inkey(_intr_continue=True)) |
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.
please conditionally check return value of keystrokes it not None, as you will be adding a timeout
parameter. Make sure to mark the start-time and compute the remaining time for each call to inkey(), You will have to use some kind of '_timeleft' function to compute remaining time like inkey() does.
Doing some research
|
This is terrific, thanks! Unfortunately I probably won't be able to work on this for about a week, but will get back to it then. |
Well there is plenty of time, now. I'd really like to dive into and help with your curtsies project (i've been watching and seeing your issues/pr's... i see what you're doing, but no comment) I'm currently focused on getting blessed merged back into blessings. The blessed project will become very little code: only "imports blessings, monkey patch the previous behavior/methods for compatibility, recommend blessings to be used instead". Erik transferred blessed code into his project as a branch we're working through some weeks ago, so in effect, "blessed" is in feature freeze. I proposed we get this specific feature in before the transfer, but erik declined it. This feature will have to be a part of some later release of blessings. I will transfer this and other tickets after the merge. As you're looking at using blessed for keyboard, you should know that I fought a tough battle over some of the api's and won some and lost some. Erik declined the (It's too bad, really I asked for his feedback almost 2 years ago on these methods and their names before blessed was born, and he didn't have any opinion to share then! I have over 267 uses of inkey currently across projects, and that's only me!) |
Also, Good luck with your pycon talk! |
Thanks for the updates, and great work on doing this merge with Eric. Thanks for the great feedback on the PR a while ago, sorry I didn't make any progress on it after you gave great specific feedback. |
self._keyboard_buf.extendleft( | ||
u''.join(keystrokes)[:m.start()]) | ||
return tuple(int(x) for x in m.groups()) | ||
|
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.
man... lot of mojo here without any test cases !
keystrokes.append(self.inkey(_intr_continue=True)) | ||
m = re.search('\x1b[[]([0-9]+);([0-9]+)R', u''.join(keystrokes)) | ||
if m: | ||
self._keyboard_buf.extendleft( |
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.
this may warrant the need for a _ungetch(ucs) method, where ucs
is characters to be pushed back into the keyboard buffer.
resuming |
This PR superseded by #72 |
This PR succeeds #32 by @thomasballinger. major -------- - **new method**, ``.get_location(timeout=None)``. - **new method**, ``.ungetch()`` which pushes data back for next ``inkey()``. - **new example** program, ``bin/resize.py``, which required such condition. - **new example** program, ``bin/detect-multibyte.py`` which uses this method. - enhancement: now possible to use stdin when stream=stderr minor -------- - method-local function, ``time_left()``, moved to ``keyboard.py`` as ``_time_left()``. - new function in keyboard.py, ``_read_until``, something like a mini-pexpect. - new private state value ``_line_buffered``, used to determine whether the terminal has already entered cbreak or raw mode. This may become public later if we also use termios routines, instead as a read-only \@Property.
This is an in-progress PR so there's something to talk about while I make progress. Things I can think of to worry about:
I'll keep working on these but would appreciate thoughts.