コード例 #1
0
    def __init__(self,
                 registry=None,
                 enable_vi_mode=Never(),
                 enable_system_bindings=Never(),
                 enable_search=Always(),
                 enable_open_in_editor=Never(),
                 enable_all=Always()):

        # Accept both Filters and booleans as input.
        enable_vi_mode = to_cli_filter(enable_vi_mode)
        enable_system_bindings = to_cli_filter(enable_system_bindings)
        enable_open_in_editor = to_cli_filter(enable_open_in_editor)
        enable_all = to_cli_filter(enable_all)

        # Create registry.
        assert registry is None or isinstance(registry, Registry)
        self.registry = registry or Registry()

        # Emacs mode filter is the opposite of Vi mode.
        enable_emacs_mode = ~enable_vi_mode

        # Vi state. (Object to keep track of in which Vi mode we are.)
        self.vi_state = ViState()

        # Load basic bindings.
        load_basic_bindings(self.registry, enable_all)

        load_basic_system_bindings(self.registry,
                                   enable_system_bindings & enable_all)

        # Load emacs bindings.
        load_emacs_bindings(self.registry, enable_emacs_mode & enable_all)

        load_emacs_open_in_editor_bindings(
            self.registry,
            enable_emacs_mode & enable_open_in_editor & enable_all)

        load_emacs_search_bindings(
            self.registry, enable_emacs_mode & enable_search & enable_all)

        load_emacs_system_bindings(
            self.registry,
            enable_emacs_mode & enable_system_bindings & enable_all)

        # Load Vi bindings.
        load_vi_bindings(self.registry,
                         self.vi_state,
                         enable_visual_key=~enable_open_in_editor,
                         filter=enable_vi_mode & enable_all)

        load_vi_open_in_editor_bindings(
            self.registry, self.vi_state,
            enable_vi_mode & enable_open_in_editor & enable_all)

        load_vi_search_bindings(self.registry, self.vi_state,
                                enable_vi_mode & enable_search & enable_all)

        load_vi_system_bindings(
            self.registry, self.vi_state,
            enable_vi_mode & enable_system_bindings & enable_all)
コード例 #2
0
    def __init__(self, registry=None, enable_vi_mode=Never(), vi_state=None,
                 enable_system_bindings=Never(), enable_search=Always(),
                 enable_open_in_editor=Never(), enable_all=Always()):

        assert registry is None or isinstance(registry, Registry)
        assert vi_state is None or isinstance(vi_state, ViState)

        # Create registry.
        self.registry = registry or Registry()

        # Vi state. (Object to keep track of in which Vi mode we are.)
        self.vi_state = vi_state or ViState()

        # Accept both Filters and booleans as input.
        enable_vi_mode = to_cli_filter(enable_vi_mode)
        enable_system_bindings = to_cli_filter(enable_system_bindings)
        enable_open_in_editor = to_cli_filter(enable_open_in_editor)
        enable_all = to_cli_filter(enable_all)

        # Emacs mode filter is the opposite of Vi mode.
        enable_emacs_mode = ~enable_vi_mode

        # Load basic bindings.
        load_basic_bindings(self.registry, enable_all)

        load_basic_system_bindings(self.registry,
            enable_system_bindings & enable_all)

        # Load emacs bindings.
        load_emacs_bindings(self.registry, enable_emacs_mode & enable_all)

        load_emacs_open_in_editor_bindings(
            self.registry, enable_emacs_mode & enable_open_in_editor & enable_all)

        load_emacs_search_bindings(
            self.registry, enable_emacs_mode & enable_search & enable_all)

        load_emacs_system_bindings(
            self.registry, enable_emacs_mode & enable_system_bindings & enable_all)

        # Load Vi bindings.
        load_vi_bindings(self.registry, self.vi_state, enable_visual_key=~enable_open_in_editor,
                         filter=enable_vi_mode & enable_all)

        load_vi_open_in_editor_bindings(
            self.registry, self.vi_state,
            enable_vi_mode & enable_open_in_editor & enable_all)

        load_vi_search_bindings(
            self.registry, self.vi_state,
            enable_vi_mode & enable_search & enable_all)

        load_vi_system_bindings(
            self.registry, self.vi_state,
            enable_vi_mode & enable_system_bindings & enable_all)
