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


Python Keys.ControlC方法代码示例

本文整理汇总了Python中prompt_toolkit.keys.Keys.ControlC方法的典型用法代码示例。如果您正苦于以下问题:Python Keys.ControlC方法的具体用法?Python Keys.ControlC怎么用?Python Keys.ControlC使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在prompt_toolkit.keys.Keys的用法示例。


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

示例1: test_remove_bindings

# 需要导入模块: from prompt_toolkit.keys import Keys [as 别名]
# 或者: from prompt_toolkit.keys.Keys import ControlC [as 别名]
def test_remove_bindings(handlers):
    with set_dummy_app():
        h = handlers.controlx_controlc
        h2 = handlers.controld

        # Test passing a handler to the remove() function.
        bindings = KeyBindings()
        bindings.add(Keys.ControlX, Keys.ControlC)(h)
        bindings.add(Keys.ControlD)(h2)
        assert len(bindings.bindings) == 2
        bindings.remove(h)
        assert len(bindings.bindings) == 1

        # Test passing a key sequence to the remove() function.
        bindings = KeyBindings()
        bindings.add(Keys.ControlX, Keys.ControlC)(h)
        bindings.add(Keys.ControlD)(h2)
        assert len(bindings.bindings) == 2
        bindings.remove(Keys.ControlX, Keys.ControlC)
        assert len(bindings.bindings) == 1 
开发者ID:prompt-toolkit,项目名称:python-prompt-toolkit,代码行数:22,代码来源:test_key_binding.py

示例2: test_feed_several

# 需要导入模块: from prompt_toolkit.keys import Keys [as 别名]
# 或者: from prompt_toolkit.keys.Keys import ControlC [as 别名]
def test_feed_several(processor, handlers):
    with set_dummy_app():
        # First an unknown key first.
        processor.feed(KeyPress(Keys.ControlQ, ""))
        processor.process_keys()

        assert handlers.called == []

        # Followed by a know key sequence.
        processor.feed(KeyPress(Keys.ControlX, ""))
        processor.feed(KeyPress(Keys.ControlC, ""))
        processor.process_keys()

        assert handlers.called == ["controlx_controlc"]

        # Followed by another unknown sequence.
        processor.feed(KeyPress(Keys.ControlR, ""))
        processor.feed(KeyPress(Keys.ControlS, ""))

        # Followed again by a know key sequence.
        processor.feed(KeyPress(Keys.ControlD, ""))
        processor.process_keys()

        assert handlers.called == ["controlx_controlc", "control_d"] 
开发者ID:prompt-toolkit,项目名称:python-prompt-toolkit,代码行数:26,代码来源:test_key_binding.py

示例3: _create_more_application

# 需要导入模块: from prompt_toolkit.keys import Keys [as 别名]
# 或者: from prompt_toolkit.keys.Keys import ControlC [as 别名]
def _create_more_application():
    """
    Create an `Application` instance that displays the "--MORE--".
    """
    from prompt_toolkit.shortcuts import create_prompt_application
    registry = Registry()

    @registry.add_binding(' ')
    @registry.add_binding('y')
    @registry.add_binding('Y')
    @registry.add_binding(Keys.ControlJ)
    @registry.add_binding(Keys.ControlI)  # Tab.
    def _(event):
        event.cli.set_return_value(True)

    @registry.add_binding('n')
    @registry.add_binding('N')
    @registry.add_binding('q')
    @registry.add_binding('Q')
    @registry.add_binding(Keys.ControlC)
    def _(event):
        event.cli.set_return_value(False)

    return create_prompt_application(
        '--MORE--', key_bindings_registry=registry, erase_when_done=True) 
开发者ID:bkerler,项目名称:android_universal,代码行数:27,代码来源:completion.py

示例4: load_abort_and_exit_bindings

# 需要导入模块: from prompt_toolkit.keys import Keys [as 别名]
# 或者: from prompt_toolkit.keys.Keys import ControlC [as 别名]
def load_abort_and_exit_bindings():
    """
    Basic bindings for abort (Ctrl-C) and exit (Ctrl-D).
    """
    registry = Registry()
    handle = registry.add_binding

    @handle(Keys.ControlC)
    def _(event):
        " Abort when Control-C has been pressed. "
        event.cli.abort()

    @Condition
    def ctrl_d_condition(cli):
        """ Ctrl-D binding is only active when the default buffer is selected
        and empty. """
        return (cli.current_buffer_name == DEFAULT_BUFFER and
                not cli.current_buffer.text)

    handle(Keys.ControlD, filter=ctrl_d_condition)(get_by_name('end-of-file'))

    return registry 
开发者ID:bkerler,项目名称:android_universal,代码行数:24,代码来源:basic.py

示例5: _create_more_session

# 需要导入模块: from prompt_toolkit.keys import Keys [as 别名]
# 或者: from prompt_toolkit.keys.Keys import ControlC [as 别名]
def _create_more_session(message: str = "--MORE--") -> "PromptSession":
    """
    Create a `PromptSession` object for displaying the "--MORE--".
    """
    from prompt_toolkit.shortcuts import PromptSession

    bindings = KeyBindings()

    @bindings.add(" ")
    @bindings.add("y")
    @bindings.add("Y")
    @bindings.add(Keys.ControlJ)
    @bindings.add(Keys.ControlM)
    @bindings.add(Keys.ControlI)  # Tab.
    def _yes(event: E) -> None:
        event.app.exit(result=True)

    @bindings.add("n")
    @bindings.add("N")
    @bindings.add("q")
    @bindings.add("Q")
    @bindings.add(Keys.ControlC)
    def _no(event: E) -> None:
        event.app.exit(result=False)

    @bindings.add(Keys.Any)
    def _ignore(event: E) -> None:
        " Disable inserting of text. "

    return PromptSession(message, key_bindings=bindings, erase_when_done=True) 
