Beispiel #1
0
 def setup_caret(self, caret):
     if isinstance(caret, types.StringType) or isinstance(caret, types.UnicodeType):
         try:
             caret = int(caret)
         except ValueError:
             caret = None
     if caret is None or caret < 0 or caret > display.screen_len(self.query):
         caret = display.screen_len(self.query)
     self.caret = caret
Beispiel #2
0
 def setup_caret(self, caret):
     if isinstance(caret, six.string_types):
         try:
             caret = int(caret)
         except ValueError:
             caret = None
     if caret is None or caret < 0 or caret > display.screen_len(self.query):
         caret = display.screen_len(self.query)
     self.caret = caret
Beispiel #3
0
 def setup_caret(self, caret):
     if isinstance(caret, types.StringType) or isinstance(
             caret, types.UnicodeType):
         try:
             caret = int(caret)
         except ValueError:
             caret = None
     if caret is None or caret < 0 or caret > display.screen_len(
             self.query):
         caret = display.screen_len(self.query)
     self.caret = caret
Beispiel #4
0
    def display_result(self, y, result, is_current = False, is_marked = False):
        line, find_info, abs_idx = result

        if is_current:
            line_style = self.CANDIDATES_LINE_SELECTED
        elif is_marked:
            line_style = self.CANDIDATES_LINE_MARKED
        else:
            line_style = self.CANDIDATES_LINE_BASIC

        keyword_style = self.CANDIDATES_LINE_QUERY + line_style

        self.display_line(y, 0, line, style = line_style)

        if find_info is None:
            return
        for (subq, match_info) in find_info:
            for x_offset, subq_len in match_info:
                try:
                    x_offset_real = display.screen_len(line, beg = 0, end = x_offset)
                    self.display.add_string(line[x_offset:x_offset + subq_len],
                                            pos_y = y,
                                            pos_x = x_offset_real,
                                            style = keyword_style)
                except curses.error as e:
                    debug.log("addnstr", str(e) + " ({0})".format(y))
Beispiel #5
0
    def display_result(self, y, result, is_current=False, is_marked=False):
        line, find_info, abs_idx = result

        if is_current:
            line_style = self.CANDIDATES_LINE_SELECTED
        elif is_marked:
            line_style = self.CANDIDATES_LINE_MARKED
        else:
            line_style = self.CANDIDATES_LINE_BASIC

        keyword_style = self.CANDIDATES_LINE_QUERY + line_style

        self.display_line(y, 0, line, style=line_style)

        if find_info is None:
            return
        for (subq, match_info) in find_info:
            for x_offset, subq_len in match_info:
                try:
                    x_offset_real = display.screen_len(line,
                                                       beg=0,
                                                       end=x_offset)
                    self.display.add_string(line[x_offset:x_offset + subq_len],
                                            pos_y=y,
                                            pos_x=x_offset_real,
                                            style=keyword_style)
                except curses.error as e:
                    debug.log("addnstr", str(e) + " ({0})".format(y))
Beispiel #6
0
    def do_display_prompt(self,
                          format,
                          y_offset=0,
                          x_offset=0,
                          y_align="top",
                          x_align="left"):
        parsed = self.display.markup_parser.parse(format)
        offset = 0
        tokens = []

        self.last_query_position = -1

        for s, attrs in parsed:
            formatted_string = self.format_prompt_string(s, offset)
            tokens.append((formatted_string, attrs))
            offset += display.screen_len(formatted_string)

        y, x = self.display.add_aligned_string_tokens(tokens,
                                                      y_offset=y_offset,
                                                      x_offset=x_offset,
                                                      y_align=y_align,
                                                      x_align=x_align)

        # when %q is specified, record its position
        if self.last_query_position >= 0:
            self.caret_x = self.last_query_position + x
            self.caret_y = self.PROMPT_OFFSET_V
Beispiel #7
0
    def display_result(self, y, result, is_current=False, is_marked=False):
        line, find_info, abs_idx, exit_status = result
        if exit_status == 0:  # set separator colour depending on exit status
            bar_colour = self.exit0_color
        else:
            bar_colour = self.exitnot0_color

        if is_current:
            line_style = self.CANDIDATES_LINE_SELECTED
        elif is_marked:
            line_style = self.CANDIDATES_LINE_MARKED
        else:
            line_style = self.CANDIDATES_LINE_BASIC

        keyword_style = self.CANDIDATES_LINE_QUERY + line_style

        # self.fold_fields = [1,2]

        new_line = self.fold_line(line, self.FIELD_SEP, self.fold_fields)

        self.display_line(y, 0, new_line, style=line_style)

        spans = self.get_spans(line, self.FIELD_SEP)
        new_spans = self.get_spans(new_line, self.FIELD_SEP)

        if find_info is None:
            return
        for (subq, match_info) in find_info:
            new_match_info = self.fold_matches(spans, new_spans, subq,
                                               match_info, self.fold_fields,
                                               self.FOLDED)
            for x_offset, subq_len in new_match_info:
                # for x_offset, subq_len in match_info:
                try:
                    x_offset_real = display.screen_len(new_line,
                                                       beg=0,
                                                       end=x_offset)

                    self.display.add_string(new_line[x_offset:x_offset +
                                                     subq_len],
                                            pos_y=y,
                                            pos_x=x_offset_real,
                                            style=keyword_style)

                except curses.error as e:
                    debug.log("view.py, addnstr", str(e) + " ({0})".format(y))

                for n in new_spans:  # colour separator blue or red depending on exit status
                    self.display.add_string(
                        new_line[n[0] - len(self.FIELD_SEP):n[0]],
                        pos_y=y,
                        pos_x=n[0] - len(self.FIELD_SEP),
                        style=(bar_colour, "bold") + line_style)
