예제 #1
0
 def quit(self, return_code):
     self.cached_values['last_search'] = self.line_edit.current_input
     self.remove_mark()
     if return_code:
         for match_arg in self.match_args():
             remote_control.main(['', 'scroll-window', match_arg, 'end'])
     self.quit_loop(return_code)
예제 #2
0
def main(args):
    try:
        remote_control.main([
            '', 'resize-window', '--self', '--axis=vertical', '--increment',
            '-100'
        ])
    except:
        pass

    error = ''
    if len(args) < 2 or not args[1].isdigit():
        error = 'Error: Window id must be provided as the first argument.'

    window_id = int(args[1])
    window_ids = [window_id]
    if len(args) > 2 and args[2] == '--all-windows':
        ls_output = run(['kitty', '@', 'ls'], stdout=PIPE)
        ls_json = json.loads(ls_output.stdout.decode())
        current_tab = None
        for os_window in ls_json:
            for tab in os_window['tabs']:
                for kitty_window in tab['windows']:
                    if kitty_window['id'] == window_id:
                        current_tab = tab
        if current_tab:
            window_ids = [
                w['id'] for w in current_tab['windows'] if not w['is_focused']
            ]
        else:
            error = 'Error: Could not find the window id provided.'

    loop = Loop()
    with cached_values_for('search') as cached_values:
        handler = Search(cached_values, window_ids, error)
        loop.loop(handler)
예제 #3
0
    def on_key(self, key_event):
        if self.text_marked and key_event.key not in [TAB, 'LEFT_CONTROL', 'RIGHT_CONTROL', 'LEFT_ALT', 'RIGHT_ALT', 'LEFT_SUPER', 'RIGHT_SUPER']:
            self.text_marked = False
            self.refresh()

        if self.line_edit.on_key(key_event):
            self.refresh()
            return

        if key_event.type is not RELEASE:
            if key_event.mods == CTRL and key_event.key == 'U':
                self.line_edit.clear()
                self.refresh()
            elif key_event.mods == CTRL and key_event.key == 'A':
                self.line_edit.home()
                self.refresh()
            elif key_event.mods == CTRL and key_event.key == 'E':
                self.line_edit.end()
                self.refresh()
            elif key_event.key is TAB:
                self.switch_mode()
                self.refresh()
            elif key_event.key is UP:
                for match_arg in self.match_args():
                    remote_control.main(['', 'kitten', match_arg, 'scroll_mark.py'])
            elif key_event.key is DOWN:
                for match_arg in self.match_args():
                    remote_control.main(['', 'kitten', match_arg, 'scroll_mark.py', 'next'])

        if key_event is enter_key:
            self.quit(0)
        elif key_event.type is RELEASE:
            if not key_event.mods:
                if key_event.key is ESCAPE:
                    self.quit(1)
예제 #4
0
 def mark(self):
     if not self.window_ids:
         return
     text = self.line_edit.current_input
     if text:
         match_case = 'i' if text.islower() else ''
         match_type = match_case + self.mode
         for match_arg in self.match_args():
             remote_control.main(['', 'create-marker', match_arg, match_type, '1', text])
     else:
         self.remove_mark()
예제 #5
0
    def on_key(self, key_event):
        if self.text_marked and key_event.key not in [
                'TAB', 'LEFT_CONTROL', 'RIGHT_CONTROL', 'LEFT_ALT',
                'RIGHT_ALT', 'LEFT_SHIFT', 'RIGHT_SHIFT', 'LEFT_SUPER',
                'RIGHT_SUPER'
        ]:
            self.text_marked = False
            self.refresh()

        if self.line_edit.on_key(key_event):
            self.refresh()
            return

        if key_event.matches('ctrl+u'):
            self.line_edit.clear()
            self.refresh()
        elif key_event.matches('ctrl+a'):
            self.line_edit.home()
            self.refresh()
        elif key_event.matches('ctrl+e'):
            self.line_edit.end()
            self.refresh()
        elif key_event.matches('tab'):
            self.switch_mode()
            self.refresh()
        elif key_event.matches('up'):
            for match_arg in self.match_args():
                remote_control.main(
                    ['', 'kitten', match_arg,
                     str(SCROLLMARK_FILE)])
        elif key_event.matches('down'):
            for match_arg in self.match_args():
                remote_control.main(
                    ['', 'kitten', match_arg,
                     str(SCROLLMARK_FILE), 'next'])
        elif key_event.matches('enter'):
            self.quit(0)
        elif key_event.matches('esc'):
            self.quit(1)
