def __init__(self, stdout, get_size, true_color=False,
                 ansi_colors_only=None, term=None, write_binary=True):
        assert callable(get_size)
        assert term is None or isinstance(term, six.text_type)
        assert all(hasattr(stdout, a) for a in ('write', 'flush'))

        if write_binary:
            assert hasattr(stdout, 'encoding')

        self._buffer = []
        self.stdout = stdout
        self.write_binary = write_binary
        self.get_size = get_size
        self.true_color = to_simple_filter(true_color)
        self.term = term or 'xterm'

        # ANSI colors only?
        if ansi_colors_only is None:
            # When not given, use the following default.
            ANSI_COLORS_ONLY = bool(os.environ.get(
                'PROMPT_TOOLKIT_ANSI_COLORS_ONLY', False))

            @Condition
            def ansi_colors_only():
                return ANSI_COLORS_ONLY or term in ('linux', 'eterm-color')
        else:
            ansi_colors_only = to_simple_filter(ansi_colors_only)

        self.ansi_colors_only = ansi_colors_only

        # Cache for escape codes.
        self._escape_code_cache = _EscapeCodeCache(ansi_colors_only=ansi_colors_only)
        self._escape_code_cache_true_color = _EscapeCodeCache(
            true_color=True, ansi_colors_only=ansi_colors_only)
示例#2
0
    def __init__(self, stdout, get_size, true_color=False,
                 ansi_colors_only=None, term=None, write_binary=True):
        assert callable(get_size)
        assert term is None or isinstance(term, six.text_type)
        assert all(hasattr(stdout, a) for a in ('write', 'flush'))

        if write_binary:
            assert hasattr(stdout, 'encoding')

        self._buffer = []
        self.stdout = stdout
        self.write_binary = write_binary
        self.get_size = get_size
        self.true_color = to_simple_filter(true_color)
        self.term = term or 'xterm'

        # ANSI colors only?
        if ansi_colors_only is None:
            # When not given, use the following default.
            ANSI_COLORS_ONLY = bool(os.environ.get(
                'PROMPT_TOOLKIT_ANSI_COLORS_ONLY', False))

            @Condition
            def ansi_colors_only():
                return ANSI_COLORS_ONLY or term in ('linux', 'eterm-color')
        else:
            ansi_colors_only = to_simple_filter(ansi_colors_only)

        self.ansi_colors_only = ansi_colors_only

        # Cache for escape codes.
        self._escape_code_cache = _EscapeCodeCache(ansi_colors_only=ansi_colors_only)
        self._escape_code_cache_true_color = _EscapeCodeCache(
            true_color=True, ansi_colors_only=ansi_colors_only)
示例#3
0
    def create_output(stdout=None, true_color=False):
        """
        Return an :class:`~prompt_toolkit.output.Output` instance for the command
        line.
        :param true_color: When True, use 24bit colors instead of 256 colors.
            (`bool` or :class:`~prompt_toolkit.filters.SimpleFilter`.)

        Notes
        -----
        This method was forked from the mainline prompt-toolkit repo.
        Copyright (c) 2014, Jonathan Slenders, All rights reserved.
        This is deprecated and slated for removal after a prompt-toolkit
        v0.57+ release.
        """
        stdout = stdout or sys.__stdout__
        true_color = to_simple_filter(true_color)

        if is_windows():
            if is_conemu_ansi():
                return ConEmuOutput(stdout)
            else:
                return Win32Output(stdout)
        else:
            term = os.environ.get('TERM', '')
            if PY2:
                term = term.decode('utf-8')

            return Vt100_Output.from_pty(stdout,
                                         true_color=true_color)  #, term=term)