コード例 #3
0
def load_key_bindings():
    """
    Create a KeyBindings object that contains the default key bindings.
    """
    all_bindings = merge_key_bindings([
        # Load basic bindings.
        load_basic_bindings(),

        # Load emacs bindings.
        load_emacs_bindings(),
        load_emacs_search_bindings(),

        # Load Vi bindings.
        load_vi_bindings(),
        load_vi_search_bindings(),
    ])

    return merge_key_bindings([
        # Make sure that the above key bindings are only active if the
        # currently focussed control is a `BufferControl`. For other controls, we
        # don't want these key bindings to intervene. (This would break "ptterm"
        # for instance, which handles 'Keys.Any' in the user control itself.)
        ConditionalKeyBindings(all_bindings, buffer_has_focus),

        # Active, even when no buffer has been focussed.
        load_mouse_bindings(),
        load_cpr_bindings(),
    ])
コード例 #4
0
def load_key_bindings():
    """
    Create a KeyBindings object that contains the default key bindings.
    """
    all_bindings = merge_key_bindings([
        # Load basic bindings.
        load_basic_bindings(),

        # Load emacs bindings.
        load_emacs_bindings(),
        load_emacs_search_bindings(),

        # Load Vi bindings.
        load_vi_bindings(),
        load_vi_search_bindings(),
    ])

    return merge_key_bindings([
        # Make sure that the above key bindings are only active if the
        # currently focused control is a `BufferControl`. For other controls, we
        # don't want these key bindings to intervene. (This would break "ptterm"
        # for instance, which handles 'Keys.Any' in the user control itself.)
        ConditionalKeyBindings(all_bindings, buffer_has_focus),

        # Active, even when no buffer has been focused.
        load_mouse_bindings(),
        load_cpr_bindings(),
    ])
コード例 #5
0
    def __init__(self,
                 registry=None,
                 enable_vi_mode=Never(),
                 enable_system_prompt=Never(),
                 enable_search=Always(),
                 enable_open_in_editor=Never()):

        assert registry is None or isinstance(registry, Registry)
        assert isinstance(enable_vi_mode, CLIFilter)
        assert isinstance(enable_system_prompt, CLIFilter)
        assert isinstance(enable_open_in_editor, CLIFilter)

        self.registry = registry or Registry()

        # Emacs mode filter is the opposite of Vi mode.
        enable_emacs_mode = ~enable_vi_mode

        # Vi state. (Object to keep track of in which Vi mode we are.)
        self.vi_state = ViState()

        # Load emacs bindings.
        load_emacs_bindings(self.registry, enable_emacs_mode)

        load_emacs_open_in_editor_bindings(
            self.registry, enable_emacs_mode & enable_open_in_editor)

        load_emacs_search_bindings(self.registry,
                                   enable_emacs_mode & enable_search)

        load_emacs_system_bindings(self.registry,
                                   enable_emacs_mode & enable_system_prompt)

        # Load Vi bindings.
        load_vi_bindings(self.registry, self.vi_state, enable_vi_mode)

        load_vi_open_in_editor_bindings(self.registry, self.vi_state,
                                        enable_vi_mode & enable_open_in_editor)

        load_vi_search_bindings(self.registry, self.vi_state,
                                enable_vi_mode & enable_search)

        load_vi_system_bindings(self.registry, self.vi_state,
                                enable_vi_mode & enable_system_prompt)
