当前位置: 首页>>代码示例>>Python>>正文


Python buffer.Buffer类代码示例

本文整理汇总了Python中prompt_toolkit.buffer.Buffer的典型用法代码示例。如果您正苦于以下问题:Python Buffer类的具体用法?Python Buffer怎么用?Python Buffer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Buffer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ctx

def ctx():
    """Context in which the ptk multiline functionality will be tested."""
    builtins.__xonsh_env__ = DummyEnv()
    builtins.__xonsh_env__['INDENT'] = '    '
    from xonsh.ptk.key_bindings import carriage_return
    ptk_buffer = Buffer()
    ptk_buffer.accept_action = MagicMock(name='accept', spec=AcceptAction)
    cli = MagicMock(name='cli', spec=CommandLineInterface)
    yield Context(indent='    ',
                  buffer=ptk_buffer,
                  accept=ptk_buffer.accept_action,
                  cli=cli,
                  cr=carriage_return)
    del builtins.__xonsh_env__
开发者ID:VHarisop,项目名称:xonsh,代码行数:14,代码来源:test_ptk_multiline.py

示例2: on_text_changed

def on_text_changed(buf: Buffer, state=state):
    filename = buf.text.rstrip().rsplit("\n", 1)[-1].strip()
    if filename == "":
        return
    if state["filename"] != filename:
        # state["filename"] = current_display.text = filename
        try:
            with open(filename) as rf:
                state["content"] = content_display.text = rf.read()
            buf.validation_state = ValidationState.VALID
            buf.validation_error = None
        except FileNotFoundError as e:
            buf.validation_error = ValidationError(message=repr(e))
            buf.validation_state = ValidationState.INVALID
开发者ID:podhmo,项目名称:individual-sandbox,代码行数:14,代码来源:05multiviews-path-completion.py

示例3: __init__

    def __init__(self, process):
        assert isinstance(process, Process)

        self.process = process
        self.chosen_name = None

        # Displayed the clock instead of this pane content.
        self.clock_mode = False

        # Give unique ID.
        Pane._pane_counter += 1
        self.pane_id = Pane._pane_counter

        # Prompt_toolkit buffer, for displaying scrollable text.
        # (In copy mode, or help mode.)
        # Note: Because the scroll_buffer can only contain text, we also use the
        #       copy_token_list, that contains a token list with color information.
        self.scroll_buffer = Buffer(read_only=True)
        self.copy_token_list = []
        self.display_scroll_buffer = False
        self.scroll_buffer_title = ''

        # Search buffer, for use in copy mode. (Each pane gets its own search buffer.)
        self.search_buffer = Buffer()
        self.is_searching = False
        self.search_state = SearchState(ignore_case=False)
开发者ID:PabloSajnovsky,项目名称:pymux,代码行数:26,代码来源:arrangement.py

示例4: ctx

def ctx():
    """Context in which the ptk multiline functionality will be tested."""
    builtins.__xonsh__ = XonshSession()
    builtins.__xonsh__.env = DummyEnv()
    builtins.__xonsh__.env["INDENT"] = "    "
    from xonsh.ptk2.key_bindings import carriage_return

    ptk_buffer = Buffer()
    ptk_buffer.accept_action = MagicMock(name="accept")
    cli = MagicMock(name="cli", spec=Application)
    yield Context(
        indent="    ",
        buffer=ptk_buffer,
        accept=ptk_buffer.accept_action,
        cli=cli,
        cr=carriage_return,
    )
    del builtins.__xonsh__.env
    del builtins.__xonsh__
开发者ID:ericmharris,项目名称:xonsh,代码行数:19,代码来源:test_ptk_multiline.py

示例5: setup

