Save ('s') and restore ('u') support added#137
Save ('s') and restore ('u') support added#137kgeorgiy wants to merge 5 commits intotartley:masterfrom
Conversation
Existing 'get_position' method is flawed in the following ways: * Naming: its setter is 'set_cursor_position', not 'set_position' * Abstraction leak: returns internal Win32 structure * There is no way to get adjusted cursor position * Receives handle, instead of on_stderr flag
There are no more uses of get_position in the code base, so it could be deprecated, and, possibly, removed in future
wiggin15
left a comment
There was a problem hiding this comment.
Generally, this looks good. Please see my review comments
| position.Y += 1 | ||
| return position | ||
|
|
||
| def get_cursor_position(self, on_stderr=False, adjust=True): |
There was a problem hiding this comment.
I'm not sure if we need this function. We already have get_position which returns the cursor position (we can rename that function to make it clear it's about the cursor). Regarding the adjustments, we have a code for adjusting the cursor position in SetConsoleCursorPosition. We can play with its adjust parameter based on if it's needed or not when restoring with 'u', instead of having more code that deals with this adjustments.
There was a problem hiding this comment.
I'm sensitive to wiggin's criticism here which I think might be valid, but am enthusiastic about the PR overall. Assuming @kgeorgiy is not still around / motivated after 4 years, I'll take a closer look at this code tonight, and try to merge it...
Apologies for resurrecting this after ignoring it for years!
| handle = win32.STDERR | ||
| position = self.get_position(handle) | ||
| adjusted_position = (position.Y + y, position.X + x) | ||
| (cy, cx) = self.get_cursor_position(on_stderr, adjust=False) |
There was a problem hiding this comment.
If we decide to continue to use get_position instead of the new get_cursor_position, we will not need this change.
|
Hey. FYI, yesterday I created a PR to test releases before we push them to PyPI. When that is merged, I'll be more confident about resuming merges and releases. I'll try to look at this PR soon. Thank you for creating it! |
|
|
||
| @staticmethod | ||
| def get_handle(on_stderr=False): | ||
| return win32.STDERR if on_stderr else win32.STDOUT |
|
I could have used this feature right now. Anyone with privileges, please take another look. |
|
Please merge it. Reliable way to get cursor position will be very useful. |
|
Eight years late, but moving fast. Since this is on a fork's master, I'm attempting to fix merge conflicts, and address review comments, in #402 |
|
@JanSichula Although, I have to ask: If one is not on Windows, then there's no reason to use Colorama (other platforms have always understood ANSI sequences just fine, so they already handle these 's' and 'u' actions), and my understanding is that modern Windows now handles ANSI codes properly, too. So do people really still need new features adding to Colorama? If anyone wants to help me understand why, it would be appreciated. Thank you! |
Includes test and demo plus minor refactoring of ansitowin32