-
Notifications
You must be signed in to change notification settings - Fork 127
Autocompleter #362
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
Autocompleter #362
Changes from all commits
f29d6af
f6b6a3c
e20f7ec
874f884
8d4f841
bfc190e
c99b9a2
21454b2
bb5e358
81adb04
50c96bc
cd60899
d5d42fb
07c283e
dac2680
dadcd27
9e24c98
94da51a
de471a8
6585622
93cc246
a448192
8a5e2ff
736cdda
9452dfa
2428482
94bea93
154fa93
4918300
ff66a95
c218633
df09c85
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| # coding=utf-8 | ||
| """ | ||
| Imports the proper readline for the platform and provides utility functions for it | ||
| """ | ||
| import sys | ||
|
|
||
| try: | ||
| from enum34 import Enum | ||
| except ImportError: | ||
| from enum import Enum | ||
|
|
||
| # Prefer statically linked gnureadline if available (for macOS compatibility due to issues with libedit) | ||
| try: | ||
| import gnureadline as readline | ||
| except ImportError: | ||
| # Try to import readline, but allow failure for convenience in Windows unit testing | ||
| # Note: If this actually fails, you should install readline on Linux or Mac or pyreadline on Windows | ||
| try: | ||
| # noinspection PyUnresolvedReferences | ||
| import readline | ||
| except ImportError: # pragma: no cover | ||
| pass | ||
|
|
||
|
|
||
| class RlType(Enum): | ||
| """Readline library types we recognize""" | ||
| GNU = 1 | ||
| PYREADLINE = 2 | ||
| NONE = 3 | ||
|
|
||
|
|
||
| # Check what implementation of readline we are using | ||
|
|
||
| rl_type = RlType.NONE | ||
|
|
||
| # The order of this check matters since importing pyreadline will also show readline in the modules list | ||
| if 'pyreadline' in sys.modules: | ||
| rl_type = RlType.PYREADLINE | ||
|
|
||
| elif 'gnureadline' in sys.modules or 'readline' in sys.modules: | ||
| rl_type = RlType.GNU | ||
|
|
||
| # Load the readline lib so we can access members of it | ||
| import ctypes | ||
| readline_lib = ctypes.CDLL(readline.__file__) | ||
|
|
||
|
|
||
| def rl_force_redisplay() -> None: | ||
| """ | ||
| Causes readline to redraw prompt and input line | ||
| """ | ||
| if not sys.stdout.isatty(): | ||
| return | ||
|
|
||
| if rl_type == RlType.GNU: # pragma: no cover | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is covered on macOS when the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reason I blocked this out is because it can't be covered by the automated tests because there's isn't a terminal.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess it depends on where we care about seeing the coverage.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh good point. I think it is reasonable to block it out if we know it won't be hit by any of our CI systems. |
||
| # rl_forced_update_display() is the proper way to redraw the prompt and line, but we | ||
| # have to use ctypes to do it since Python's readline API does not wrap the function | ||
| readline_lib.rl_forced_update_display() | ||
|
|
||
| # After manually updating the display, readline asks that rl_display_fixed be set to 1 for efficiency | ||
| display_fixed = ctypes.c_int.in_dll(readline_lib, "rl_display_fixed") | ||
| display_fixed.value = 1 | ||
|
|
||
| elif rl_type == RlType.PYREADLINE: # pragma: no cover | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is covered on Windows when the |
||
| # noinspection PyProtectedMember | ||
| readline.rl.mode._print_prompt() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| pyparsing | ||
| pyperclip | ||
| wcwidth | ||
| colorama | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for adding this. We need to keep this up-to-date so that the documentation builds correctly on ReadTheDocs |
||
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.
Thanks for fixing the code coverage analysis configuration now that
cmd2is a multi-file package