コード例 #6
0
    def __init__(self, registry=None, enable_vi_mode=False,
                 enable_system_prompt=False, enable_search=True,
                 enable_open_in_editor=False):

        self.registry = registry or Registry()

        # Flags. You can change these anytime.
        self.enable_vi_mode = enable_vi_mode
        self.enable_system_prompt = enable_system_prompt
        self.enable_search = enable_search
        self.enable_open_in_editor = enable_open_in_editor

        # Create set of filters to enable/disable sets of key bindings at
        # runtime.
        vi_mode_enabled = ViModeEnabled(self)
        emacs_mode_enabled = ~ vi_mode_enabled
        system_prompt_enabled = SystemPromptEnabled(self)
        search_enabled = SearchEnabled(self)
        open_in_editor_enabled = OpenInEditorEnabled(self)

        # Vi state. (Object to keep track of in which Vi mode we are.)
        self.vi_state = ViState()

        # Load all bindings in the registry with the correct filters.
        load_emacs_bindings(self.registry, emacs_mode_enabled)
        load_emacs_open_in_editor_bindings(
            self.registry, emacs_mode_enabled & open_in_editor_enabled)
        load_emacs_search_bindings(
            self.registry, emacs_mode_enabled & search_enabled)
        load_emacs_system_bindings(
            self.registry, emacs_mode_enabled & system_prompt_enabled)

        load_vi_bindings(self.registry, self.vi_state, vi_mode_enabled)
        load_vi_open_in_editor_bindings(
            self.registry, self.vi_state,
            vi_mode_enabled & open_in_editor_enabled)
        load_vi_search_bindings(
            self.registry, self.vi_state,
            vi_mode_enabled & search_enabled)
        load_vi_system_bindings(
            self.registry, self.vi_state,
            vi_mode_enabled & system_prompt_enabled)
コード例 #7
0
ファイル: manager.py プロジェクト: 0038lana/Test-Task
    def __init__(self, registry=None,
                 enable_vi_mode=None,  # (`enable_vi_mode` is deprecated.)
                 get_search_state=None,
                 enable_abort_and_exit_bindings=False,
                 enable_system_bindings=False, enable_search=False,
                 enable_open_in_editor=False, enable_extra_page_navigation=False,
                 enable_auto_suggest_bindings=False,
                 enable_all=True):

        assert registry is None or isinstance(registry, Registry)
        assert get_search_state is None or callable(get_search_state)

        # Create registry.
        self.registry = registry or Registry()

        # Accept both Filters and booleans as input.
        enable_abort_and_exit_bindings = to_cli_filter(enable_abort_and_exit_bindings)
        enable_system_bindings = to_cli_filter(enable_system_bindings)
        enable_search = to_cli_filter(enable_search)
        enable_open_in_editor = to_cli_filter(enable_open_in_editor)
        enable_extra_page_navigation = to_cli_filter(enable_extra_page_navigation)
        enable_auto_suggest_bindings = to_cli_filter(enable_auto_suggest_bindings)
        enable_all = to_cli_filter(enable_all)

        # Load basic bindings.
        load_basic_bindings(self.registry, enable_all)
        load_mouse_bindings(self.registry, enable_all)

        load_abort_and_exit_bindings(
            self.registry, enable_abort_and_exit_bindings & enable_all)

        load_basic_system_bindings(self.registry,
            enable_system_bindings & enable_all)

        # Load emacs bindings.
        load_emacs_bindings(self.registry, enable_all)

        load_emacs_open_in_editor_bindings(
            self.registry, enable_open_in_editor & enable_all)

        load_emacs_search_bindings(
            self.registry,
            filter=enable_search & enable_all,
            get_search_state=get_search_state)

        load_emacs_system_bindings(
            self.registry, enable_system_bindings & enable_all)

        load_extra_emacs_page_navigation_bindings(
            self.registry,
            enable_extra_page_navigation & enable_all)

        # Load Vi bindings.
        load_vi_bindings(
            self.registry, enable_visual_key=~enable_open_in_editor,
            filter=enable_all,
            get_search_state=get_search_state)

        load_vi_open_in_editor_bindings(
            self.registry,
            enable_open_in_editor & enable_all)

        load_vi_search_bindings(
            self.registry,
            filter=enable_search & enable_all,
            get_search_state=get_search_state)

        load_vi_system_bindings(
            self.registry,
            enable_system_bindings & enable_all)

        load_extra_vi_page_navigation_bindings(
            self.registry,
            enable_extra_page_navigation & enable_all)

        # Suggestion bindings.
        # (This has to come at the end, because the Vi bindings also have an
        # implementation for the "right arrow", but we really want the
        # suggestion binding when a suggestion is available.)
        load_auto_suggestion_bindings(
            self.registry,
            enable_auto_suggest_bindings & enable_all)