def setup():
    global indent_
    global buffer
    global bufaccept
    global cli
    global carriage_return
    global builtins
    
    import builtins

    builtins.__xonsh_env__ = Env()
    builtins.__xonsh_env__['INDENT'] = '    '

    from xonsh.ptk.key_bindings import carriage_return

    indent_ = '    '
    buffer = Buffer()
    bufaccept = MagicMock(name='accept', spec=AcceptAction)
    cli = MagicMock(name='cli', spec=CommandLineInterface)
    buffer.accept_action = bufaccept
开发者ID:blink1073,项目名称:xonsh,代码行数:20,代码来源:test_ptk_multiline.py

示例6: test_undo_capitalize

    def test_undo_capitalize(self):
        buffer = Buffer()

        text = 'Selec'
        buffer.set_document(Document(text, len(text)))
        self.capitalizer.apply_capitalization(buffer)
        self.assertEqual('Selec', buffer.text)

        text = buffer.text + 't'
        buffer.set_document(Document(text, len(text)))
        self.capitalizer.apply_capitalization(buffer)
        self.assertEqual('SELECT', buffer.text)

        text = buffer.text + 'i'
        buffer.set_document(Document(text, len(text)))
        self.capitalizer.apply_capitalization(buffer)
        self.assertEqual('Selecti', buffer.text)

        text = buffer.text + 'on'
        buffer.set_document(Document(text, len(text)))
        self.capitalizer.apply_capitalization(buffer)
        self.assertEqual('Selection', buffer.text)
开发者ID:crate,项目名称:crash,代码行数:22,代码来源:test_repl.py

示例7: __init__

    def __init__(self, prompt='Shell command: ', enable_global_bindings=True):
        self.prompt = prompt
        self.enable_global_bindings = to_filter(enable_global_bindings)

        self.system_buffer = Buffer(name=SYSTEM_BUFFER)

        self._bindings = self._build_key_bindings()

        self.buffer_control = BufferControl(
            buffer=self.system_buffer,
            lexer=SimpleLexer(style='class:system-toolbar.text'),
            input_processors=[BeforeInput(
                lambda: self.prompt, style='class:system-toolbar')],
            key_bindings=self._bindings)

        self.window = Window(
            self.buffer_control, height=1,
            style='class:system-toolbar')

        self.container = ConditionalContainer(
            content=self.window,
            filter=has_focus(self.system_buffer))
开发者ID:PKpacheco,项目名称:monitor-dollar-value-galicia,代码行数:22,代码来源:toolbars.py

示例8: test_simple_search_with_arg

def test_simple_search_with_arg(_history):
    buff = Buffer(history=_history)
    buff.yank_last_arg(n=2)
    assert buff.document.current_line == 'three'
开发者ID:tsvenson,项目名称:python-prompt-toolkit,代码行数:4,代码来源:test_yank_nth_arg.py

示例9: test_simple_search_with_quotes

def test_simple_search_with_quotes(_history):
    _history.append_string("""one two "three 'x' four"\n""")
    buff = Buffer(history=_history)
    buff.yank_last_arg()
    assert buff.document.current_line == '''"three 'x' four"'''
开发者ID:tsvenson,项目名称:python-prompt-toolkit,代码行数:5,代码来源:test_yank_nth_arg.py

示例10: test_simple_search

def test_simple_search(_history):
    buff = Buffer(history=_history)
    buff.yank_last_arg()
    assert buff.document.current_line == 'four'
开发者ID:tsvenson,项目名称:python-prompt-toolkit,代码行数:4,代码来源:test_yank_nth_arg.py

示例11: test_empty_history

def test_empty_history():
    buf = Buffer()
    buf.yank_last_arg()
    assert buf.document.current_line == ''
开发者ID:tsvenson,项目名称:python-prompt-toolkit,代码行数:4,代码来源:test_yank_nth_arg.py

示例12: SystemToolbar

