mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-06 09:20:57 +01:00
Merge branch 'jonathanslenders-new-features'
This commit is contained in:
commit
fdab4ed280
5 changed files with 41 additions and 22 deletions
|
@ -4,6 +4,8 @@ The following table displays information about the environment variables that
|
|||
effect XONSH performance in some way. It also lists their default values, if
|
||||
applicable.
|
||||
|
||||
.. Please keep the following in alphabetic order - scopatz
|
||||
|
||||
.. list-table::
|
||||
:widths: 1 1 3
|
||||
:header-rows: 1
|
||||
|
@ -44,6 +46,13 @@ applicable.
|
|||
* - INDENT
|
||||
- ``' '``
|
||||
- Indentation string for multiline input
|
||||
* - MOUSE_SUPPORT
|
||||
- ``False``
|
||||
- Enable mouse support in the prompt_toolkit shell. This allows clicking
|
||||
for positioning the cursor or selecting a completion. In some terminals
|
||||
however, this disables the ability to scroll back through the history
|
||||
of the terminal.
|
||||
(Only usable with SHELL_TYPE=prompt_toolkit)
|
||||
* - MULTILINE_PROMPT
|
||||
- ``'.'``
|
||||
- Prompt text for 2nd+ lines of input, may be str or function which returns
|
||||
|
|
|
@ -62,6 +62,7 @@ DEFAULT_ENSURERS = {
|
|||
'CASE_SENSITIVE_COMPLETIONS': (is_bool, to_bool, bool_to_str),
|
||||
'BASH_COMPLETIONS': (is_env_path, str_to_env_path, env_path_to_str),
|
||||
'TEEPTY_PIPE_DELAY': (is_float, float, str),
|
||||
'MOUSE_SUPPORT': (is_bool, to_bool, bool_to_str),
|
||||
}
|
||||
|
||||
#
|
||||
|
@ -75,7 +76,7 @@ def default_value(f):
|
|||
def is_callable_default(x):
|
||||
"""Checks if a value is a callable default."""
|
||||
return callable(x) and getattr(x, '_xonsh_callable_default', False)
|
||||
|
||||
|
||||
DEFAULT_PROMPT = ('{BOLD_GREEN}{user}@{hostname}{BOLD_BLUE} '
|
||||
'{cwd}{branch_color}{curr_branch} '
|
||||
'{BOLD_BLUE}${NO_COLOR} ')
|
||||
|
@ -112,7 +113,7 @@ DEFAULT_VALUES = {
|
|||
'AUTO_PUSHD': False,
|
||||
'BASH_COMPLETIONS': ('/usr/local/etc/bash_completion',
|
||||
'/opt/local/etc/profile.d/bash_completion.sh') if ON_MAC \
|
||||
else ('/etc/bash_completion',
|
||||
else ('/etc/bash_completion',
|
||||
'/usr/share/bash-completion/completions/git'),
|
||||
'CASE_SENSITIVE_COMPLETIONS': ON_LINUX,
|
||||
'CDPATH': (),
|
||||
|
@ -124,6 +125,7 @@ DEFAULT_VALUES = {
|
|||
'LC_TIME': locale.setlocale(locale.LC_TIME),
|
||||
'LC_MONETARY': locale.setlocale(locale.LC_MONETARY),
|
||||
'LC_NUMERIC': locale.setlocale(locale.LC_NUMERIC),
|
||||
'MOUSE_SUPPORT': False,
|
||||
'MULTILINE_PROMPT': '.',
|
||||
'PATH': (),
|
||||
'PATHEXT': (),
|
||||
|
@ -590,11 +592,11 @@ except AttributeError:
|
|||
pass
|
||||
|
||||
def load_static_config(ctx):
|
||||
"""Loads a static configuration file from a given context, rather than the
|
||||
"""Loads a static configuration file from a given context, rather than the
|
||||
current environment.
|
||||
"""
|
||||
env = {}
|
||||
env['XDG_CONFIG_HOME'] = ctx.get('XDG_CONFIG_HOME',
|
||||
env['XDG_CONFIG_HOME'] = ctx.get('XDG_CONFIG_HOME',
|
||||
DEFAULT_VALUES['XDG_CONFIG_HOME'])
|
||||
env['XONSH_CONFIG_DIR'] = ctx['XONSH_CONFIG_DIR'] if 'XONSH_CONFIG_DIR' in ctx \
|
||||
else xonsh_config_dir(env)
|
||||
|
@ -656,7 +658,7 @@ def default_env(env=None):
|
|||
ctx.update(os.environ)
|
||||
conf = load_static_config(ctx)
|
||||
ctx.update(conf.get('env', ()))
|
||||
ctx.update(load_foreign_envs(shells=conf.get('foreign_shells', DEFAULT_SHELLS),
|
||||
ctx.update(load_foreign_envs(shells=conf.get('foreign_shells', DEFAULT_SHELLS),
|
||||
issue_warning=False))
|
||||
if ON_WINDOWS:
|
||||
windows_env_fixes(ctx)
|
||||
|
|
|
@ -15,18 +15,21 @@ class PromptToolkitCompleter(Completer):
|
|||
|
||||
def get_completions(self, document, complete_event):
|
||||
"""Returns a generator for list of completions."""
|
||||
line = document.current_line
|
||||
endidx = document.cursor_position_col
|
||||
space_pos = document.find_backwards(' ')
|
||||
if space_pos is None:
|
||||
begidx = 0
|
||||
else:
|
||||
begidx = space_pos + endidx + 1
|
||||
prefix = line[begidx:endidx]
|
||||
completions = self.completer.complete(prefix,
|
||||
line,
|
||||
begidx,
|
||||
endidx,
|
||||
self.ctx)
|
||||
for comp in completions:
|
||||
yield Completion(comp, -len(prefix))
|
||||
|
||||
# Only generate completions when the user typed not a tab.
|
||||
if not (document.char_before_cursor or '').isspace():
|
||||
line = document.current_line
|
||||
endidx = document.cursor_position_col
|
||||
space_pos = document.find_backwards(' ')
|
||||
if space_pos is None:
|
||||
begidx = 0
|
||||
else:
|
||||
begidx = space_pos + endidx + 1
|
||||
prefix = line[begidx:endidx]
|
||||
completions = self.completer.complete(prefix,
|
||||
line,
|
||||
begidx,
|
||||
endidx,
|
||||
self.ctx)
|
||||
for comp in completions:
|
||||
yield Completion(comp, -len(prefix))
|
||||
|
|
|
@ -32,5 +32,3 @@ def load_xonsh_bindings(key_bindings_manager):
|
|||
indent instead of autocompleting.
|
||||
"""
|
||||
event.cli.current_buffer.insert_text(env.get('INDENT'))
|
||||
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ from warnings import warn
|
|||
|
||||
from prompt_toolkit.shortcuts import get_input
|
||||
from prompt_toolkit.key_binding.manager import KeyBindingManager
|
||||
from prompt_toolkit.auto_suggest import AutoSuggestFromHistory
|
||||
from pygments.token import Token
|
||||
from pygments.style import Style
|
||||
|
||||
|
@ -46,6 +47,7 @@ class PromptToolkitShell(BaseShell):
|
|||
self.history = setup_history()
|
||||
self.pt_completer = PromptToolkitCompleter(self.completer, self.ctx)
|
||||
self.key_bindings_manager = KeyBindingManager(
|
||||
enable_auto_suggest_bindings=True,
|
||||
enable_search=True, enable_abort_and_exit_bindings=True)
|
||||
load_xonsh_bindings(self.key_bindings_manager)
|
||||
|
||||
|
@ -57,10 +59,13 @@ class PromptToolkitShell(BaseShell):
|
|||
"""Enters a loop that reads and execute input from user."""
|
||||
if intro:
|
||||
print(intro)
|
||||
mouse_support = builtins.__xonsh_env__.get('MOUSE_SUPPORT')
|
||||
while not builtins.__xonsh_exit__:
|
||||
try:
|
||||
token_func, style_cls = self._get_prompt_tokens_and_style()
|
||||
line = get_input(
|
||||
mouse_support=mouse_support,
|
||||
auto_suggest=AutoSuggestFromHistory(),
|
||||
get_prompt_tokens=token_func,
|
||||
style=style_cls,
|
||||
completer=self.pt_completer,
|
||||
|
@ -91,6 +96,8 @@ class PromptToolkitShell(BaseShell):
|
|||
Token.Menu.Completions.Completion: 'bg:#008888 #ffffff',
|
||||
Token.Menu.Completions.ProgressButton: 'bg:#003333',
|
||||
Token.Menu.Completions.ProgressBar: 'bg:#00aaaa',
|
||||
Token.AutoSuggestion: '#666666',
|
||||
Token.Aborted: '#888888',
|
||||
}
|
||||
# update with the prompt styles
|
||||
styles.update({t: s for (t, s) in zip(tokens, cstyles)})
|
||||
|
|
Loading…
Add table
Reference in a new issue