コード例 #8
0
def load_key_bindings(get_search_state=None,
                      enable_abort_and_exit_bindings=False,
                      enable_system_bindings=False,
                      enable_search=False,
                      enable_open_in_editor=False,
                      enable_extra_page_navigation=False,
                      enable_auto_suggest_bindings=False):
    """
    Create a Registry object that contains the default key bindings.

    :param enable_abort_and_exit_bindings: Filter to enable Ctrl-C and Ctrl-D.
    :param enable_system_bindings: Filter to enable the system bindings (meta-!
            prompt and Control-Z suspension.)
    :param enable_search: Filter to enable the search bindings.
    :param enable_open_in_editor: Filter to enable open-in-editor.
    :param enable_open_in_editor: Filter to enable open-in-editor.
    :param enable_extra_page_navigation: Filter for enabling extra page
        navigation. (Bindings for up/down scrolling through long pages, like in
        Emacs or Vi.)
    :param enable_auto_suggest_bindings: Filter to enable fish-style suggestions.
    """

    assert get_search_state is None or callable(get_search_state)

    # Accept both Filters and booleans as input.
    enable_abort_and_exit_bindings = to_cli_filter(
        enable_abort_and_exit_bindings)
    enable_system_bindings = to_cli_filter(enable_system_bindings)
    enable_search = to_cli_filter(enable_search)
    enable_open_in_editor = to_cli_filter(enable_open_in_editor)
    enable_extra_page_navigation = to_cli_filter(enable_extra_page_navigation)
    enable_auto_suggest_bindings = to_cli_filter(enable_auto_suggest_bindings)

    registry = MergedRegistry([
        # Load basic bindings.
        load_basic_bindings(),
        load_mouse_bindings(),
        ConditionalRegistry(load_abort_and_exit_bindings(),
                            enable_abort_and_exit_bindings),
        ConditionalRegistry(load_basic_system_bindings(),
                            enable_system_bindings),

        # Load emacs bindings.
        load_emacs_bindings(),
        ConditionalRegistry(load_emacs_open_in_editor_bindings(),
                            enable_open_in_editor),
        ConditionalRegistry(
            load_emacs_search_bindings(get_search_state=get_search_state),
            enable_search),
        ConditionalRegistry(load_emacs_system_bindings(),
                            enable_system_bindings),
        ConditionalRegistry(load_extra_emacs_page_navigation_bindings(),
                            enable_extra_page_navigation),

        # Load Vi bindings.
        load_vi_bindings(get_search_state=get_search_state),
        ConditionalRegistry(load_vi_open_in_editor_bindings(),
                            enable_open_in_editor),
        ConditionalRegistry(
            load_vi_search_bindings(get_search_state=get_search_state),
            enable_search),
        ConditionalRegistry(load_vi_system_bindings(), enable_system_bindings),
        ConditionalRegistry(load_extra_vi_page_navigation_bindings(),
                            enable_extra_page_navigation),

        # Suggestion bindings.
        # (This has to come at the end, because the Vi bindings also have an
        # implementation for the "right arrow", but we really want the
        # suggestion binding when a suggestion is available.)
        ConditionalRegistry(load_auto_suggestion_bindings(),
                            enable_auto_suggest_bindings),
    ])

    return registry