Beispiel #8
0
    def display_prompt(self):
        self.caret_x = -1
        self.caret_y = -1

        self.do_display_prompt(self.RPROMPT,
                               y_offset = self.PROMPT_OFFSET_V,
                               x_align = "right")

        self.do_display_prompt(self.PROMPT,
                               y_offset = self.PROMPT_OFFSET_V)

        try:
            # move caret
            if self.caret_x >= 0 and self.caret_y >= 0:
                self.screen.move(self.caret_y,
                                 self.caret_x + display.screen_len(self.model.query, 0, self.model.caret))
        except curses.error:
            pass
Beispiel #9
0
    def display_prompt(self):
        self.caret_x = -1
        self.caret_y = -1

        self.do_display_prompt(self.RPROMPT,
                               y_offset=self.PROMPT_OFFSET_V,
                               x_align="right")

        self.do_display_prompt(self.PROMPT, y_offset=self.PROMPT_OFFSET_V)

        try:
            # move caret
            if self.caret_x >= 0 and self.caret_y >= 0:
                self.screen.move(
                    self.caret_y, self.caret_x +
                    display.screen_len(self.model.query, 0, self.model.caret))
        except curses.error:
            pass
Beispiel #10
0
    def display_result(self, y, result, is_current = False, is_marked = False):
        line, find_info, abs_idx = result

        if is_current:
            line_style = self.CANDIDATES_LINE_SELECTED
        elif is_marked:
            line_style = self.CANDIDATES_LINE_MARKED
        else:
            line_style = self.CANDIDATES_LINE_BASIC

        keyword_style = self.CANDIDATES_LINE_QUERY + line_style

        # self.fold_fields = [1,2]

        new_line = self.fold_line(line,self.FIELD_SEP,self.fold_fields)

        self.display_line(y, 0, new_line, style = line_style)

        spans = self.get_spans(line, self.FIELD_SEP)
        new_spans = self.get_spans(new_line, self.FIELD_SEP)

        if find_info is None:
            return
        for (subq, match_info) in find_info:
            new_match_info = self.fold_matches(spans, new_spans, subq, match_info, self.fold_fields, self.FOLDED)
            for x_offset, subq_len in new_match_info:
            # for x_offset, subq_len in match_info:
                try:
                    x_offset_real = display.screen_len(new_line, beg = 0, end = x_offset)

                    self.display.add_string(new_line[x_offset:x_offset + subq_len],
                                            pos_y = y,
                                            pos_x = x_offset_real,
                                            style = keyword_style)
                    
                    # debug.log((line,x_offset,x_offset+subq_len,y,x_offset_real))
                    # debug.log(line[x_offset:x_offset + subq_len])
                    # x_offset_real = display.screen_len(line, beg = 0, end = x_offset)
                    # self.display.add_string(line[x_offset:x_offset + subq_len],
                    #                         pos_y = y,
                    #                         pos_x = x_offset_real,
                    #                         style = keyword_style)
                except curses.error as e:
                    debug.log("addnstr", str(e) + " ({0})".format(y))
Beispiel #11
0
    def do_display_prompt(self, format,
                          y_offset = 0, x_offset = 0,
                          y_align = "top", x_align = "left"):
        parsed = self.display.markup_parser.parse(format)
        offset = 0
        tokens = []

        self.last_query_position = -1

        for s, attrs in parsed:
            formatted_string = self.format_prompt_string(s, offset)
            tokens.append((formatted_string, attrs))
            offset += display.screen_len(formatted_string)

        y, x = self.display.add_aligned_string_tokens(tokens,
                                                      y_offset = y_offset,
                                                      x_offset = x_offset,
                                                      y_align = y_align,
                                                      x_align = x_align)

        # when %q is specified, record its position
        if self.last_query_position >= 0:
            self.caret_x = self.last_query_position + x
            self.caret_y = self.PROMPT_OFFSET_V