Beispiel #1
0
def load_modified_bindings(registry, filter=Always()):
    handle = create_handle_decorator(registry, filter)
    has_selection = HasSelection()

    def at_the_end(b):
        text = b.document.text_after_cursor
        return text == '' or (text.isspace() and not '\n' in text)

    def lexes(b):
        try:
            tokenize(b.text)
        except Exception:
            return False
        return True

    @handle(Keys.ControlJ,
            filter=~has_selection & IsMultiline() & ~HasSearch(),
            save_before=False)
    def _(event):
        b = event.current_buffer

        # We don't need full validation here, just test if hy
        # can lex the text
        if at_the_end(b) and lexes(b):
            b.document = Document(text=b.text.rstrip(),
                                  cursor_position=len(b.text.rstrip()))

            b.accept_action.validate_and_handle(event.cli, b)
        else:
            auto_newline(b)

    @handle(Keys.ControlJ,
            filter=~has_selection & ~IsMultiline() & ~HasSearch(),
            save_before=False)
    def _(event):
        b = event.current_buffer
        if at_the_end(b) and lexes(b):
            b.accept_action.validate_and_handle(event.cli, b)
        else:
            auto_newline(b)
Beispiel #2
0
    def __init__(self, editor):
        def get_tokens(cli):
            eb = editor.window_arrangement.active_editor_buffer

            lineno = eb.buffer.document.cursor_position_row
            errors = eb.report_errors

            for e in errors:
                if e.lineno == lineno:
                    return e.message_token_list

            return []

        super(ReportMessageToolbar, self).__init__(
                get_tokens,
                filter=~HasFocus(COMMAND_BUFFER) & ~HasSearch() & ~HasFocus('system'))
Beispiel #3
0
 def __init__(self, vi_mode=False):
     super(SearchToolbar, self).__init__(content=Window(
         SearchToolbarControl(vi_mode=vi_mode),
         height=LayoutDimension.exact(1)),
                                         filter=HasSearch() & ~IsDone())
Beispiel #4
0
    def __init__(self, pager: "Pager") -> None:
        self.pager = pager
        self.dynamic_body = _DynamicBody(pager)

        # Build an interface.
        has_colon = HasColon(pager)

        self.examine_control: BufferControl = BufferControl(
            buffer=pager.examine_buffer,
            lexer=SimpleLexer(style="class:examine,examine-text"),
            input_processors=[
                BeforeInput(lambda: [("class:examine", " Examine: ")])
            ],
        )

        self.search_toolbar = SearchToolbar(vi_mode=True,
                                            search_buffer=pager.search_buffer)

        self.container = FloatContainer(
            content=HSplit([
                ConditionalContainer(
                    content=Titlebar(pager),
                    filter=Condition(lambda: pager.display_titlebar),
                ),
                self.dynamic_body,
                self.search_toolbar,
                SystemToolbar(),
                ConditionalContainer(
                    content=VSplit([
                        Window(
                            height=1,
                            content=FormattedTextControl(
                                self._get_statusbar_left_tokens),
                            style="class:statusbar",
                        ),
                        Window(
                            height=1,
                            content=FormattedTextControl(
                                self._get_statusbar_right_tokens),
                            style="class:statusbar.cursorposition",
                            align=WindowAlign.RIGHT,
                        ),
                    ]),
                    filter=~HasSearch()
                    & ~has_focus(SYSTEM_BUFFER)
                    & ~has_colon
                    & ~has_focus("EXAMINE"),
                ),
                ConditionalContainer(
                    content=Window(FormattedTextControl(" :"),
                                   height=1,
                                   style="class:examine"),
                    filter=has_colon,
                ),
                ConditionalContainer(
                    content=Window(self.examine_control,
                                   height=1,
                                   style="class:examine"),
                    filter=has_focus(pager.examine_buffer),
                ),
            ]),
            floats=[
                Float(right=0, height=1, bottom=1, content=_Arg()),
                Float(
                    bottom=1,
                    left=0,
                    right=0,
                    height=1,
                    content=ConditionalContainer(
                        content=MessageToolbarBar(pager),
                        filter=Condition(lambda: bool(pager.message)),
                    ),
                ),
                Float(
                    right=0,
                    height=1,
                    bottom=1,
                    content=ConditionalContainer(
                        content=FormattedTextToolbar(
                            lambda: [("class:loading", " Loading... ")], ),
                        filter=Condition(lambda: pager.current_source_info.
                                         waiting_for_input_stream),
                    ),
                ),
                Float(xcursor=True,
                      ycursor=True,
                      content=MultiColumnCompletionsMenu()),
            ],
        )
 def __init__(self):
     super(SearchToolbar, self).__init__(SearchToolbarControl(),
                                         height=LayoutDimension.exact(1),
                                         filter=HasSearch() & ~IsDone())
