def XonshTerminal256Formatter(): if (ptk_version_info() and ptk_version_info() > (2, 0) and pygments_version_info() and (2, 2, 0) <= pygments_version_info() < (2, 4, 0)): # Monky patch pygments' dict of console codes # with the new color names used by PTK2 # Can be removed once pygment names get fixed. _monkey_patch_pygments_codes() class XonshTerminal256FormatterProxy(terminal256.Terminal256Formatter): """Proxy class for xonsh terminal256 formatting that understands. xonsh color tokens. """ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) # just keep the opening token for colors. color_names = set(map(str, Color.subtypes)) for name, (opener, closer) in self.style_string.items(): if name in color_names: self.style_string[name] = (opener, "") # special case DEFAULT, because it is special. self.style_string["Token.Color.DEFAULT"] = ("\x1b[39m", "") return XonshTerminal256FormatterProxy
def XonshTerminal256Formatter(): if ( ptk_version_info() and ptk_version_info() > (2, 0) and pygments_version_info() and (2, 2) <= pygments_version_info() < (2, 3) ): # Monky patch pygments' dict of console codes # with the new color names used by PTK2 # Can be removed once pygment names get fixed. _monkey_patch_pygments_codes() class XonshTerminal256FormatterProxy(terminal256.Terminal256Formatter): """Proxy class for xonsh terminal256 formatting that understands. xonsh color tokens. """ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) # just keep the opening token for colors. color_names = set(map(str, Color.subtypes)) for name, (opener, closer) in self.style_string.items(): if name in color_names: self.style_string[name] = (opener, "") # special case NO_COLOR, because it is special. self.style_string["Token.Color.NO_COLOR"] = ("\x1b[39m", "") return XonshTerminal256FormatterProxy
def __init__(self, ctx=None, shell_type=None, config=None, rc=None, **kwargs): """ Parameters ---------- ctx : Mapping, optional The execution context for the shell (e.g. the globals namespace). If none, this is computed by loading the rc files. If not None, this no additional context is computed and this is used directly. shell_type : str, optional The shell type to start, such as 'readline', 'prompt_toolkit', or 'random'. config : str, optional Path to configuration file. rc : list of str, optional Sequence of paths to run control files. """ self.login = kwargs.get('login', True) self.stype = shell_type self._init_environ(ctx, config, rc, kwargs.get('scriptcache', True), kwargs.get('cacheall', False)) env = builtins.__xonsh_env__ # pick a valid shell -- if no shell is specified by the user, # shell type is pulled from env if shell_type is None: shell_type = env.get('SHELL_TYPE') if shell_type == 'best' or shell_type is None: shell_type = best_shell_type() elif shell_type == 'random': shell_type = random.choice(('readline', 'prompt_toolkit')) if shell_type == 'prompt_toolkit': if not has_prompt_toolkit(): warn( 'prompt_toolkit is not available, using readline instead.') shell_type = 'readline' env['SHELL_TYPE'] = shell_type # actually make the shell if shell_type == 'none': from xonsh.base_shell import BaseShell as shell_class elif shell_type == 'prompt_toolkit': if ptk_version_info()[:2] < (1, 0): msg = ('prompt-toolkit version < v1.0.0 is not supported, ' 'xonsh may not work as expected. Please update.') warn(msg, RuntimeWarning) from xonsh.ptk.shell import PromptToolkitShell as shell_class elif shell_type == 'readline': from xonsh.readline_shell import ReadlineShell as shell_class else: raise XonshError( '{} is not recognized as a shell type'.format(shell_type)) self.shell = shell_class(execer=self.execer, ctx=self.ctx, **kwargs) # allows history garbace colector to start running builtins.__xonsh_history__.gc.wait_for_shell = False
def __init__(self, ctx=None, shell_type=None, config=None, rc=None, **kwargs): """ Parameters ---------- ctx : Mapping, optional The execution context for the shell (e.g. the globals namespace). If none, this is computed by loading the rc files. If not None, this no additional context is computed and this is used directly. shell_type : str, optional The shell type to start, such as 'readline', 'prompt_toolkit', or 'random'. config : str, optional Path to configuration file. rc : list of str, optional Sequence of paths to run control files. """ self.login = kwargs.get('login', True) self.stype = shell_type self._init_environ(ctx, config, rc, kwargs.get('scriptcache', True), kwargs.get('cacheall', False)) env = builtins.__xonsh_env__ # pick a valid shell if shell_type is not None: env['SHELL_TYPE'] = shell_type shell_type = env.get('SHELL_TYPE') if shell_type == 'best' or shell_type is None: shell_type = BEST_SHELL_TYPE elif shell_type == 'random': shell_type = random.choice(('readline', 'prompt_toolkit')) if shell_type == 'prompt_toolkit': if not has_prompt_toolkit(): warn('prompt_toolkit is not available, using readline instead.') shell_type = env['SHELL_TYPE'] = 'readline' # actually make the shell if shell_type == 'none': from xonsh.base_shell import BaseShell as shell_class elif shell_type == 'prompt_toolkit': if ptk_version_info()[:2] < (0, 57) or \ ptk_version() == '<0.57': # TODO: remove in future msg = ('prompt-toolkit version < v0.57 and may not work as ' 'expected. Please update.') warn(msg, RuntimeWarning) from xonsh.ptk.shell import PromptToolkitShell as shell_class elif shell_type == 'readline': from xonsh.readline_shell import ReadlineShell as shell_class else: raise XonshError('{} is not recognized as a shell type'.format( shell_type)) self.shell = shell_class(execer=self.execer, ctx=self.ctx, **kwargs) # allows history garbace colector to start running builtins.__xonsh_history__.gc.wait_for_shell = False
def __init__(self, ctx=None, shell_type=None, config=None, rc=None, **kwargs): """ Parameters ---------- ctx : Mapping, optional The execution context for the shell (e.g. the globals namespace). If none, this is computed by loading the rc files. If not None, this no additional context is computed and this is used directly. shell_type : str, optional The shell type to start, such as 'readline', 'prompt_toolkit', or 'random'. config : str, optional Path to configuration file. rc : list of str, optional Sequence of paths to run control files. """ self.login = kwargs.get("login", True) self.stype = shell_type self._init_environ(ctx, config, rc, kwargs.get("scriptcache", True), kwargs.get("cacheall", False)) env = builtins.__xonsh_env__ # pick a valid shell -- if no shell is specified by the user, # shell type is pulled from env if shell_type is None: shell_type = env.get("SHELL_TYPE") if shell_type == "best" or shell_type is None: shell_type = best_shell_type() elif shell_type == "random": shell_type = random.choice(("readline", "prompt_toolkit")) if shell_type == "prompt_toolkit": if not has_prompt_toolkit(): warn("prompt_toolkit is not available, using readline instead.") shell_type = "readline" env["SHELL_TYPE"] = shell_type # actually make the shell if shell_type == "none": from xonsh.base_shell import BaseShell as shell_class elif shell_type == "prompt_toolkit": if ptk_version_info()[:2] < (1, 0): msg = ( "prompt-toolkit version < v1.0.0 is not supported, " "xonsh may not work as expected. Please update." ) warn(msg, RuntimeWarning) from xonsh.ptk.shell import PromptToolkitShell as shell_class elif shell_type == "readline": from xonsh.readline_shell import ReadlineShell as shell_class else: raise XonshError("{} is not recognized as a shell type".format(shell_type)) self.shell = shell_class(execer=self.execer, ctx=self.ctx, **kwargs) # allows history garbace colector to start running builtins.__xonsh_history__.gc.wait_for_shell = False
def __init__(self, cli=None, *args, **kwargs): """Implements a prompt that statefully holds a command-line interface. When used as a context manager, it will return itself on entry and reset itself on exit. Parameters ---------- cli : CommandLineInterface or None, optional If this is not a CommandLineInterface object, such an object will be created when the prompt() method is called. """ self.cli = cli self.major_minor = ptk_version_info()[:2]
def __init__(self, **kwargs): super().__init__(**kwargs) self.prompter = Prompter() self.history = PromptToolkitHistory() self.pt_completer = PromptToolkitCompleter(self.completer, self.ctx) key_bindings_manager_args = { 'enable_auto_suggest_bindings': True, 'enable_search': True, 'enable_abort_and_exit_bindings': True, 'enable_open_in_editor': True, } major, minor = ptk_version_info()[:2] self.new_vi_mode_flag = (major, minor) >= (1, 0) \ and ptk_version() != '<0.57' if not self.new_vi_mode_flag: # enable_vi_mode is deprecated acoording to prompt_toolset 1.0 document. key_bindings_manager_args['enable_vi_mode'] = Condition( lambda cli: builtins.__xonsh_env__.get('VI_MODE')) self.key_bindings_manager = KeyBindingManager( **key_bindings_manager_args) load_xonsh_bindings(self.key_bindings_manager)
from xonsh.commands_cache import CommandsCache if not hasattr(builtins, "__xonsh__"): from argparse import Namespace builtins.__xonsh__ = Namespace() builtins.__xonsh__.load = lambda *a, **kw: None builtins.__xonsh__.link_builtins = lambda *a, **kw: None spec = importlib.util.find_spec("prompt_toolkit") if spec is not None: # hacky runaround to import PTK-specific events builtins.__xonsh__.env = Env() from xonsh.platform import ptk_version_info if ptk_version_info()[0] < 2: from xonsh.ptk.shell import events else: from xonsh.ptk2.shell import events else: from xonsh.events import events sys.path.insert(0, os.path.dirname(__file__)) def setup(sphinx): from xonsh.pyghooks import XonshConsoleLexer sphinx.add_lexer("xonshcon", XonshConsoleLexer())
) skip_if_on_windows = pytest.mark.skipif(ON_WINDOWS, reason="Unix stuff") skip_if_on_azure_pipelines = pytest.mark.skipif( ON_AZURE_PIPELINES, reason="not suitable for azure" ) skip_if_on_unix = pytest.mark.skipif(not ON_WINDOWS, reason="Windows stuff") skip_if_on_darwin = pytest.mark.skipif(ON_DARWIN, reason="not Mac friendly") skip_if_on_travis = pytest.mark.skipif(ON_TRAVIS, reason="not Travis CI friendly") skip_if_lt_ptk2 = pytest.mark.skipif( ptk_version_info()[0] < 2, reason="prompt-toolkit <2" ) def sp(cmd): return subprocess.check_output(cmd, universal_newlines=True) class DummyStyler: styles = defaultdict(str) class DummyBaseShell(BaseShell): def __init__(self): self.styler = DummyStyler()
skip_if_on_conda = pytest.mark.skipif( ON_CONDA, reason="Conda and virtualenv _really_ hate each other") skip_if_on_msys = pytest.mark.skipif( ON_MSYS, reason="MSYS and virtualenv _really_ hate each other") skip_if_on_windows = pytest.mark.skipif(ON_WINDOWS, reason='Unix stuff') skip_if_on_unix = pytest.mark.skipif(not ON_WINDOWS, reason='Windows stuff') skip_if_on_darwin = pytest.mark.skipif(ON_DARWIN, reason='not Mac friendly') skip_if_on_travis = pytest.mark.skipif(ON_TRAVIS, reason='not Travis CI friendly') skip_if_lt_ptk2 = pytest.mark.skipif(ptk_version_info()[0] < 2, reason="prompt-tollkit <2") def sp(cmd): return subprocess.check_output(cmd, universal_newlines=True) class DummyStyler(): styles = defaultdict(str) class DummyBaseShell(BaseShell): def __init__(self): self.styler = DummyStyler()
from xonsh.xontribs import xontrib_metadata from xonsh import main from xonsh.commands_cache import CommandsCache if not hasattr(builtins, "__xonsh__"): from argparse import Namespace builtins.__xonsh__ = Namespace() builtins.__xonsh__.load = lambda *a, **kw: None builtins.__xonsh__.link_builtins = lambda *a, **kw: None spec = importlib.util.find_spec('prompt_toolkit') if spec is not None: # hacky runaround to import PTK-specific events builtins.__xonsh__.env = Env() from xonsh.platform import ptk_version_info if ptk_version_info()[0] < 2: from xonsh.ptk.shell import events else: from xonsh.ptk2.shell import events else: from xonsh.events import events sys.path.insert(0, os.path.dirname(__file__)) def setup(sphinx): from xonsh.pyghooks import XonshConsoleLexer sphinx.add_lexer("xonshcon", XonshConsoleLexer()) # -- General configuration -----------------------------------------------------