예제 #6
0
 def remove_mark(self):
     for match_arg in self.match_args():
         remote_control.main(['', 'remove-marker', match_arg])
예제 #7
0
    def on_key(self, key_event):
        if self.text_marked and key_event.key not in [
                'TAB', 'LEFT_CONTROL', 'RIGHT_CONTROL', 'LEFT_ALT',
                'RIGHT_ALT', 'LEFT_SHIFT', 'RIGHT_SHIFT', 'LEFT_SUPER',
                'RIGHT_SUPER'
        ]:
            self.text_marked = False
            self.refresh()

        if self.line_edit.on_key(key_event):
            self.refresh()
            return

        if key_event.matches('ctrl+u'):
            self.line_edit.clear()
            self.refresh()
        elif key_event.matches('ctrl+a'):
            self.line_edit.home()
            self.refresh()
        elif key_event.matches('ctrl+e'):
            self.line_edit.end()
            self.refresh()
        elif key_event.matches('ctrl+backspace') or key_event.matches(
                'ctrl+w'):
            before, _ = self.line_edit.split_at_cursor()

            try:
                start, _ = reindex(before, SPACE_PATTERN_END, right=True)
            except ValueError:
                start = -1

            try:
                space = before[:start].rindex(' ')
            except ValueError:
                space = 0
            self.line_edit.backspace(len(before) - space)
            self.refresh()
        elif key_event.matches('ctrl+left') or key_event.matches('ctrl+b'):
            before, _ = self.line_edit.split_at_cursor()
            try:
                start, _ = reindex(before, SPACE_PATTERN_END, right=True)
            except ValueError:
                start = -1

            try:
                space = before[:start].rindex(' ')
            except ValueError:
                space = 0
            self.line_edit.left(len(before) - space)
            self.refresh()
        elif key_event.matches('ctrl+right') or key_event.matches('ctrl+f'):
            _, after = self.line_edit.split_at_cursor()
            try:
                _, end = reindex(after, SPACE_PATTERN_START)
            except ValueError:
                end = 0

            try:
                space = after[end:].index(' ') + 1
            except ValueError:
                space = len(after)
            self.line_edit.right(space)
            self.refresh()
        elif key_event.matches('alt+backspace') or key_event.matches('alt+w'):
            before, _ = self.line_edit.split_at_cursor()

            try:
                start, _ = reindex(before,
                                   NON_ALPHANUM_PATTERN_END,
                                   right=True)
            except ValueError:
                start = -1
            else:
                self.line_edit.backspace(len(before) - start)
                self.refresh()
                return

            try:
                start, _ = reindex(before, NON_ALPHANUM_PATTERN, right=True)
            except ValueError:
                self.line_edit.backspace(len(before))
                self.refresh()
                return

            self.line_edit.backspace(len(before) - (start + 1))
            self.refresh()
        elif key_event.matches('alt+left') or key_event.matches('alt+b'):
            before, _ = self.line_edit.split_at_cursor()

            try:
                start, _ = reindex(before,
                                   NON_ALPHANUM_PATTERN_END,
                                   right=True)
            except ValueError:
                start = -1
            else:
                self.line_edit.left(len(before) - start)
                self.refresh()
                return

            try:
                start, _ = reindex(before, NON_ALPHANUM_PATTERN, right=True)
            except ValueError:
                self.line_edit.left(len(before))
                self.refresh()
                return

            self.line_edit.left(len(before) - (start + 1))
            self.refresh()
        elif key_event.matches('alt+right') or key_event.matches('alt+f'):
            _, after = self.line_edit.split_at_cursor()

            try:
                _, end = reindex(after, NON_ALPHANUM_PATTERN_START)
            except ValueError:
                end = 0
            else:
                self.line_edit.right(end)
                self.refresh()
                return

            try:
                _, end = reindex(after, NON_ALPHANUM_PATTERN)
            except ValueError:
                self.line_edit.right(len(after))
                self.refresh()
                return

            self.line_edit.right(end - 1)
            self.refresh()
        elif key_event.matches('tab'):
            self.switch_mode()
            self.refresh()
        elif key_event.matches('up'):
            for match_arg in self.match_args():
                remote_control.main(
                    ['', 'kitten', match_arg,
                     str(SCROLLMARK_FILE)])
        elif key_event.matches('down'):
            for match_arg in self.match_args():
                remote_control.main(
                    ['', 'kitten', match_arg,
                     str(SCROLLMARK_FILE), 'next'])
        elif key_event.matches('enter'):
            self.quit(0)
        elif key_event.matches('esc'):
            self.quit(1)