コード例 #9
0
    def __init__(self,
                 registry=None,
                 enable_vi_mode=False,
                 get_vi_state=None,
                 get_search_state=None,
                 enable_abort_and_exit_bindings=False,
                 enable_system_bindings=False,
                 enable_search=False,
                 enable_open_in_editor=False,
                 enable_extra_page_navigation=False,
                 enable_auto_suggest_bindings=False,
                 enable_all=True):

        assert registry is None or isinstance(registry, Registry)
        assert get_vi_state is None or callable(get_vi_state)
        assert get_search_state is None or callable(get_search_state)

        # Create registry.
        self.registry = registry or Registry()

        # Vi state. (Object to keep track of in which Vi mode we are.)
        if get_vi_state is None:
            vi_state = ViState(
            )  # Stateful. Should be defined outside the function below.

            def get_vi_state(cli):
                return vi_state

        self.get_vi_state = get_vi_state

        # Accept both Filters and booleans as input.
        enable_vi_mode = to_cli_filter(enable_vi_mode)
        enable_abort_and_exit_bindings = to_cli_filter(
            enable_abort_and_exit_bindings)
        enable_system_bindings = to_cli_filter(enable_system_bindings)
        enable_search = to_cli_filter(enable_search)
        enable_open_in_editor = to_cli_filter(enable_open_in_editor)
        enable_extra_page_navigation = to_cli_filter(
            enable_extra_page_navigation)
        enable_auto_suggest_bindings = to_cli_filter(
            enable_auto_suggest_bindings)
        enable_all = to_cli_filter(enable_all)

        # Emacs mode filter is the opposite of Vi mode.
        enable_emacs_mode = ~enable_vi_mode

        # Load basic bindings.
        load_basic_bindings(self.registry, enable_all)

        load_abort_and_exit_bindings(
            self.registry, enable_abort_and_exit_bindings & enable_all)

        load_basic_system_bindings(self.registry,
                                   enable_system_bindings & enable_all)

        # Load emacs bindings.
        load_emacs_bindings(self.registry, enable_emacs_mode & enable_all)

        load_emacs_open_in_editor_bindings(
            self.registry,
            enable_emacs_mode & enable_open_in_editor & enable_all)

        load_emacs_search_bindings(self.registry,
                                   filter=enable_emacs_mode & enable_search
                                   & enable_all,
                                   get_search_state=get_search_state)

        load_emacs_system_bindings(
            self.registry,
            enable_emacs_mode & enable_system_bindings & enable_all)

        load_extra_emacs_page_navigation_bindings(
            self.registry,
            enable_emacs_mode & enable_extra_page_navigation & enable_all)

        # Load Vi bindings.
        load_vi_bindings(self.registry,
                         self.get_vi_state,
                         enable_visual_key=~enable_open_in_editor,
                         filter=enable_vi_mode & enable_all,
                         get_search_state=get_search_state)

        load_vi_open_in_editor_bindings(
            self.registry, self.get_vi_state,
            enable_vi_mode & enable_open_in_editor & enable_all)

        load_vi_search_bindings(self.registry,
                                self.get_vi_state,
                                filter=enable_vi_mode & enable_search
                                & enable_all,
                                get_search_state=get_search_state)

        load_vi_system_bindings(
            self.registry, self.get_vi_state,
            enable_vi_mode & enable_system_bindings & enable_all)

        load_extra_vi_page_navigation_bindings(
            self.registry,
            enable_vi_mode & enable_extra_page_navigation & enable_all)

        # Suggestion bindings.
        # (This has to come at the end, because the Vi bindings also have an
        # implementation for the "right arrow", but we really want the
        # suggestion binding when a suggestion is available.)
        load_auto_suggestion_bindings(
            self.registry, enable_auto_suggest_bindings & enable_all)
