-
Notifications
You must be signed in to change notification settings - Fork 124
New quoted completion #329
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
Conversation
…quoted_completion
|
@kmvanbrunt Hey Kevin, nice job fixing the problems with gnureadline! |
tleonhardt
left a comment
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.
WOW! You put a tremendous amount of work into improving tab-completion in this PR!! Thanks for your diligent work Kevin.
Fix the unit tests on Python 2.7 due to lack of an enum module in Python 2.7. Then I think this looks good, though I will do some more manual testing before we merge this.
| @@ -1,3 +1,22 @@ | |||
| ## 0.8.3 (TBD) | |||
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 updating the CHANGELOG. If you want, there is probably enough in this PR to constitute a release in and of itself.
|
|
||
| # Make sure you have an "import functools" somewhere at the top | ||
| complete_foo = functools.partial(path_complete) | ||
| complete_foo = self.path_complete |
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.
If path_complete() is now a method within cmd2.Cmd again, please make sure you grep through the examples and update all relevant ones including python_scripting.py and paged_output.py.
|
|
||
| # Make sure you have an "import functools" somewhere at the top | ||
| complete_bar = functools.partial(path_complete, dir_only=True) | ||
| complete_bar = functools.partialmethod(cmd2.Cmd.path_complete, dir_only=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.
Should there be some kind of comment regarding partialmethod existing for Python 3 only?
cmd2.py
Outdated
| import traceback | ||
| import unittest | ||
| from code import InteractiveConsole | ||
| from enum import Enum |
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.
The enum module was added in Python 3.4. For Python 2.7, we either need to not use enum or add a conditional dependency on the enum34 backport like so:
try:
from enum34 import Enum
except ImportError:
from enum import Enum|
|
||
|
|
||
| # Tells what implementation of readline we are using | ||
| class RlType(Enum): |
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.
Need to make some sort of change so that this works on Python 2.7. See the comment above in the imports regarding the enum module.
cmd2.py
Outdated
| if self.allow_appended_space and endidx == len(line): | ||
| str_to_append += ' ' | ||
|
|
||
| self.completion_matches[0] = self.completion_matches[0] + str_to_append |
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.
Recommend using +=
cmd2.py
Outdated
| else: | ||
| readline_lib_path = '' | ||
|
|
||
| if 'gnureadline' in sys.modules: |
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.
Good work on figuring out how to dynamically find the library path.
| self.exclude_from_help = ['do_eof', 'do_eos', 'do__relative_load'] | ||
| self.excludeFromHistory = '''history edit eof eos'''.split() | ||
| # Commands to exclude from the help menu and tab completion | ||
| self.hidden_commands = ['eof', 'eos', '_relative_load'] |
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.
I like how you just provide the command name now and don't need to include the do_*
| :param begidx: int - the beginning index of the prefix text | ||
| :param endidx: int - the ending index of the prefix text | ||
| :return: A 2 item tuple where the items are | ||
| On Success |
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.
Nice comments throughout!
| # Python 3.4 and earlier require contextlib2 for temporarily redirecting stderr and stdout | ||
| ":python_version<'3.5'": ['contextlib2'], | ||
| # Python 3.3 and earlier require enum34 backport of enum module from Python 3.4 | ||
| ":python_version<'3.4'": ['enum34'], |
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.
I added a conditional dependency on the enum34 module for Python 2.7. This change here (and the associated one in the tox.ini file should fix the unit test failures on Python 2.7.
|
@kmvanbrunt The unit tests are all passing now. Let me know when you are happy with this PR and I will do some more manual testing before merging it in. If you want to increase code coverage that would be great. But you have already put a tremendous amount of work into this PR, so we should probably wrap it up soonish and let you take a well deserved rest ;-) |
Tab completing tokens with spaces now works.
If a completion has a space and no opening quote, then an opening quote will be written to the screen.
Closing quotes are added if completion type allows it.
Added more interaction with the readline library that Python wrapper does not offer.
Added tab completion after redirection strings (|, >, >>, <) for every command.
Moved all tab completion functions into the cmd2 class since they now depend on allow_redirection flag.