示例#4
0
文件: shortcuts.py 项目: mwiebe/xonsh
    def create_output(stdout=None, true_color=False):
        """
        Return an :class:`~prompt_toolkit.output.Output` instance for the command
        line.
        :param true_color: When True, use 24bit colors instead of 256 colors.
            (`bool` or :class:`~prompt_toolkit.filters.SimpleFilter`.)

        Notes
        -----
        This method was forked from the mainline prompt-toolkit repo.
        Copyright (c) 2014, Jonathan Slenders, All rights reserved.
        This is deprecated and slated for removal after a prompt-toolkit
        v0.57+ release.
        """
        stdout = stdout or sys.__stdout__
        true_color = to_simple_filter(true_color)

        if is_windows():
            if is_conemu_ansi():
                return ConEmuOutput(stdout)
            else:
                return Win32Output(stdout)
        else:
            term = os.environ.get('TERM', '')
            if PY2:
                term = term.decode('utf-8')

            return Vt100_Output.from_pty(stdout, true_color=true_color)#, term=term)
    def __init__(self, stdout, get_size, true_color=False, term=None):
        assert callable(get_size)
        assert term is None or isinstance(term, six.text_type)

        self._buffer = []
        self.stdout = stdout
        self.get_size = get_size
        self.true_color = to_simple_filter(true_color)
        self.term = term or 'xterm'

        # Cache for escape codes.
        self._escape_code_cache = _EscapeCodeCache(true_color=False, term=term)
        self._escape_code_cache_true_color = _EscapeCodeCache(true_color=True, term=term)
示例#6
0
    def __init__(self, stdout, get_size, true_color=False, term=None):
        assert callable(get_size)
        assert term is None or isinstance(term, six.text_type)

        self._buffer = []
        self.stdout = stdout
        self.get_size = get_size
        self.true_color = to_simple_filter(true_color)
        self.term = term or 'xterm'

        # Cache for escape codes.
        self._escape_code_cache = _EscapeCodeCache(true_color=False, term=term)
        self._escape_code_cache_true_color = _EscapeCodeCache(true_color=True,
                                                              term=term)
示例#7
0
    def __init__(self, stdout, get_size, true_color=False, term=None, write_binary=True):
        assert callable(get_size)
        assert term is None or isinstance(term, six.text_type)
        assert all(hasattr(stdout, a) for a in ('write', 'flush'))

        if write_binary:
            assert hasattr(stdout, 'encoding')

        self._buffer = []
        self.stdout = stdout
        self.write_binary = write_binary
        self.get_size = get_size
        self.true_color = to_simple_filter(true_color)
        self.term = term or 'xterm'

        # Cache for escape codes.
        self._escape_code_cache = _EscapeCodeCache(true_color=False, term=term)
        self._escape_code_cache_true_color = _EscapeCodeCache(true_color=True, term=term)
示例#8
0
    def __init__(self, stdout, get_size, true_color=False, term=None, write_binary=True):
        assert callable(get_size)
        assert term is None or isinstance(term, six.text_type)
        assert all(hasattr(stdout, a) for a in ('write', 'flush'))

        if write_binary:
            assert hasattr(stdout, 'encoding')

        self._buffer = []
        self.stdout = stdout
        self.write_binary = write_binary
        self.get_size = get_size
        self.true_color = to_simple_filter(true_color)
        self.term = term or 'xterm'

        # Cache for escape codes.
        self._escape_code_cache = _EscapeCodeCache(true_color=False, term=term)
        self._escape_code_cache_true_color = _EscapeCodeCache(true_color=True, term=term)
示例#9
0
 def __init__(self, true_color=False, ansi_colors_only=False):
     assert isinstance(true_color, bool)
     self.true_color = true_color
     self.ansi_colors_only = to_simple_filter(ansi_colors_only)
 def __init__(self, true_color=False, ansi_colors_only=False):
     assert isinstance(true_color, bool)
     self.true_color = true_color
     self.ansi_colors_only = to_simple_filter(ansi_colors_only)