コード例 #10
0
ファイル: manager.py プロジェクト: RevinKey/Slyp
    def __init__(self, registry=None, enable_vi_mode=False, get_vi_state=None,
                 get_search_state=None,
                 enable_abort_and_exit_bindings=False,
                 enable_system_bindings=False, enable_search=False,
                 enable_open_in_editor=False, enable_extra_page_navigation=False,
                 enable_auto_suggest_bindings=False,
                 enable_all=True):

        assert registry is None or isinstance(registry, Registry)
        assert get_vi_state is None or callable(get_vi_state)
        assert get_search_state is None or callable(get_search_state)

        # Create registry.
        self.registry = registry or Registry()

        # Vi state. (Object to keep track of in which Vi mode we are.)
        if get_vi_state is None:
            vi_state = ViState()  # Stateful. Should be defined outside the function below.

            def get_vi_state(cli):
                return vi_state

        self.get_vi_state = get_vi_state

        # Accept both Filters and booleans as input.
        enable_vi_mode = to_cli_filter(enable_vi_mode)
        enable_abort_and_exit_bindings = to_cli_filter(enable_abort_and_exit_bindings)
        enable_system_bindings = to_cli_filter(enable_system_bindings)
        enable_search = to_cli_filter(enable_search)
        enable_open_in_editor = to_cli_filter(enable_open_in_editor)
        enable_extra_page_navigation = to_cli_filter(enable_extra_page_navigation)
        enable_auto_suggest_bindings = to_cli_filter(enable_auto_suggest_bindings)
        enable_all = to_cli_filter(enable_all)

        # Emacs mode filter is the opposite of Vi mode.
        enable_emacs_mode = ~enable_vi_mode

        # Load basic bindings.
        load_basic_bindings(self.registry, enable_all)

        load_abort_and_exit_bindings(
            self.registry, enable_abort_and_exit_bindings & enable_all)

        load_basic_system_bindings(self.registry,
            enable_system_bindings & enable_all)

        # Load emacs bindings.
        load_emacs_bindings(self.registry, enable_emacs_mode & enable_all)

        load_emacs_open_in_editor_bindings(
            self.registry, enable_emacs_mode & enable_open_in_editor & enable_all)

        load_emacs_search_bindings(
            self.registry,
            filter=enable_emacs_mode & enable_search & enable_all,
            get_search_state=get_search_state)

        load_emacs_system_bindings(
            self.registry, enable_emacs_mode & enable_system_bindings & enable_all)

        load_extra_emacs_page_navigation_bindings(
            self.registry,
            enable_emacs_mode & enable_extra_page_navigation & enable_all)

        # Load Vi bindings.
        load_vi_bindings(
            self.registry, self.get_vi_state, enable_visual_key=~enable_open_in_editor,
            filter=enable_vi_mode & enable_all,
            get_search_state=get_search_state)

        load_vi_open_in_editor_bindings(
            self.registry, self.get_vi_state,
            enable_vi_mode & enable_open_in_editor & enable_all)

        load_vi_search_bindings(
            self.registry, self.get_vi_state,
            filter=enable_vi_mode & enable_search & enable_all,
            get_search_state=get_search_state)

        load_vi_system_bindings(
            self.registry, self.get_vi_state,
            enable_vi_mode & enable_system_bindings & enable_all)

        load_extra_vi_page_navigation_bindings(
            self.registry,
            enable_vi_mode & enable_extra_page_navigation & enable_all)

        # Suggestion bindings.
        # (This has to come at the end, because the Vi bindings also have an
        # implementation for the "right arrow", but we really want the
        # suggestion binding when a suggestion is available.)
        load_auto_suggestion_bindings(
            self.registry,
            enable_auto_suggest_bindings & enable_all)
コード例 #11
0
def load_key_bindings(
        get_search_state=None,
        enable_abort_and_exit_bindings=False,
        enable_system_bindings=False,
        enable_search=False,
        enable_open_in_editor=False,
        enable_extra_page_navigation=False,
        enable_auto_suggest_bindings=False):
    """
    Create a Registry object that contains the default key bindings.

    :param enable_abort_and_exit_bindings: Filter to enable Ctrl-C and Ctrl-D.
    :param enable_system_bindings: Filter to enable the system bindings (meta-!
            prompt and Control-Z suspension.)
    :param enable_search: Filter to enable the search bindings.
    :param enable_open_in_editor: Filter to enable open-in-editor.
    :param enable_open_in_editor: Filter to enable open-in-editor.
    :param enable_extra_page_navigation: Filter for enabling extra page
        navigation. (Bindings for up/down scrolling through long pages, like in
        Emacs or Vi.)
    :param enable_auto_suggest_bindings: Filter to enable fish-style suggestions.
    """

    assert get_search_state is None or callable(get_search_state)

    # Accept both Filters and booleans as input.
    enable_abort_and_exit_bindings = to_cli_filter(enable_abort_and_exit_bindings)
    enable_system_bindings = to_cli_filter(enable_system_bindings)
    enable_search = to_cli_filter(enable_search)
    enable_open_in_editor = to_cli_filter(enable_open_in_editor)
    enable_extra_page_navigation = to_cli_filter(enable_extra_page_navigation)
    enable_auto_suggest_bindings = to_cli_filter(enable_auto_suggest_bindings)

    registry = MergedRegistry([
        # Load basic bindings.
        load_basic_bindings(),
        load_mouse_bindings(),

        ConditionalRegistry(load_abort_and_exit_bindings(),
                            enable_abort_and_exit_bindings),

        ConditionalRegistry(load_basic_system_bindings(),
                            enable_system_bindings),

        # Load emacs bindings.
        load_emacs_bindings(),

        ConditionalRegistry(load_emacs_open_in_editor_bindings(),
                            enable_open_in_editor),

        ConditionalRegistry(load_emacs_search_bindings(get_search_state=get_search_state),
                            enable_search),

        ConditionalRegistry(load_emacs_system_bindings(),
                            enable_system_bindings),

        ConditionalRegistry(load_extra_emacs_page_navigation_bindings(),
                            enable_extra_page_navigation),

        # Load Vi bindings.
        load_vi_bindings(get_search_state=get_search_state),

        ConditionalRegistry(load_vi_open_in_editor_bindings(),
                            enable_open_in_editor),

        ConditionalRegistry(load_vi_search_bindings(get_search_state=get_search_state),
                            enable_search),

        ConditionalRegistry(load_vi_system_bindings(),
                            enable_system_bindings),

        ConditionalRegistry(load_extra_vi_page_navigation_bindings(),
                            enable_extra_page_navigation),

        # Suggestion bindings.
        # (This has to come at the end, because the Vi bindings also have an
        # implementation for the "right arrow", but we really want the
        # suggestion binding when a suggestion is available.)
        ConditionalRegistry(load_auto_suggestion_bindings(),
                            enable_auto_suggest_bindings),
    ])

    return registry
