def __init__(self, ctx=None, shell_type=None, **kwargs): self._init_environ(ctx) 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 == 'prompt_toolkit': if not is_prompt_toolkit_available(): warn('prompt_toolkit is not available, using readline instead.') shell_type = env['SHELL_TYPE'] = 'readline' # actually make the shell if shell_type == 'prompt_toolkit': from xonsh.prompt_toolkit_shell import PromptToolkitShell self.shell = PromptToolkitShell(execer=self.execer, ctx=self.ctx, **kwargs) elif shell_type == 'readline': from xonsh.readline_shell import ReadlineShell self.shell = ReadlineShell(execer=self.execer, ctx=self.ctx, **kwargs) else: raise XonshError('{} is not recognized as a shell type'.format( shell_type)) # allows history garbace colector to start running builtins.__xonsh_history__.gc.wait_for_shell = False
def __init__(self, ctx=None, shell_type=None, **kwargs): self._init_environ(ctx) env = builtins.__xonsh_env__ if shell_type is not None: env['SHELL_TYPE'] = shell_type if env['SHELL_TYPE'] == 'prompt_toolkit': if not is_prompt_toolkit_available(): warn( 'prompt_toolkit is not available, using readline instead.') env['SHELL_TYPE'] = 'readline' if env['SHELL_TYPE'] == 'prompt_toolkit': from xonsh.prompt_toolkit_shell import PromptToolkitShell self.shell = PromptToolkitShell(execer=self.execer, ctx=self.ctx, **kwargs) elif env['SHELL_TYPE'] == 'readline': from xonsh.readline_shell import ReadlineShell self.shell = ReadlineShell(execer=self.execer, ctx=self.ctx, **kwargs) else: raise XonshError('{} is not recognized as a shell type'.format( env['SHELL_TYPE']))
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._init_environ(ctx, config, rc) 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': shell_type = best_shell_type() elif shell_type == 'random': shell_type = random.choice(('readline', 'prompt_toolkit')) if shell_type == 'prompt_toolkit': if not is_prompt_toolkit_available(): warn('prompt_toolkit is not available, using readline instead.') shell_type = env['SHELL_TYPE'] = 'readline' # actually make the shell if shell_type == 'prompt_toolkit': vptk = prompt_toolkit_version() minor = int(vptk.split('.')[1]) if minor < 57 or vptk == '<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 self.shell = PromptToolkitShell(execer=self.execer, ctx=self.ctx, **kwargs) elif shell_type == 'readline': from xonsh.readline_shell import ReadlineShell self.shell = ReadlineShell(execer=self.execer, ctx=self.ctx, **kwargs) else: raise XonshError('{} is not recognized as a shell type'.format( shell_type)) # allows history garbace colector to start running builtins.__xonsh_history__.gc.wait_for_shell = False
def readline_shell(xonsh_execer, tmpdir, mocker): from xonsh.readline_shell import ReadlineShell inp_path = tmpdir / "in" inp = inp_path.open("w+") out_path = tmpdir / "out" out = out_path.open("w+") shell = ReadlineShell(execer=xonsh_execer, ctx={}, stdin=inp, stdout=out) mocker.patch.object(shell, "_load_remaining_input_into_queue") yield shell inp.close() out.close()