示例#11
0
    def create_prompt_application(self,
                                  message='',
                                  multiline=False,
                                  wrap_lines=True,
                                  is_password=False,
                                  vi_mode=False,
                                  complete_while_typing=True,
                                  enable_history_search=False,
                                  lexer=None,
                                  enable_system_bindings=False,
                                  enable_open_in_editor=False,
                                  validator=None,
                                  completer=None,
                                  reserve_space_for_menu=8,
                                  auto_suggest=None,
                                  style=None,
                                  history=None,
                                  clipboard=None,
                                  get_prompt_tokens=None,
                                  get_bottom_toolbar_tokens=None,
                                  display_completions_in_columns=False,
                                  get_title=None,
                                  mouse_support=False,
                                  extra_input_processors=None,
                                  key_bindings_registry=None,
                                  on_abort=AbortAction.RAISE_EXCEPTION,
                                  on_exit=AbortAction.RAISE_EXCEPTION,
                                  accept_action=AcceptAction.RETURN_DOCUMENT,
                                  default=''):
        """Create an :class:`~Application` instance for a prompt.

        (It is meant to cover 90% of the prompt use cases, where no extreme
        customization is required. For more complex input, it is required to create
        a custom :class:`~Application` instance.)

        message : Text to be shown before the prompt.
        mulitiline : Allow multiline input. Pressing enter will insert a
                           newline. (This requires Meta+Enter to accept the input.)
        wrap_lines : `bool` or :class:`~prompt_toolkit.filters.CLIFilter`.
            When True (the default), automatically wrap long lines instead of
            scrolling horizontally.
        is_password : Show asterisks instead of the actual typed characters.
        vi_mode : `bool` or :class:`~prompt_toolkit.filters.CLIFilter`. If
            True, use Vi key bindings.
        complete_while_typing : `bool` or
            :class:`~prompt_toolkit.filters.CLIFilter`. Enable autocompletion while
            typing.
        enable_history_search : `bool` or
            :class:`~prompt_toolkit.filters.CLIFilter`. Enable up-arrow parting
            string matching.
        lexer : :class:`~prompt_toolkit.layout.lexers.Lexer` to be used for
            the syntax highlighting.
        validator : :class:`~prompt_toolkit.validation.Validator` instance
            for input validation.
        completer : :class:`~prompt_toolkit.completion.Completer` instance
            for input completion.
        reserve_space_for_menu : Space to be reserved for displaying the menu.
            (0 means that no space needs to be reserved.)
        auto_suggest : :class:`~prompt_toolkit.auto_suggest.AutoSuggest`
            instance for input suggestions.
        style : Pygments style class for the color scheme.
        enable_system_bindings : `bool` or
            :class:`~prompt_toolkit.filters.CLIFilter`. Pressing Meta+'!' will show
            a system prompt.
        enable_open_in_editor : `bool` or
            :class:`~prompt_toolkit.filters.CLIFilter`. Pressing 'v' in Vi mode or
            C-X C-E in emacs mode will open an external editor.
        history : :class:`~prompt_toolkit.history.History` instance.
        clipboard : :class:`~prompt_toolkit.clipboard.base.Clipboard` instance.
            (e.g. :class:`~prompt_toolkit.clipboard.in_memory.InMemoryClipboard`)
        get_bottom_toolbar_tokens : Optional callable which takes a
            :class:`~prompt_toolkit.interface.CommandLineInterface` and returns a
            list of tokens for the bottom toolbar.
        display_completions_in_columns : `bool` or
            :class:`~prompt_toolkit.filters.CLIFilter`. Display the completions in
            multiple columns.
        get_title : Callable that returns the title to be displayed in the
            terminal.
        mouse_support : `bool` or :class:`~prompt_toolkit.filters.CLIFilter`
            to enable mouse support.
        default : The default text to be shown in the input buffer. (This can
            be edited by the user.)

        Notes
        -----
        This method was forked from the mainline prompt-toolkit repo.
        Copyright (c) 2014, Jonathan Slenders, All rights reserved.

        WARNING; This method is due for removal once prompt-toolkit >v0.54 
        is released.
        """
        if key_bindings_registry is None:
            key_bindings_registry = KeyBindingManager.for_prompt(
                enable_vi_mode=vi_mode,
                enable_system_bindings=enable_system_bindings,
                enable_open_in_editor=enable_open_in_editor).registry

        # Make sure that complete_while_typing is disabled when enable_history_search
        # is enabled. (First convert to SimpleFilter, to avoid doing bitwise operations
        # on bool objects.)
        complete_while_typing = to_simple_filter(complete_while_typing)
        enable_history_search = to_simple_filter(enable_history_search)
        multiline = to_simple_filter(multiline)

        complete_while_typing = complete_while_typing & ~enable_history_search

        # Accept Pygments styles as well for backwards compatibility.
        try:
            if issubclass(style, pygments.style.Style):
                style = PygmentsStyle(style)
        except TypeError:  # Happens when style is `None` or an instance of something else.
            pass

        # Create application
        return Application(layout=self.create_prompt_layout(
            message=message,
            lexer=lexer,
            is_password=is_password,
            reserve_space_for_menu=(reserve_space_for_menu
                                    if completer is not None else 0),
            multiline=Condition(lambda cli: multiline()),
            get_prompt_tokens=get_prompt_tokens,
            get_bottom_toolbar_tokens=get_bottom_toolbar_tokens,
            display_completions_in_columns=display_completions_in_columns,
            extra_input_processors=extra_input_processors,
            wrap_lines=wrap_lines),
                           buffer=Buffer(
                               enable_history_search=enable_history_search,
                               complete_while_typing=complete_while_typing,
                               is_multiline=multiline,
                               history=(history or InMemoryHistory()),
                               validator=validator,
                               completer=completer,
                               auto_suggest=auto_suggest,
                               accept_action=accept_action,
                               initial_document=Document(default),
                           ),
                           style=style or DEFAULT_STYLE,
                           clipboard=clipboard,
                           key_bindings_registry=key_bindings_registry,
                           get_title=get_title,
                           mouse_support=mouse_support,
                           on_abort=on_abort,
                           on_exit=on_exit)