コード例 #12
0
ファイル: manager.py プロジェクト: jean/python-prompt-toolkit
    def __init__(self, registry=None,
                 enable_vi_mode=None,  # (`enable_vi_mode` is deprecated.)
                 get_search_state=None,
                 enable_abort_and_exit_bindings=False,
                 enable_system_bindings=False, enable_search=False,
                 enable_open_in_editor=False, enable_extra_page_navigation=False,
                 enable_auto_suggest_bindings=False,
                 enable_all=True):

        assert registry is None or isinstance(registry, Registry)
        assert get_search_state is None or callable(get_search_state)

        # Emacs/Vi mode.
        if enable_vi_mode is None:
            enable_vi_mode = InEditingMode(EditingMode.VI)
            enable_emacs_mode = InEditingMode(EditingMode.EMACS)
        else:
            # When `enable_vi_mode` is given, use this to determine whether Vi
            # or Emacs bindings are active, rather than using
            # CommandLineInterface.editing_mode.
            enable_vi_mode = to_cli_filter(enable_vi_mode)
            enable_emacs_mode = ~enable_vi_mode

        # Create registry.
        self.registry = registry or Registry()

        # Accept both Filters and booleans as input.
        enable_abort_and_exit_bindings = to_cli_filter(enable_abort_and_exit_bindings)
        enable_system_bindings = to_cli_filter(enable_system_bindings)
        enable_search = to_cli_filter(enable_search)
        enable_open_in_editor = to_cli_filter(enable_open_in_editor)
        enable_extra_page_navigation = to_cli_filter(enable_extra_page_navigation)
        enable_auto_suggest_bindings = to_cli_filter(enable_auto_suggest_bindings)
        enable_all = to_cli_filter(enable_all)

        # Load basic bindings.
        load_basic_bindings(self.registry, enable_all)

        load_abort_and_exit_bindings(
            self.registry, enable_abort_and_exit_bindings & enable_all)

        load_basic_system_bindings(self.registry,
            enable_system_bindings & enable_all)

        # Load emacs bindings.
        load_emacs_bindings(self.registry, enable_emacs_mode & enable_all)

        load_emacs_open_in_editor_bindings(
            self.registry, enable_emacs_mode & enable_open_in_editor & enable_all)

        load_emacs_search_bindings(
            self.registry,
            filter=enable_emacs_mode & enable_search & enable_all,
            get_search_state=get_search_state)

        load_emacs_system_bindings(
            self.registry, enable_emacs_mode & enable_system_bindings & enable_all)

        load_extra_emacs_page_navigation_bindings(
            self.registry,
            enable_emacs_mode & enable_extra_page_navigation & enable_all)

        # Load Vi bindings.
        load_vi_bindings(
            self.registry, enable_visual_key=~enable_open_in_editor,
            filter=enable_vi_mode & enable_all,
            get_search_state=get_search_state)

        load_vi_open_in_editor_bindings(
            self.registry,
            enable_vi_mode & enable_open_in_editor & enable_all)

        load_vi_search_bindings(
            self.registry,
            filter=enable_vi_mode & enable_search & enable_all,
            get_search_state=get_search_state)

        load_vi_system_bindings(
            self.registry,
            enable_vi_mode & enable_system_bindings & enable_all)

        load_extra_vi_page_navigation_bindings(
            self.registry,
            enable_vi_mode & enable_extra_page_navigation & enable_all)

        # Suggestion bindings.
        # (This has to come at the end, because the Vi bindings also have an
        # implementation for the "right arrow", but we really want the
        # suggestion binding when a suggestion is available.)
        load_auto_suggestion_bindings(
            self.registry,
            enable_auto_suggest_bindings & enable_all)