class SystemToolbar(object):
    """
    Toolbar for a system prompt.

    :param prompt: Prompt to be displayed to the user.
    """
    def __init__(self, prompt='Shell command: ', enable_global_bindings=True):
        self.prompt = prompt
        self.enable_global_bindings = to_filter(enable_global_bindings)

        self.system_buffer = Buffer(name=SYSTEM_BUFFER)

        self._bindings = self._build_key_bindings()

        self.buffer_control = BufferControl(
            buffer=self.system_buffer,
            lexer=SimpleLexer(style='class:system-toolbar.text'),
            input_processors=[BeforeInput(
                lambda: self.prompt, style='class:system-toolbar')],
            key_bindings=self._bindings)

        self.window = Window(
            self.buffer_control, height=1,
            style='class:system-toolbar')

        self.container = ConditionalContainer(
            content=self.window,
            filter=has_focus(self.system_buffer))

    def _get_display_before_text(self):
        return [
            ('class:system-toolbar', 'Shell command: '),
            ('class:system-toolbar.text', self.system_buffer.text),
            ('', '\n'),
        ]

    def _build_key_bindings(self):
        focused = has_focus(self.system_buffer)

        # Emacs
        emacs_bindings = KeyBindings()
        handle = emacs_bindings.add

        @handle('escape', filter=focused)
        @handle('c-g', filter=focused)
        @handle('c-c', filter=focused)
        def _(event):
            " Hide system prompt. "
            self.system_buffer.reset()
            event.app.layout.focus_last()

        @handle('enter', filter=focused)
        def _(event):
            " Run system command. "
            event.app.run_system_command(
                self.system_buffer.text,
                display_before_text=self._get_display_before_text())
            self.system_buffer.reset(append_to_history=True)
            event.app.layout.focus_last()

        # Vi.
        vi_bindings = KeyBindings()
        handle = vi_bindings.add

        @handle('escape', filter=focused)
        @handle('c-c', filter=focused)
        def _(event):
            " Hide system prompt. "
            event.app.vi_state.input_mode = InputMode.NAVIGATION
            self.system_buffer.reset()
            event.app.layout.focus_last()

        @handle('enter', filter=focused)
        def _(event):
            " Run system command. "
            event.app.vi_state.input_mode = InputMode.NAVIGATION
            event.app.run_system_command(
                self.system_buffer.text,
                display_before_text=self._get_display_before_text())
            self.system_buffer.reset(append_to_history=True)
            event.app.layout.focus_last()

        # Global bindings. (Listen to these bindings, even when this widget is
        # not focussed.)
        global_bindings = KeyBindings()
        handle = global_bindings.add

        @handle(Keys.Escape, '!', filter= ~focused & emacs_mode, is_global=True)
        def _(event):
            " M-'!' will focus this user control. "
            event.app.layout.focus(self.window)

        @handle('!', filter=~focused & vi_mode & vi_navigation_mode, is_global=True)
        def _(event):
            " Focus. "
            event.app.vi_state.input_mode = InputMode.INSERT
            event.app.layout.focus(self.window)

        return merge_key_bindings([
            ConditionalKeyBindings(emacs_bindings, emacs_mode),
#.........这里部分代码省略.........
开发者ID:PKpacheco,项目名称:monitor-dollar-value-galicia,代码行数:101,代码来源:toolbars.py

示例13: test_yank_nth_arg_with_arg

def test_yank_nth_arg_with_arg(_history):
    buff = Buffer(history=_history)
    buff.yank_nth_arg(n=2)
    assert buff.document.current_line == 'three'
开发者ID:tsvenson,项目名称:python-prompt-toolkit,代码行数:4,代码来源:test_yank_nth_arg.py

示例14: test_repeated_search_with_wraparound

def test_repeated_search_with_wraparound(_history):
    buff = Buffer(history=_history)
    buff.yank_last_arg()
    buff.yank_last_arg()
    buff.yank_last_arg()
    assert buff.document.current_line == 'four'
开发者ID:tsvenson,项目名称:python-prompt-toolkit,代码行数:6,代码来源:test_yank_nth_arg.py

示例15: TextArea

class TextArea(object):
    """
    A simple input field.

    This is a higher level abstraction on top of several other classes with
    sane defaults.

    This widget does have the most common options, but it does not intend to
    cover every single use case. For more configurations options, you can
    always build a text area manually, using a
    :class:`~prompt_toolkit.buffer.Buffer`,
    :class:`~prompt_toolkit.layout.BufferControl` and
    :class:`~prompt_toolkit.layout.Window`.

    Buffer attributes:

    :param text: The initial text.
    :param multiline: If True, allow multiline input.
    :param completer: :class:`~prompt_toolkit.completion.Completer` instance
        for auto completion.
    :param complete_while_typing: Boolean.
    :param accept_handler: Called when `Enter` is pressed (This should be a
        callable that takes a buffer as input).
    :param history: :class:`~prompt_toolkit.history.History` instance.
    :param auto_suggest: :class:`~prompt_toolkit.auto_suggest.AutoSuggest`
        instance for input suggestions.

    BufferControl attributes:

    :param password: When `True`, display using asterisks.
    :param focusable: When `True`, allow this widget to receive the focus.
    :param focus_on_click: When `True`, focus after mouse click.
    :param input_processors: `None` or a list of
        :class:`~prompt_toolkit.layout.Processor` objects.

    Window attributes:

    :param lexer: :class:`~prompt_toolkit.lexers.Lexer` instance for syntax
        highlighting.
    :param wrap_lines: When `True`, don't scroll horizontally, but wrap lines.
    :param width: Window width. (:class:`~prompt_toolkit.layout.Dimension` object.)
    :param height: Window height. (:class:`~prompt_toolkit.layout.Dimension` object.)
    :param scrollbar: When `True`, display a scroll bar.
    :param style: A style string.
    :param dont_extend_width: When `True`, don't take up more width then the
                              preferred width reported by the control.
    :param dont_extend_height: When `True`, don't take up more width then the
                               preferred height reported by the control.
    :param get_line_prefix: None or a callable that returns formatted text to
        be inserted before a line. It takes a line number (int) and a
        wrap_count and returns formatted text. This can be used for
        implementation of line continuations, things like Vim "breakindent" and
        so on.

    Other attributes:

    :param search_field: An optional `SearchToolbar` object.
    """
    def __init__(self, text='', multiline=True, password=False,
                 lexer=None, auto_suggest=None, completer=None,
                 complete_while_typing=True, accept_handler=None, history=None,
                 focusable=True, focus_on_click=False, wrap_lines=True,
                 read_only=False, width=None, height=None,
                 dont_extend_height=False, dont_extend_width=False,
                 line_numbers=False, get_line_prefix=None, scrollbar=False,
                 style='', search_field=None, preview_search=True, prompt='',
                 input_processors=None):
       # assert isinstance(text, six.text_type)

        if search_field is None:
            search_control = None

        if input_processors is None:
            input_processors = []

        # Writeable attributes.
        self.completer = completer
        self.complete_while_typing = complete_while_typing
        self.lexer = lexer
        self.auto_suggest = auto_suggest
        self.read_only = read_only
        self.wrap_lines = wrap_lines

        self.buffer = Buffer(
            document=Document(text, 0),
            multiline=multiline,
            read_only=Condition(lambda: is_true(self.read_only)),
            completer=DynamicCompleter(lambda: self.completer),
            complete_while_typing=Condition(
                lambda: is_true(self.complete_while_typing)),
            auto_suggest=DynamicAutoSuggest(lambda: self.auto_suggest),
            accept_handler=accept_handler,
            history=history)

        self.control = BufferControl(
            buffer=self.buffer,
            lexer=DynamicLexer(lambda: self.lexer),
            input_processors=[
                ConditionalProcessor(
                    AppendAutoSuggestion(),
#.........这里部分代码省略.........
开发者ID:DreamTeamXtreme,项目名称:Adventure,代码行数:101,代码来源:customBase.py


注:本文中的prompt_toolkit.buffer.Buffer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。