示例#12
0
 def __init__(self, stdout, get_size, true_color=False):
     self._buffer = []
     self.stdout = stdout
     self.get_size = get_size
     self.true_color = to_simple_filter(true_color)
示例#13
0
    def create_prompt_application(self,
        message='',
        multiline=False,
        wrap_lines=True,
        is_password=False,
        vi_mode=False,
        complete_while_typing=True,
        enable_history_search=False,
        lexer=None,
        enable_system_bindings=False,
        enable_open_in_editor=False,
        validator=None,
        completer=None,
        reserve_space_for_menu=8,
        auto_suggest=None,
        style=None,
        history=None,
        clipboard=None,
        get_prompt_tokens=None,
        get_bottom_toolbar_tokens=None,
        display_completions_in_columns=False,
        get_title=None,
        mouse_support=False,
        extra_input_processors=None,
        key_bindings_registry=None,
        on_abort=AbortAction.RAISE_EXCEPTION,
        on_exit=AbortAction.RAISE_EXCEPTION,
        accept_action=AcceptAction.RETURN_DOCUMENT,
        default=''):
        """Create an :class:`~Application` instance for a prompt.

        (It is meant to cover 90% of the prompt use cases, where no extreme
        customization is required. For more complex input, it is required to create
        a custom :class:`~Application` instance.)

        message : Text to be shown before the prompt.
        mulitiline : Allow multiline input. Pressing enter will insert a
                           newline. (This requires Meta+Enter to accept the input.)
        wrap_lines : `bool` or :class:`~prompt_toolkit.filters.CLIFilter`.
            When True (the default), automatically wrap long lines instead of
            scrolling horizontally.
        is_password : Show asterisks instead of the actual typed characters.
        vi_mode : `bool` or :class:`~prompt_toolkit.filters.CLIFilter`. If
            True, use Vi key bindings.
        complete_while_typing : `bool` or
            :class:`~prompt_toolkit.filters.CLIFilter`. Enable autocompletion while
            typing.
        enable_history_search : `bool` or
            :class:`~prompt_toolkit.filters.CLIFilter`. Enable up-arrow parting
            string matching.
        lexer : :class:`~prompt_toolkit.layout.lexers.Lexer` to be used for
            the syntax highlighting.
        validator : :class:`~prompt_toolkit.validation.Validator` instance
            for input validation.
        completer : :class:`~prompt_toolkit.completion.Completer` instance
            for input completion.
        reserve_space_for_menu : Space to be reserved for displaying the menu.
            (0 means that no space needs to be reserved.)
        auto_suggest : :class:`~prompt_toolkit.auto_suggest.AutoSuggest`
            instance for input suggestions.
        style : Pygments style class for the color scheme.
        enable_system_bindings : `bool` or
            :class:`~prompt_toolkit.filters.CLIFilter`. Pressing Meta+'!' will show
            a system prompt.
        enable_open_in_editor : `bool` or
            :class:`~prompt_toolkit.filters.CLIFilter`. Pressing 'v' in Vi mode or
            C-X C-E in emacs mode will open an external editor.
        history : :class:`~prompt_toolkit.history.History` instance.
        clipboard : :class:`~prompt_toolkit.clipboard.base.Clipboard` instance.
            (e.g. :class:`~prompt_toolkit.clipboard.in_memory.InMemoryClipboard`)
        get_bottom_toolbar_tokens : Optional callable which takes a
            :class:`~prompt_toolkit.interface.CommandLineInterface` and returns a
            list of tokens for the bottom toolbar.
        display_completions_in_columns : `bool` or
            :class:`~prompt_toolkit.filters.CLIFilter`. Display the completions in
            multiple columns.
        get_title : Callable that returns the title to be displayed in the
            terminal.
        mouse_support : `bool` or :class:`~prompt_toolkit.filters.CLIFilter`
            to enable mouse support.
        default : The default text to be shown in the input buffer. (This can
            be edited by the user.)

        Notes
        -----
        This method was forked from the mainline prompt-toolkit repo.
        Copyright (c) 2014, Jonathan Slenders, All rights reserved.

        WARNING; This method is due for removal once prompt-toolkit >v0.54 
        is released.
        """
        if key_bindings_registry is None:
            key_bindings_registry = KeyBindingManager.for_prompt(
                enable_vi_mode=vi_mode,
                enable_system_bindings=enable_system_bindings,
                enable_open_in_editor=enable_open_in_editor).registry

        # Make sure that complete_while_typing is disabled when enable_history_search
        # is enabled. (First convert to SimpleFilter, to avoid doing bitwise operations
        # on bool objects.)
        complete_while_typing = to_simple_filter(complete_while_typing)
        enable_history_search = to_simple_filter(enable_history_search)
        multiline = to_simple_filter(multiline)

        complete_while_typing = complete_while_typing & ~enable_history_search

        # Accept Pygments styles as well for backwards compatibility.
        try:
            if issubclass(style, pygments.style.Style):
                style = PygmentsStyle(style)
        except TypeError: # Happens when style is `None` or an instance of something else.
            pass

        # Create application
        return Application(
            layout=self.create_prompt_layout(
                message=message,
                lexer=lexer,
                is_password=is_password,
                reserve_space_for_menu=(reserve_space_for_menu if completer is not None else 0),
                multiline=Condition(lambda cli: multiline()),
                get_prompt_tokens=get_prompt_tokens,
                get_bottom_toolbar_tokens=get_bottom_toolbar_tokens,
                display_completions_in_columns=display_completions_in_columns,
                extra_input_processors=extra_input_processors,
                wrap_lines=wrap_lines),
            buffer=Buffer(
                enable_history_search=enable_history_search,
                complete_while_typing=complete_while_typing,
                is_multiline=multiline,
                history=(history or InMemoryHistory()),
                validator=validator,
                completer=completer,
                auto_suggest=auto_suggest,
                accept_action=accept_action,
                initial_document=Document(default),
            ),
            style=style or DEFAULT_STYLE,
            clipboard=clipboard,
            key_bindings_registry=key_bindings_registry,
            get_title=get_title,
            mouse_support=mouse_support,
            on_abort=on_abort,
            on_exit=on_exit)
示例#14
0
 def __init__(self, stdout, get_size, true_color=False):
     self._buffer = []
     self.stdout = stdout
     self.get_size = get_size
     self.true_color = to_simple_filter(true_color)