Skip to content

Conversation

@kmvanbrunt
Copy link
Member

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.

kmvanbrunt and others added 30 commits March 17, 2018 14:33
@tleonhardt
Copy link
Member

@kmvanbrunt Hey Kevin, nice job fixing the problems with gnureadline!

Copy link
Member

@tleonhardt tleonhardt left a 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)
Copy link
Member

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
Copy link
Member

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)
Copy link
Member

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
Copy link
Member

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):
Copy link
Member

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
Copy link
Member

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:
Copy link
Member

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']
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice comments throughout!

@tleonhardt tleonhardt added this to the 0.8.3 milestone Mar 27, 2018
@python-cmd2 python-cmd2 deleted a comment from kmvanbrunt Mar 27, 2018
tleonhardt
tleonhardt previously approved these changes Mar 28, 2018
# 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'],
Copy link
Member

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.

@tleonhardt
Copy link
Member

@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 ;-)

@kmvanbrunt kmvanbrunt merged commit 8520938 into master Mar 30, 2018
@kmvanbrunt kmvanbrunt deleted the new_quoted_completion branch March 30, 2018 02:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants