mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-05 17:00:58 +01:00
commit
741342aeec
4 changed files with 39 additions and 9 deletions
15
news/compup.rst
Normal file
15
news/compup.rst
Normal file
|
@ -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
|
|
@ -162,7 +162,9 @@ def DEFAULT_ENSURERS():
|
||||||
'BOTTOM_TOOLBAR': (is_string_or_callable, ensure_string, ensure_string),
|
'BOTTOM_TOOLBAR': (is_string_or_callable, ensure_string, ensure_string),
|
||||||
'SUBSEQUENCE_PATH_COMPLETION': (is_bool, to_bool, bool_to_str),
|
'SUBSEQUENCE_PATH_COMPLETION': (is_bool, to_bool, bool_to_str),
|
||||||
'SUPPRESS_BRANCH_TIMEOUT_MESSAGE': (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_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_BRANCH_TIMEOUT': (is_float, float, str),
|
||||||
'VC_HG_SHOW_BRANCH': (is_bool, to_bool, bool_to_str),
|
'VC_HG_SHOW_BRANCH': (is_bool, to_bool, bool_to_str),
|
||||||
'VI_MODE': (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_STORE_STDIN': (is_bool, to_bool, bool_to_str),
|
||||||
'XONSH_TRACEBACK_LOGFILE': (is_logfile_opt, to_logfile_opt, logfile_opt_to_str),
|
'XONSH_TRACEBACK_LOGFILE': (is_logfile_opt, to_logfile_opt, logfile_opt_to_str),
|
||||||
'XONSH_DATETIME_FORMAT': (is_string, ensure_string, ensure_string),
|
'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_MAX_NUM': 5,
|
||||||
'SUGGEST_THRESHOLD': 3,
|
'SUGGEST_THRESHOLD': 3,
|
||||||
'TITLE': DEFAULT_TITLE,
|
'TITLE': DEFAULT_TITLE,
|
||||||
|
'UPDATE_COMPLETIONS_ON_KEYPRESS': False,
|
||||||
'UPDATE_OS_ENVIRON': False,
|
'UPDATE_OS_ENVIRON': False,
|
||||||
|
'UPDATE_PROMPT_ON_KEYPRESS': False,
|
||||||
'VC_BRANCH_TIMEOUT': 0.2 if ON_WINDOWS else 0.1,
|
'VC_BRANCH_TIMEOUT': 0.2 if ON_WINDOWS else 0.1,
|
||||||
'VC_HG_SHOW_BRANCH': True,
|
'VC_HG_SHOW_BRANCH': True,
|
||||||
'VI_MODE': False,
|
'VI_MODE': False,
|
||||||
|
@ -336,7 +339,6 @@ def DEFAULT_VALUES():
|
||||||
'XONSH_STORE_STDOUT': False,
|
'XONSH_STORE_STDOUT': False,
|
||||||
'XONSH_TRACEBACK_LOGFILE': None,
|
'XONSH_TRACEBACK_LOGFILE': None,
|
||||||
'XONSH_DATETIME_FORMAT': '%Y-%m-%d %H:%M',
|
'XONSH_DATETIME_FORMAT': '%Y-%m-%d %H:%M',
|
||||||
'UPDATE_PROMPT_ON_KEYPRESS': False,
|
|
||||||
}
|
}
|
||||||
if hasattr(locale, 'LC_MESSAGES'):
|
if hasattr(locale, 'LC_MESSAGES'):
|
||||||
dv['LC_MESSAGES'] = locale.setlocale(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"
|
"- If ``$COMPLETIONS_DISPLAY`` is ``multi`` or ``true``, display completions\n"
|
||||||
" in multiple columns while typing.\n\n"
|
" in multiple columns while typing.\n\n"
|
||||||
'These option values are not case- or type-sensitive, so e.g.'
|
'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 "
|
"and ``$COMPLETIONS_DISPLAY = 'none'`` are equivalent. Only usable with "
|
||||||
"``$SHELL_TYPE=prompt_toolkit``"),
|
"``$SHELL_TYPE=prompt_toolkit``"),
|
||||||
'COMPLETIONS_CONFIRM': VarDocs(
|
'COMPLETIONS_CONFIRM': VarDocs(
|
||||||
|
@ -591,10 +593,19 @@ def DEFAULT_DOCS():
|
||||||
"in the same manner as ``$PROMPT``, see 'Customizing the Prompt' "
|
"in the same manner as ``$PROMPT``, see 'Customizing the Prompt' "
|
||||||
'http://xon.sh/tutorial.html#customizing-the-prompt.',
|
'http://xon.sh/tutorial.html#customizing-the-prompt.',
|
||||||
default='``xonsh.environ.DEFAULT_TITLE``'),
|
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(
|
'UPDATE_OS_ENVIRON': VarDocs(
|
||||||
"If True ``os.environ`` will always be updated "
|
"If True ``os.environ`` will always be updated "
|
||||||
"when the xonsh environment changes. The environment can be reset to "
|
"when the xonsh environment changes. The environment can be reset to "
|
||||||
"the default value by calling ``__xonsh_env__.undo_replace_env()``"),
|
"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(
|
'VC_BRANCH_TIMEOUT': VarDocs(
|
||||||
'The timeout (in seconds) for version control '
|
'The timeout (in seconds) for version control '
|
||||||
'branch computations. This is a timeout per subprocess call, so the '
|
'branch computations. This is a timeout per subprocess call, so the '
|
||||||
|
@ -740,10 +751,6 @@ def DEFAULT_DOCS():
|
||||||
'XONSH_DATETIME_FORMAT': VarDocs(
|
'XONSH_DATETIME_FORMAT': VarDocs(
|
||||||
'The format that is used for ``datetime.strptime()`` in various places'
|
'The format that is used for ``datetime.strptime()`` in various places'
|
||||||
'i.e the history timestamp option'),
|
'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.'),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -20,9 +20,12 @@ class PromptToolkitCompleter(Completer):
|
||||||
|
|
||||||
def get_completions(self, document, complete_event):
|
def get_completions(self, document, complete_event):
|
||||||
"""Returns a generator for list of completions."""
|
"""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.
|
# Only generate completions when the user hits tab.
|
||||||
if complete_event.completion_requested:
|
if should_complete:
|
||||||
if self.completer is None:
|
if self.completer is None:
|
||||||
yield from []
|
yield from []
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -70,6 +70,10 @@ class PromptToolkitShell(BaseShell):
|
||||||
auto_suggest = auto_suggest if env.get('AUTO_SUGGEST') else None
|
auto_suggest = auto_suggest if env.get('AUTO_SUGGEST') else None
|
||||||
completions_display = env.get('COMPLETIONS_DISPLAY')
|
completions_display = env.get('COMPLETIONS_DISPLAY')
|
||||||
multicolumn = (completions_display == 'multi')
|
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:
|
if HAS_PYGMENTS:
|
||||||
self.styler.style_name = env.get('XONSH_COLOR_STYLE')
|
self.styler.style_name = env.get('XONSH_COLOR_STYLE')
|
||||||
completer = None if completions_display == 'none' else self.pt_completer
|
completer = None if completions_display == 'none' else self.pt_completer
|
||||||
|
@ -100,6 +104,7 @@ class PromptToolkitShell(BaseShell):
|
||||||
'reserve_space_for_menu': 0,
|
'reserve_space_for_menu': 0,
|
||||||
'key_bindings_registry': self.key_bindings_manager.registry,
|
'key_bindings_registry': self.key_bindings_manager.registry,
|
||||||
'display_completions_in_columns': multicolumn,
|
'display_completions_in_columns': multicolumn,
|
||||||
|
'complete_while_typing': complete_while_typing,
|
||||||
}
|
}
|
||||||
if builtins.__xonsh_env__.get('COLOR_INPUT'):
|
if builtins.__xonsh_env__.get('COLOR_INPUT'):
|
||||||
if HAS_PYGMENTS:
|
if HAS_PYGMENTS:
|
||||||
|
|
Loading…
Add table
Reference in a new issue