From 220e2782f6be332d8479cfe104e98b0679f94c4e Mon Sep 17 00:00:00 2001 From: Anthony Scopatz Date: Sat, 4 Feb 2017 22:58:23 -0500 Subject: [PATCH 1/3] completions updating implementation --- news/compup.rst | 15 +++++++++++++++ xonsh/environ.py | 21 ++++++++++++++------- xonsh/ptk/shell.py | 4 ++++ 3 files changed, 33 insertions(+), 7 deletions(-) create mode 100644 news/compup.rst diff --git a/news/compup.rst b/news/compup.rst new file mode 100644 index 000000000..af68fbb0d --- /dev/null +++ b/news/compup.rst @@ -0,0 +1,15 @@ +**Added:** + +* New ``$UPDATE_COMPLETIONS_ON_KEYPRESS`` controls whether or not completions + will automatically display and update while typing. This feature is only + available in the prompt-toolkit shell. + +**Changed:** None + +**Deprecated:** None + +**Removed:** None + +**Fixed:** None + +**Security:** None diff --git a/xonsh/environ.py b/xonsh/environ.py index 3d2d341d7..b33456854 100644 --- a/xonsh/environ.py +++ b/xonsh/environ.py @@ -162,7 +162,9 @@ def DEFAULT_ENSURERS(): 'BOTTOM_TOOLBAR': (is_string_or_callable, ensure_string, ensure_string), 'SUBSEQUENCE_PATH_COMPLETION': (is_bool, to_bool, bool_to_str), 'SUPPRESS_BRANCH_TIMEOUT_MESSAGE': (is_bool, to_bool, bool_to_str), + 'UPDATE_COMPLETIONS_ON_KEYPRESS': (is_bool, to_bool, bool_to_str), 'UPDATE_OS_ENVIRON': (is_bool, to_bool, bool_to_str), + 'UPDATE_PROMPT_ON_KEYPRESS': (is_bool, to_bool, bool_to_str), 'VC_BRANCH_TIMEOUT': (is_float, float, str), 'VC_HG_SHOW_BRANCH': (is_bool, to_bool, bool_to_str), 'VI_MODE': (is_bool, to_bool, bool_to_str), @@ -188,7 +190,6 @@ def DEFAULT_ENSURERS(): 'XONSH_STORE_STDIN': (is_bool, to_bool, bool_to_str), 'XONSH_TRACEBACK_LOGFILE': (is_logfile_opt, to_logfile_opt, logfile_opt_to_str), 'XONSH_DATETIME_FORMAT': (is_string, ensure_string, ensure_string), - 'UPDATE_PROMPT_ON_KEYPRESS': (is_bool, to_bool, bool_to_str), } @@ -305,7 +306,9 @@ def DEFAULT_VALUES(): 'SUGGEST_MAX_NUM': 5, 'SUGGEST_THRESHOLD': 3, 'TITLE': DEFAULT_TITLE, + 'UPDATE_COMPLETIONS_ON_KEYPRESS': False, 'UPDATE_OS_ENVIRON': False, + 'UPDATE_PROMPT_ON_KEYPRESS': False, 'VC_BRANCH_TIMEOUT': 0.2 if ON_WINDOWS else 0.1, 'VC_HG_SHOW_BRANCH': True, 'VI_MODE': False, @@ -336,7 +339,6 @@ def DEFAULT_VALUES(): 'XONSH_STORE_STDOUT': False, 'XONSH_TRACEBACK_LOGFILE': None, 'XONSH_DATETIME_FORMAT': '%Y-%m-%d %H:%M', - 'UPDATE_PROMPT_ON_KEYPRESS': False, } if hasattr(locale, 'LC_MESSAGES'): dv['LC_MESSAGES'] = locale.setlocale(locale.LC_MESSAGES) @@ -424,7 +426,7 @@ def DEFAULT_DOCS(): "- If ``$COMPLETIONS_DISPLAY`` is ``multi`` or ``true``, display completions\n" " in multiple columns while typing.\n\n" 'These option values are not case- or type-sensitive, so e.g.' - "writing ``$COMPLETIONS_DISPLAY = None``" + "writing ``$COMPLETIONS_DISPLAY = None`` " "and ``$COMPLETIONS_DISPLAY = 'none'`` are equivalent. Only usable with " "``$SHELL_TYPE=prompt_toolkit``"), 'COMPLETIONS_CONFIRM': VarDocs( @@ -591,10 +593,19 @@ def DEFAULT_DOCS(): "in the same manner as ``$PROMPT``, see 'Customizing the Prompt' " 'http://xon.sh/tutorial.html#customizing-the-prompt.', default='``xonsh.environ.DEFAULT_TITLE``'), + 'UPDATE_COMPLETIONS_ON_KEYPRESS': VarDocs( + 'Completions display is evaluated and presented whenever a key is ' + 'pressed. This avoids the need to press TAB, except to cycle through ' + 'the possibilities. This currently only affects the prompt-toolkit shell.' + ), 'UPDATE_OS_ENVIRON': VarDocs( "If True ``os.environ`` will always be updated " "when the xonsh environment changes. The environment can be reset to " "the default value by calling ``__xonsh_env__.undo_replace_env()``"), + 'UPDATE_PROMPT_ON_KEYPRESS': VarDocs( + 'Disables caching the prompt between commands, ' + 'so that it would be reevaluated on each keypress. ' + 'Disabled by default because of the incurred performance penalty.'), 'VC_BRANCH_TIMEOUT': VarDocs( 'The timeout (in seconds) for version control ' 'branch computations. This is a timeout per subprocess call, so the ' @@ -738,10 +749,6 @@ def DEFAULT_DOCS(): 'XONSH_DATETIME_FORMAT': VarDocs( 'The format that is used for ``datetime.strptime()`` in various places' 'i.e the history timestamp option'), - 'UPDATE_PROMPT_ON_KEYPRESS': VarDocs( - 'Disables caching the prompt between commands, ' - 'so that it would be reevaluated on each keypress. ' - 'Disabled by default because of the incurred performance penalty.'), } diff --git a/xonsh/ptk/shell.py b/xonsh/ptk/shell.py index 2692fd8d6..2f5e7192c 100644 --- a/xonsh/ptk/shell.py +++ b/xonsh/ptk/shell.py @@ -70,6 +70,9 @@ class PromptToolkitShell(BaseShell): auto_suggest = auto_suggest if env.get('AUTO_SUGGEST') else None completions_display = env.get('COMPLETIONS_DISPLAY') multicolumn = (completions_display == 'multi') + complete_while_typing = env.get('UPDATE_COMPLETIONS_ON_KEYPRESS') + if complete_while_typing: + enable_history_search = False if HAS_PYGMENTS: self.styler.style_name = env.get('XONSH_COLOR_STYLE') completer = None if completions_display == 'none' else self.pt_completer @@ -100,6 +103,7 @@ class PromptToolkitShell(BaseShell): 'reserve_space_for_menu': 0, 'key_bindings_registry': self.key_bindings_manager.registry, 'display_completions_in_columns': multicolumn, + 'complete_while_typing': complete_while_typing, } if builtins.__xonsh_env__.get('COLOR_INPUT'): if HAS_PYGMENTS: From 011b36aa991da6caff08035d3eec0c4a988ef938 Mon Sep 17 00:00:00 2001 From: Anthony Scopatz Date: Thu, 9 Feb 2017 00:10:32 -0500 Subject: [PATCH 2/3] now the keypress completere is working --- xonsh/ptk/completer.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/xonsh/ptk/completer.py b/xonsh/ptk/completer.py index 126bcf0dd..3a2d02780 100644 --- a/xonsh/ptk/completer.py +++ b/xonsh/ptk/completer.py @@ -20,9 +20,12 @@ class PromptToolkitCompleter(Completer): def get_completions(self, document, complete_event): """Returns a generator for list of completions.""" - + should_complete = ( + complete_event.completion_requested or + builtins.__xonsh_env__.get('UPDATE_COMPLETIONS_ON_KEYPRESS') + ) # Only generate completions when the user hits tab. - if complete_event.completion_requested: + if should_complete: if self.completer is None: yield from [] else: From 41896b18ccfc511bd24ebea5fbdc8381079c13f6 Mon Sep 17 00:00:00 2001 From: Anthony Scopatz Date: Thu, 9 Feb 2017 00:12:46 -0500 Subject: [PATCH 3/3] added doc --- xonsh/ptk/shell.py | 1 + 1 file changed, 1 insertion(+) diff --git a/xonsh/ptk/shell.py b/xonsh/ptk/shell.py index ad115623c..dd541f5d2 100644 --- a/xonsh/ptk/shell.py +++ b/xonsh/ptk/shell.py @@ -72,6 +72,7 @@ class PromptToolkitShell(BaseShell): multicolumn = (completions_display == 'multi') complete_while_typing = env.get('UPDATE_COMPLETIONS_ON_KEYPRESS') if complete_while_typing: + # PTK requires history search to be none when completing while typing enable_history_search = False if HAS_PYGMENTS: self.styler.style_name = env.get('XONSH_COLOR_STYLE')