diff options
author | Christophe Vu-Brugier <cvubrugier@yahoo.fr> | 2013-10-12 15:06:36 +0200 |
---|---|---|
committer | Christophe Vu-Brugier <cvubrugier@yahoo.fr> | 2013-10-12 15:35:18 +0200 |
commit | 7355da783e3c91ba01fd346b9ac731da103a63de (patch) | |
tree | ef9ffe92a3d73d63f768274e5b60300b49a92662 | |
parent | 451a5260f37b07dbdb91ce3ce96c2912c23ea065 (diff) | |
download | configshell-fb-7355da783e3c91ba01fd346b9ac731da103a63de.tar.gz |
Remove the readline completion hook fallback used with Python < 2.6
Signed-off-by: Christophe Vu-Brugier <cvubrugier@yahoo.fr>
-rw-r--r-- | configshell/shell.py | 40 |
1 files changed, 3 insertions, 37 deletions
diff --git a/configshell/shell.py b/configshell/shell.py index 050f17f..2e5edad 100644 --- a/configshell/shell.py +++ b/configshell/shell.py @@ -125,6 +125,8 @@ class ConfigShell(object): if tty: readline.set_completer_delims('\t\n ~!#$^&()[{]}\|;\'",?') + readline.set_completion_display_matches_hook( + self._display_completions_python) self.log = log.Log() @@ -175,44 +177,10 @@ class ConfigShell(object): # Private methods - def _set_readline_display_matches(self): - ''' - In order to stay compatible with python versions < 2.6, - we are not using readline.set_completion_display_matches_hook() but - instead use ctypes there to bind to the C readline hook if needed. - This hooks a callback function to display readline completions. - ''' - if 'set_completion_display_matches_hook' in dir(readline): - readline.set_completion_display_matches_hook( - self._display_completions_python) - else: - from ctypes import cdll, CFUNCTYPE, POINTER - from ctypes import c_char_p, c_int, c_void_p, cast - libreadline = None - try: - libreadline = cdll.LoadLibrary('libreadline.so') - except OSError: - try: - libreadline = cdll.LoadLibrary('libreadline.so.5') - except OSError: - try: - libreadline = cdll.LoadLibrary('libreadline.so.6') - except OSError: - self.log.critical( - "Could not find readline shared library.") - if libreadline: - completion_func_type = \ - CFUNCTYPE(None, POINTER(c_char_p), c_int, c_int) - hook = completion_func_type(self._display_completions) - ptr = c_void_p.in_dll(libreadline, - 'rl_completion_display_matches_hook') - ptr.value = cast(hook, c_void_p).value - def _display_completions_python(self, substitution, matches, max_length): ''' - A wrapper to be used with python>=2.6 readline display completion hook. + Display completion hook for readline ''' - self.log.debug("Using python >=2.6 readline display hook.") matches = [substitution] + matches self._display_completions(matches, len(matches)-1, max_length) @@ -671,8 +639,6 @@ class ConfigShell(object): @returns: The next possible completion for text. @rtype: str ''' - self._set_readline_display_matches() - if state == 0: cmdline = readline.get_line_buffer() self._current_completions = [] |