开发者ID:prompt-toolkit,项目名称:python-prompt-toolkit,代码行数:32,代码来源:completion.py

示例6: bindings

# 需要导入模块: from prompt_toolkit.keys import Keys [as 别名]
# 或者: from prompt_toolkit.keys.Keys import ControlC [as 别名]
def bindings(handlers):
    bindings = KeyBindings()
    bindings.add(Keys.ControlX, Keys.ControlC)(handlers.controlx_controlc)
    bindings.add(Keys.ControlX)(handlers.control_x)
    bindings.add(Keys.ControlD)(handlers.control_d)
    bindings.add(Keys.ControlSquareClose, Keys.Any)(handlers.control_square_close_any)

    return bindings 
开发者ID:prompt-toolkit,项目名称:python-prompt-toolkit,代码行数:10,代码来源:test_key_binding.py

示例7: test_feed_simple

# 需要导入模块: from prompt_toolkit.keys import Keys [as 别名]
# 或者: from prompt_toolkit.keys.Keys import ControlC [as 别名]
def test_feed_simple(processor, handlers):
    with set_dummy_app():
        processor.feed(KeyPress(Keys.ControlX, "\x18"))
        processor.feed(KeyPress(Keys.ControlC, "\x03"))
        processor.process_keys()

        assert handlers.called == ["controlx_controlc"] 
开发者ID:prompt-toolkit,项目名称:python-prompt-toolkit,代码行数:9,代码来源:test_key_binding.py

示例8: callback

# 需要导入模块: from prompt_toolkit.keys import Keys [as 别名]
# 或者: from prompt_toolkit.keys.Keys import ControlC [as 别名]
def callback(key_press):
    print(key_press)

    if key_press.key == Keys.ControlC:
        sys.exit(0) 
开发者ID:prompt-toolkit,项目名称:python-prompt-toolkit,代码行数:7,代码来源:debug_vt100_input.py

示例9: main

# 需要导入模块: from prompt_toolkit.keys import Keys [as 别名]
# 或者: from prompt_toolkit.keys.Keys import ControlC [as 别名]
def main():
    input = Win32Input()
    done = asyncio.Event()

    def keys_ready():
        for key_press in input.read_keys():
            print(key_press)

            if key_press.key == Keys.ControlC:
                done.set()

    with input.raw_mode():
        with input.attach(keys_ready):
            await done.wait() 
开发者ID:prompt-toolkit,项目名称:python-prompt-toolkit,代码行数:16,代码来源:debug_win_input.py

示例10: load_emacs_system_bindings

# 需要导入模块: from prompt_toolkit.keys import Keys [as 别名]
# 或者: from prompt_toolkit.keys.Keys import ControlC [as 别名]
def load_emacs_system_bindings():
    registry = ConditionalRegistry(Registry(), EmacsMode())
    handle = registry.add_binding

    has_focus = HasFocus(SYSTEM_BUFFER)

    @handle(Keys.Escape, '!', filter= ~has_focus)
    def _(event):
        """
        M-'!' opens the system prompt.
        """
        event.cli.push_focus(SYSTEM_BUFFER)

    @handle(Keys.Escape, filter=has_focus)
    @handle(Keys.ControlG, filter=has_focus)
    @handle(Keys.ControlC, filter=has_focus)
    def _(event):
        """
        Cancel system prompt.
        """
        event.cli.buffers[SYSTEM_BUFFER].reset()
        event.cli.pop_focus()

    @handle(Keys.ControlJ, filter=has_focus)
    def _(event):
        """
        Run system command.
        """
        system_line = event.cli.buffers[SYSTEM_BUFFER]
        event.cli.run_system_command(system_line.text)
        system_line.reset(append_to_history=True)

        # Focus previous buffer again.
        event.cli.pop_focus()

    return registry 
开发者ID:bkerler,项目名称:android_universal,代码行数:38,代码来源:emacs.py

示例11: load_vi_system_bindings

# 需要导入模块: from prompt_toolkit.keys import Keys [as 别名]
# 或者: from prompt_toolkit.keys.Keys import ControlC [as 别名]
def load_vi_system_bindings():
    registry = ConditionalRegistry(Registry(), ViMode())
    handle = registry.add_binding

    has_focus = filters.HasFocus(SYSTEM_BUFFER)
    navigation_mode = ViNavigationMode()

    @handle('!', filter=~has_focus & navigation_mode)
    def _(event):
        """
        '!' opens the system prompt.
        """
        event.cli.push_focus(SYSTEM_BUFFER)
        event.cli.vi_state.input_mode = InputMode.INSERT

    @handle(Keys.Escape, filter=has_focus)
    @handle(Keys.ControlC, filter=has_focus)
    def _(event):
        """
        Cancel system prompt.
        """
        event.cli.vi_state.input_mode = InputMode.NAVIGATION
        event.cli.buffers[SYSTEM_BUFFER].reset()
        event.cli.pop_focus()

    @handle(Keys.ControlJ, filter=has_focus)
    def _(event):
        """
        Run system command.
        """
        event.cli.vi_state.input_mode = InputMode.NAVIGATION

        system_buffer = event.cli.buffers[SYSTEM_BUFFER]
        event.cli.run_system_command(system_buffer.text)
        system_buffer.reset(append_to_history=True)

        # Focus previous buffer again.
        event.cli.pop_focus()

    return registry 
开发者ID:bkerler,项目名称:android_universal,代码行数:42,代码来源:vi.py


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