Beispiel #6
0
    def __init__(self, pager):
        self.pager = pager
        self.dynamic_body = _DynamicBody(pager)

        # Build an interface.
        has_colon = HasColon(pager)

        self.container = FloatContainer(content=HSplit([
            Titlebar(pager),
            self.dynamic_body,
            SearchToolbar(vi_mode=True),
            SystemToolbar(),
            ConditionalContainer(content=VSplit([
                Window(height=D.exact(1),
                       content=TokenListControl(
                           self._get_statusbar_left_tokens,
                           default_char=Char(' ', Token.Statusbar))),
                Window(height=D.exact(1),
                       content=TokenListControl(
                           self._get_statusbar_right_tokens,
                           align_right=True,
                           default_char=Char(' ', Token.Statusbar))),
            ]),
                                 filter=~HasSearch() & ~HasFocus(SYSTEM_BUFFER)
                                 & ~has_colon & ~HasFocus('EXAMINE')),
            ConditionalContainer(content=TokenListToolbar(
                lambda cli: [(Token.Statusbar, ' :')],
                default_char=Char(token=Token.Statusbar)),
                                 filter=has_colon),
            ConditionalContainer(content=Window(BufferControl(
                buffer_name='EXAMINE',
                default_char=Char(token=Token.Toolbar.Examine),
                lexer=SimpleLexer(default_token=Token.Toolbar.Examine.Text),
                input_processors=[
                    BeforeInput(
                        lambda cli: [(Token.Toolbar.Examine, ' Examine: ')]),
                ]),
                                                height=D.exact(1)),
                                 filter=HasFocus('EXAMINE')),
            ConditionalContainer(content=Window(BufferControl(
                buffer_name='PATTERN_FILTER',
                default_char=Char(token=Token.Toolbar.Search),
                lexer=SimpleLexer(default_token=Token.Toolbar.Search.Text),
                input_processors=[
                    BeforeInput(lambda cli: [(Token.Toolbar.Search, '&/')]),
                ]),
                                                height=D.exact(1)),
                                 filter=HasFocus('PATTERN_FILTER')),
        ]),
                                        floats=[
                                            Float(right=0,
                                                  height=1,
                                                  bottom=1,
                                                  content=_Arg()),
                                            Float(bottom=1,
                                                  left=0,
                                                  right=0,
                                                  height=1,
                                                  content=MessageToolbarBar(
                                                      pager)),
                                            Float(
                                                right=0,
                                                height=1,
                                                bottom=1,
                                                content=ConditionalContainer(
                                                    content=TokenListToolbar(
                                                        lambda cli: [
                                                            (Token.Loading,
                                                             ' Loading... ')
                                                        ],
                                                        default_char=Char(
                                                            token=Token.
                                                            Statusbar)),
                                                    filter=Condition(
                                                        lambda cli: pager.
                                                        waiting_for_input_stream
                                                    ))),
                                            Float(
                                                xcursor=True,
                                                ycursor=True,
                                                content=
                                                MultiColumnCompletionsMenu()),
                                        ])
Beispiel #7
0
 def __init__(self):
     super(VimInputBar,
           self).__init__(BufferControl(buffer_name='vim-input'),
                          height=LayoutDimension.exact(1),
                          filter=~HasSearch() & ~HasFocus('system'))