コード例 #13
0
ファイル: manager.py プロジェクト: AlexisMarie8330/Doll
    def __init__(
            self,
            registry=None,
            enable_vi_mode=None,  # (`enable_vi_mode` is deprecated.)
            get_search_state=None,
            enable_abort_and_exit_bindings=False,
            enable_system_bindings=False,
            enable_search=False,
            enable_open_in_editor=False,
            enable_extra_page_navigation=False,
            enable_auto_suggest_bindings=False,
            enable_all=True):

        assert registry is None or isinstance(registry, Registry)
        assert get_search_state is None or callable(get_search_state)

        # Create registry.
        self.registry = registry or Registry()

        # Accept both Filters and booleans as input.
        enable_abort_and_exit_bindings = to_cli_filter(
            enable_abort_and_exit_bindings)
        enable_system_bindings = to_cli_filter(enable_system_bindings)
        enable_search = to_cli_filter(enable_search)
        enable_open_in_editor = to_cli_filter(enable_open_in_editor)
        enable_extra_page_navigation = to_cli_filter(
            enable_extra_page_navigation)
        enable_auto_suggest_bindings = to_cli_filter(
            enable_auto_suggest_bindings)
        enable_all = to_cli_filter(enable_all)

        # Load basic bindings.
        load_basic_bindings(self.registry, enable_all)
        load_mouse_bindings(self.registry, enable_all)

        load_abort_and_exit_bindings(
            self.registry, enable_abort_and_exit_bindings & enable_all)

        load_basic_system_bindings(self.registry,
                                   enable_system_bindings & enable_all)

        # Load emacs bindings.
        load_emacs_bindings(self.registry, enable_all)

        load_emacs_open_in_editor_bindings(self.registry,
                                           enable_open_in_editor & enable_all)

        load_emacs_search_bindings(self.registry,
                                   filter=enable_search & enable_all,
                                   get_search_state=get_search_state)

        load_emacs_system_bindings(self.registry,
                                   enable_system_bindings & enable_all)

        load_extra_emacs_page_navigation_bindings(
            self.registry, enable_extra_page_navigation & enable_all)

        # Load Vi bindings.
        load_vi_bindings(self.registry,
                         enable_visual_key=~enable_open_in_editor,
                         filter=enable_all,
                         get_search_state=get_search_state)

        load_vi_open_in_editor_bindings(self.registry,
                                        enable_open_in_editor & enable_all)

        load_vi_search_bindings(self.registry,
                                filter=enable_search & enable_all,
                                get_search_state=get_search_state)

        load_vi_system_bindings(self.registry,
                                enable_system_bindings & enable_all)

        load_extra_vi_page_navigation_bindings(
            self.registry, enable_extra_page_navigation & enable_all)

        # Suggestion bindings.
        # (This has to come at the end, because the Vi bindings also have an
        # implementation for the "right arrow", but we really want the
        # suggestion binding when a suggestion is available.)
        load_auto_suggestion_bindings(
            self.registry, enable_auto_suggest_bindings & enable_all)