From 3961310418a922e1eb4c14a7a9e49247f061bf82 Mon Sep 17 00:00:00 2001 From: mdraw Date: Thu, 1 Oct 2015 01:57:53 +0200 Subject: [PATCH] Made prompt_toolkit's mouse_support optional Introducing a new environment variable MOUSE_SUPPORT for this, which can either be True or False. Default is False. --- docs/envvars.rst | 7 +++++++ xonsh/environ.py | 12 +++++++----- xonsh/prompt_toolkit_shell.py | 3 ++- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/docs/envvars.rst b/docs/envvars.rst index de9eeb218..9e675ca6f 100644 --- a/docs/envvars.rst +++ b/docs/envvars.rst @@ -146,6 +146,13 @@ applicable. * - XONSH_INTERACTIVE - - ``True`` if xonsh is running interactively, and ``False`` otherwise. + * - 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) * - XONSH_SHOW_TRACEBACK - ``False`` but not set - Controls if a traceback is shown exceptions occur in the shell. Set ``True`` diff --git a/xonsh/environ.py b/xonsh/environ.py index 87d69496e..9d421437f 100644 --- a/xonsh/environ.py +++ b/xonsh/environ.py @@ -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': (), @@ -581,6 +582,7 @@ BASE_ENV = { 'LC_MONETARY': locale.setlocale(locale.LC_MONETARY), 'LC_NUMERIC': locale.setlocale(locale.LC_NUMERIC), 'XONSH_VERSION': XONSH_VERSION, + 'MOUSE_SUPPORT': False, } try: @@ -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) diff --git a/xonsh/prompt_toolkit_shell.py b/xonsh/prompt_toolkit_shell.py index 7f8046f32..5fe0e4270 100644 --- a/xonsh/prompt_toolkit_shell.py +++ b/xonsh/prompt_toolkit_shell.py @@ -59,11 +59,12 @@ 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=True, + mouse_support=mouse_support, auto_suggest=AutoSuggestFromHistory(), get_prompt_tokens=token_func, style=style_cls,